I was wondering if anyone knew the formula for direction on a 2D Plane. I already know the X and Y of the object. What's the formula for direction?
Posted on 2002-12-08 13:45:54 by CyberGuy
You need at least a pair of (x,y) coordinate sets so you can draw line between them and by that line determine direction.
Posted on 2002-12-08 14:28:13 by comrade
Ok, after I have the pairs of X, and Y whats the formula?
Posted on 2002-12-08 15:23:49 by CyberGuy
You need direction as an angle?
Posted on 2002-12-08 16:10:33 by comrade
Like this:
width = x2 - x1

height = y2 - y1
angle = arctan(height/width)


Direction would be angle.
Posted on 2002-12-08 16:15:21 by comrade
Thanks guys!
Posted on 2002-12-08 19:44:51 by CyberGuy
Ok now something more complex...suppose I wish to code an Aim Constraint...
Let us suppose further that the Aim Constraint is based on a 3d vector (a virtual line between two points in 3d space).
This means we have the dX,dY,dZ values (axial differences)
What's the most suitable method to find the 3d angle of the imaginary ray for the purpose of creating a YawPitchRoll matrix for performing inverse kinematic transformations back up the weapon arm of a bone-animated model?
Posted on 2002-12-08 23:20:10 by Homer
If the two vectors are unit vectors, you can use the dot product:

Using two vectors A and B: (Ax*Bx) + (Ay*By) + (Az*Bz) = cos of the angle

You can get the unit vectors from the original vectors by taking the xyz values and dividing them by the length of that vector.

To find the unit vector, get the length. The length equals sqr(x^2 + y^2 + z^2).
Then x/lenght, y/length, z/length = xyz in unit vector form

Do this for both vectors.

Going back to the top and using the dot product will now give you the cos of the angle between the two vectors.
Posted on 2002-12-09 10:28:10 by drhowarddrfine
Yup ok good... but that gives me a single angle about an arbitrary axis, right?
For YawPitchRoll I need 3 rotation angles...
There's a DX function for creating a rotation matrix about an arbitrary axis, but I haven't needed it in the past... if I recall correctly, it required an angle, and the axis as a unit vector.
I don't care what kind of xform matrix I end up with, as long as it performs the required rotation !! Any hints on calculating the arbitrary axis? I assume its the up vector rotated around the rotated Ray (:tongue:)
Posted on 2002-12-10 23:21:00 by Homer