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?

You need at least a pair of (x,y) coordinate sets so you can draw line between them and by that line determine direction.

Ok, after I have the pairs of X, and Y whats the formula?

You need direction as an angle?

Like this:

Direction would be

```
width = x2 - x1
```

height = y2 - y1

angle = arctan(height/width)

Direction would be

**angle**.Thanks guys!

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?

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?

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.

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.

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:)

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:)