PDA

View Full Version : 3DSMAX: Using Scripted Controllers With Trig Functions.. Hit A Snag


Malkalypse
06-10-2007, 05:54 AM
I am having some trouble getting some components on a mechanical device to move properly. I have broken the movements I need down, and think I am on my way to a solution. However, there is an issue I have run up against:

http://www.versatileartist.com/temp/PCA_anim06.max (http://www.versatileartist.com/temp/PCA_anim06.max)

The problem in question can be found by selecting the yellow line (Radius_Pitch01xy), going to Motion -> Assign Controller, and choosing "X Rotation: Float Script".

I am trying to get the yellow line to rotate such that it will form the third side of the triangle (i.e. matching the rotation of the brown line.) The brown line uses a lookat controller, which is not a workable solution for what I am trying to do.

The math for this should be fairly simple.. the sine of an angle (the angle in radians) is a/c, with a and c being the opposite and hypotenuse sides of the triangle (I already have the lengths, so it should work just as I have it.. however, if you move the time slider around you will see that, while it starts out kinda close, it isn't lining up, and becomes worse when the dimensions of the triangle change.

magicm
06-10-2007, 01:41 PM
You need the inverse tangent function to calculate the angle. Divide the adjacent (Pitch01Forward) by the opposite side (Pitch01Up) and calculate the arctangent. Here's the code:

o = $Radius_Pitch01Up.height -- opposite
a = $Radius_Pitch01Forward.height -- adjacent

-- arctan adjacent/opposite
degToRad (atan (a/o))
Martijn

CGTalk Moderation
06-10-2007, 01:41 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.