PDA

View Full Version : Finding angles between 2 3d points.



Enebreus
July 13th, 2007, 05:45 PM
Hey all, I'm stumped.

I'm trying to find the 2 (radian) angles between 3D points for example (0, 0, 0) --> (10, 10, 30)

I enlisted the help of a guy from work and came up with:


var dz:Number = lObj.myX-cView.camX;
var dy:Number = lObj.myY-cView.camY;
var dx:Number = lObj.myZ-cView.camZ;
B =Math.asin(dz/Math.sqrt(dx*dx+dy*dy+dz*dz));
A =Math.asin(dy/Math.sqrt(dx*dx+dy*dy));
(lObj is the object I'm moving towards. cView is the position of my viewer/camera.)

This seems to work, until my dx value goes into the negatives, then it just kinda goes crazy :P

Is there a more widely accepted way of finding the two angles?
I'd really appreciate it if someone could furnish me with an example, I've been trying to Google a solution for about two hours, although I've run across several promising leads most are over my head.

FizixMan
July 13th, 2007, 06:34 PM
A =Math.asin(dy/Math.sqrt(dx*dx+dy*dy));


If you're dividing by the vector length, shouldn't this be Math.sqrt(dx*dx+dy*dy+dz*dz)?

Enebreus
July 13th, 2007, 07:29 PM
Crap, I found a pretty major bug in another part of the code.
So... the stuff I posted above might actually be correct. I'll pop back in when I get a better idea.

Anic
July 16th, 2007, 06:38 AM
we beleive in u!