So it finally happened, the URL that I used for 15+ years to reference sin math went down.
For posterity, i'll paste it here:
Fun with Sin
To create the sine wave curve pictured in the first example below, consider the illustration above. Imagine the hypotenuse, C, of the triangle sweeping around the circle in a counter-clockwise rotation. At each point along the sweep, you get back the length of A on the Y axis. The circle is 1 unit in radius, so the value goes from 0 to 1, then back to 0, then 0 to -1 and back to 0 again.The reason you get the "sine wave" curve below is that you are progressing through the values of the 'sweep' over time.
The sin() function uses as its input the angle,, of the counter-clockwise 'sweep', in radians, not degrees.
There are 2* PI radians in 360 degrees.
radians = degrees * (PI / 180)
degrees = radians * (180 / PI)
More easily, in MEL you can convert using the commands "deg_to_rad" and "rad_to_deg".
In these examples, Maya's predefined attribute called "time" (the current time in seconds) is input to the sin function. This means at 3.1415927 seconds, we've gone 180 degrees around the circle, which gives the progression from 0 to 1 and back to 0. At 6.28 seconds we are the rest of the way around (0 to -1 to 0) and the cycle repeats.
Note: the curves graphed below are the result of baking the expressions into keyframes. You won't see these curves in the graph editor when using expressions.
function | description | example |
sin( ) | returns the sine of the given value. | translateY = sin(time); you can change the amplitude: |
cos( ) | The cosine ratio is a value between -1 and 1. The cos function works like the sin function except its return values are 90 degrees, or pi/2, out of phase. | translateY = cos(time);![]() The cos function is very handy for making an "opposing" action to an object being controlled by the sin function. |
abs( ) | Returns the absolute value of number. The absolute value of an integer or floating point number is the number without its positive or negative sign. The absolute value of a vector is a vector with components stripped of negative signs. | translateY = abs( sin(time) );![]() the absolute value of the sine wave makes for a good bouncing action. |
max( ) | Returns the larger of two floating point numbers. float max(float number, float number) number is a number you want to compare. | translateY = max( 0, sin(time) );![]() max works like a clamp. The sine wave is not allowed to go below 0. |
min( ) | Returns the lesser of two floating point numbers. float min( float number, float number) number is a number you want to compare. | translateY = min( 0, sin(time) ); |
linstep( ) | Returns a value from 0 to 1 that represents a parameter's proportional distance between a minimum and maximum value. This function lets you increase an attribute such as opacity from 0 to 1 linearly over a time range. float linstep(float start, float end, float parameter) start and end specifies the minimum and maximum values. parameter is the value you want to use to generate the proportional number. If parameter is less than start, linstep returns 0. If parameter is greater than end, linstep returns 1. | translateY = linstep( 0, 1, sin(time) ); |