PDA

View Full Version : rotation (trig) problem...


eek
08-24-2005, 10:45 AM
Ok,
So Mark Tsang and I last night were trying to figure this out. I might just be to do with max 4 but i'll post it anyway. So i have 2 points: 'a' and 'b' and a third 'c'

So im trying to calculate the rotation of 'c's [2] off the position of 'a' and 'b'. I have 'a' and 100 in z and 'b' 100 in x. So if you draw a line between the two the angle you get is 45 degrees. like the angles of a triangle.

so as a max script this works fine:

d1 = $a.pos[3]-$c.pos[3] -- this gets on length (opposite)
d2 = distance $a.pos $b.pos

then:

if $b.pos[1] > $a.pos[1] then n = asin(d1/d2) else n = -asin(d1/d2)

$c.rotation.controller[2].value = n -- you remove this and the 'n' in a script controller but for ms is to check it works.

so asin is finding the trigometric angle, you need the if clause and -asin if 'a' goes behind 'b' in x


So this is fine for ms you evaluate it and it produces the right result but when i convert it to a float_script on 'c' [2] rotation it goes whacky and spins like crazy!! Anyone know whats going on? Is it a quat thing? Am i get aditional rotations in the script?

Im adding dependsOn $a $b to the script to see a result is this causing it?

eek

marktsang
08-24-2005, 11:39 AM
hi charles,
had a quick look when i got up again (i was wrecked last night)
those trig functions return degrees
thats why it spins
change to

dependson $b $c
d1 = $b.pos[3]-$c.pos[3]
d2 = distance $b.pos $c.pos


if $b.pos[1] < $c.pos[1] then
(
n = degtorad (asin (d1/d2))

$d.rotation.controller[2].value = n
)
else
(
n = degtorad ( -atan (d1/d2))
$d.rotation.controller[2].value = n
)


mark tsang

eek
08-24-2005, 03:15 PM
Ah ok,

Cool i'll give it a try, cheers Mark


edit..
THANKYOU,THANKYOU it works! sweet!

oh and the else bit i edited to:

degtoRad 180-asin(d1/d2)


eek

eek
08-24-2005, 11:22 PM
im gunnna have to find a better way to rip out the first variable. Using distance causes havok as if the points move in another axis as it still affects the trig value - distance looks at points wherever they are.

I need to get that length some other way, and i need to keep it seperate as ive gotta put the script on the other axis...

eek

PEN
08-25-2005, 04:39 PM
I'm not really sure what final result that you are after? If I know that I might have an answer for you.

eek
08-26-2005, 07:18 PM
Ah hi Paul,

Just looking into cleaner ways to produce my spline muscles, rather than bolting lots of constriants together. I found a easy way to get 'd1's value just by doing a standard trig fomula.

I think mixing rotations together, is a no no . Im getting weird result so im gunna look in matrix's and see if i do everything with positional data.

Basically i have two points and a point between them, when the first to come together it pushes the middle out. This is fine if the base and top point move up and down, left and right but foward and back it has to move up/down with the base/top points to simulate it following it. Its a little difficult to explain :(

eek

PEN
08-29-2005, 02:29 PM
Eek, when ever dealing with complex rotations I find it far better to go to the matrix and deal with postion values and then get the rotations from that. Adding values up and having them return usable values becomes far easier.

Here is a box pointing at a sphere along the +X axis:

s=sphere pos:[200,300,50]
b=box pos:[-100,20,-50]

z=[0,0,1] --world upnode
x=normalize (s.pos-b.pos)
y=normalize (cross z x)
z=cross x y --recalculate the z upnode so that you don't skew the matrix

b.transform=(matrix3 x y z b.pos)

eek
08-29-2005, 02:45 PM
oohh,

Thanks Paul, ive been looking into matrix stuff this weekend. Matrix's seem far more stable as there at the root of all this stuff and they govern whole transforms.

Ive done a little muscle/surfacing test, and i'll post/send it over to you sometime today. Heres a little pic:

http://www.eekstudios.com/cgtalk/tmuscle4_test.jpg

And ill post a clip of it on the 'facial animation setup thread'

eek

CGTalk Moderation
08-29-2005, 02:45 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.