6
$\begingroup$

I am trying to make an animation in which a mathematical function changes as a function of time. Given below are two images which are z math surfaces(from the "extra objects" add on) whose equations are:

  1. $\sin x+\cos y$
  2. $\sin x-\cos y$ sin(x)+cos(y) sin(x)-cos(y)

The first image should change in the other for which the mathematical function can be given as $\sin x+t\cos y$, where $t$ varies from $1$ to $-1$

This is a simple mathematical surface parametrized in $t$ ($t$ obviously is a function of time and in our case a function the frame number).

Here I have picked up simple equations just to get the idea of implementing it and I actually intend to use it for more complex functions and even for the XYZ math surface. How do I go about it? (I would prefer a way without scripting but if I have to use scripting then please tell me in detail as to how to proceed with it.)

$\endgroup$
0

3 Answers 3

10
$\begingroup$

enter image description here

I'm not aware of a simple way to do this without scripting, so here's a scripting based solution, using a frame change app handler.

frame_change_pre app handlers run before every frame change, so they're ideal to update a mesh every frame.

This function alters the active object's vertices Z values according to the equation z = sin( x ) + t * cos( y ). Here, t is a normalized value that maps frame numbers between 1-100 to values between -1 and 1.

import bpy
from math import sin, cos

def update_z_from_equation( scene ):
    o = scene.objects.active

    frameMin, frameMax = 1, 100
    tMin, tMax         = -1, 1

    t = tMin + ( scene.frame_current / frameMax ) * ( tMax - tMin ) * tMax 

    for v in o.data.vertices:
        v.co.z = sin( v.co.x ) + t * cos( v.co.y )

bpy.app.handlers.frame_change_pre.append( update_z_from_equation )

To use this add a grid plane, subdivide a few times, scale X5 in edit mode, then run the script once and keep the plane selected and active.

$\endgroup$
3
  • 2
    $\begingroup$ It is also possible to add keyframes to each vertex. $\endgroup$
    – sambler
    Aug 7, 2017 at 12:41
  • $\begingroup$ Didn't know that, cool! $\endgroup$
    – TLousky
    Aug 7, 2017 at 12:53
  • $\begingroup$ Right as usual @batFINGER, will fix $\endgroup$
    – TLousky
    Aug 7, 2017 at 13:26
10
$\begingroup$

I would suggest using Animation Nodes for more interactive results.

The Grid Mesh node generates evenly spaced vectors (Which can act as your 2D coordinates plane).

Points

I separate the vectors into their x,y,z components (Z is zero in the grid), for every vector I compute the equation you provided above in terms of the x and y values I extracted, then I form a new vector from the x, y and z where z is the value we computed, resulting in points that satisfy your function:

Points

In order to make it a 3D mesh with faces, we use the original polygon indices and new vectors to make a mesh as follows, this is just how meshed are output to object:

Mesh

Last step is to introduce the (t) in your equation, which will be time, we can use the animate float node with the starting and ending values -1, 1 respectively as you stated in the question. And of course Duration is the duration of the animation. Resulting in the animation as you see:

Animation

If you want to color the surface based on its z value, where the higher the point is the higher the red value and the slower it is the bluer it is, you can use the following shading node tree:

Shading

$\endgroup$
10
  • $\begingroup$ this method definitely needs me to learn a lot. Could you suggest me some topics from the manual to read for a good start. I have never used the node editor before.It also promises to give me freedom to control my mesh surface mathematically. $\endgroup$ Aug 7, 2017 at 13:44
  • 1
    $\begingroup$ @GouriShanker I edited the question for more details, please see the documentation here for more information on each node and information on how to install Animation Nodes: animation-nodes-manual.readthedocs.io/en/latest $\endgroup$
    – Omar Emara
    Aug 7, 2017 at 15:09
  • 1
    $\begingroup$ I could follow till end but then how should I actually change the time during the animation. when I am running the animation the frames are changing and the other set keyframes are responding as they should be. But the function is not changing. I tried to set key frames to the time node but it did not help. $\endgroup$ Aug 12, 2017 at 14:56
  • $\begingroup$ @GouriShanker Can you show me your node tree? $\endgroup$
    – Omar Emara
    Aug 13, 2017 at 9:37
  • $\begingroup$ sorry, I could not update due to net connection issues. I could work out the last part by using the 'time info' node. thanks. $\endgroup$ Aug 13, 2017 at 9:47
5
$\begingroup$

Join as Shapes.

Make one mesh with your equation (1)

enter image description here

Then make another with equation (2), making sure x and y subdivisions remain the same. You need to have the same amount of verts to join as shapes. Select both meshes and choose Join as shapes from shape key extras.

enter image description here

The Basis shapekey will be eqtn (1) and the other eqtn (2). Here is an example with 0 at frame 1, 1 at end frame.

enter image description here

$\endgroup$
4
  • $\begingroup$ This definitely seems to be the simplest one but with may limitations. Here seems to work fine because the two functions happen to be quite similar and hece the intermediate shapes of the function seems to follow the desired equation. I doubt if we actually have good mathematical control over in between shapes. Nevertheless it was a really great help as I can solve my problems in many other cases in a very neat and simple manner> $\endgroup$ Aug 7, 2017 at 13:33
  • $\begingroup$ In hindsight would suggest using z = 0 as the Basis shape. If two functions are used g(x, y) and h(x, y) then the shape keys will equate to w1 * g() + w2 * h() where w1, w2 are the key values of shapes g and h respectively. As long as w1 + w2 = 1 and both are in range [0, 1] should give reasonable result. $\endgroup$
    – batFINGER
    Aug 7, 2017 at 13:49
  • $\begingroup$ seems like I will have linear combinations of the two (or more) functions. Can this way of using the shape functions help me to model functions like:-sin(kx-wt) i.e when the time parameter is not a linear coefficiants? $\endgroup$ Aug 7, 2017 at 14:38
  • $\begingroup$ For non-linear combinations, just add more shapes, with the equation for that frame, the shape keyed to 1 on that frame. Eg in the least linear case, if time was in frames, sin(kx) on frame 0, sin(kx - w) on frame 1.... which would be a PITA doing via UI, but would be a simple script to put together, which can do if you are interested. $\endgroup$
    – batFINGER
    Aug 7, 2017 at 15:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .