## Sunday, November 22, 2009

### The first sine of madness!

One of the most useful trig function in 3D that's applied often in dynamics, rigging, or even modeling is the Sine function. It is a good clean way to get a rhythmic flow while at the same time easy to control for offset and do useful math for animation.

So I'm here to talk about 4 ways to create the sine function in Maya each with it's benefit and drawbacks.

1.Expression

This is by far the easiest way to create the sine function in Maya, it's clean, fast, and easy to read creation makes this, probably the most used way to make the sine function. But there is a debate about when and how an expression should be used.

People like Aaron Holly and Jason Schiffer had talked about sometimes it's better to make a node net work insisted of writing an expression because the nature of expression "could be" heavy at run time.

You see when an object’s attributes are accessed via a MEL script, Maya does not make connections for the relevant attributes of the nodes, so the directed graph evaluation process is bypassed. In order to ensure that the value of expression's target is consistently up to date, the Evaluation option must be set to Always so that the evaluation can be triggered when necessary.
So for the expression to work it needs to be evaluated every frame and can slow down the scene.

2. Set-Driven-Key

This is kind of a "hack" way to get the sine function to work in Maya, it is lite to use and won't slow down the scene but it does not give the absolute true value of the sine function just a very close one, This doesn't take too long to setup but could get messy.

The basic idea is we are going to create a simple version of the sine function by having an input value(a channel) that's in degrees, being the driver it will set-driven-keys anther channel from 0-360 which than will outputs values from 0,1,-1,and 0. Set that animation curve to cycle pre and post infinity you got yourself a simple sine curve.

3.Ramp

This is very much a "hack" way to get the sine function, this was shown to me by a very clever fellow by the name Alon Gibli who is an amazing rigger and technical artist.

So what this is trying to do is to create the closest sine function without using an expressions. First make a multiply-divide node with the degrees being the input -input 1 (x) divide that by 360 so the degree value is normalized to the ramp value of 0-1. Connect the output 1 (x) to v-cord of the ramp. Set the ramp to a 0,1,-1,0. The output color of the ramp should be the function. Of course I was made aware that this could cause bugs to come up in Maya. But it is a pretty useful way to create the sine function

4.Trig model

This is by all means the least practical way to create the sine function, it takes a long time and has a very unnecessary "involved" way to setup. But it is a somewhat correct way to find the sine function that is unique enough for me to show it.

This method tries to create the a triangle in side a Maya circle but first you will need.
a plane that sits horizontal in the middle of the circle
and two locators

The circle of course has a radius of 1 will be the hypotenuse, a locator is snapped on the the circle (name it locator 1) and will be grouped to a null object with it's the origin at the center of the circle. Rotating that null-group will move locator 1 in a circular motion creating the opposite.

Create another locator (name it locator 2) that's point constrain to the first loactor but at the same time geo-constrain to the plane creating adjacent side. "Note this only works because Maya treats geo-constrain differently than a normal, parent, point, etc constrain."

Finally Make a distance node that's between locator 1, and locator 2. So whenever the null-group is rotated in degrees the distance-node will give out the sine-function.

Of course these are not all of the ways to create the sine function in Maya, plug-ins such as (Mathematic Nodes) are very helpful. But if you have a good way to create the sine function please share.

#### 1 comment:

1. Sine has some nifty applications too - my friend has an awesome foot setup he uses based on sine!

Generally I set it up with a ramp node (I have an aversion to expressions XD) but I want to try the trig model that you posted at some point...