• Advertisement

• ### Popular Now

• 13
• 18
• 19
• 27
• 10
• Advertisement
• Advertisement
• Advertisement

# Find angle between two Y positions...?

This topic is 4584 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

Hi there! I'm wondering how to (insert name of thread here) ...? Two points, A and B, got x,y,z values in 3D space. If the points where on a plane, it should be easy trig to find the direction, but since the two points are in a 3D space, I'm wondering if there's a way to calculate the angle using only the Y's of the positions...?

#### Share this post

##### Share on other sites
Advertisement
I'm not sure what you mean -- if you want to find the angle between the Y components of the vertices, this will always be zero. Because this is a one-dimensional problem the positions will both lie somewhere along the same (Y) axis and hence their angle is zero.

I suppose you want to find the angle between the two vectors when projected on some plane (let's say the XY plane). The angle between vectors is given by the dot product. I'm not sure but I think you can just construct two 2D vectors by discarding the Z-component and then compute a 2D dot product.

Greetz,

Illco

#### Share this post

##### Share on other sites
you want to calculate the angle relative to what exactly? the x-z plane? I'm a little confused on exactly what youre asking, can you possibly re-phrase the question? exactly what angle do you want?

Tim

#### Share this post

##### Share on other sites
Ok, sorry for the vague question! :)

Anyway, I need to find the angle between two Y positions ANYWHERE in the 3d area...

             | Y      |      |    A |________B_____  X    |/         |     |          x   /|            / x          /__________________Z

x = Intersection dot with ground

I have already calculated the angle between X,Z coords of the points, but since it's 3d, I dont know how to calculate the angle between Ay and By... :S

Any clues?

#### Share this post

##### Share on other sites
Nice art. But as I said: the Y-coordinates themselves have no angle. Imagine the Y-axis:
|||||

Then Ay and By are somewhere along it:
|| <- By|| <- Ay|

They do not make any angle as this is a one dimensional axis. Put differently: the vectors run in parallel. So I think I'm still not clear on what you want.

Illco

#### Share this post

##### Share on other sites
Don't have time to give the answer atm, but I'll venture a guess as to what the OP is asking. Perhaps this is to determine an appropriate yaw and pitch or yaw and pitch delta given a target point. So (minus the details), the solution may be to find the difference between the angles from A and B to the ground plane (or equivalently, the y axis).
Quote:
 I have already calculated the angle between X,Z coords of the points
If you were to post your code for this, it would probably become clear what you're trying to do with the y coordinates.

#### Share this post

##### Share on other sites
The above poster is correct... :)

I'm trying to set the Yaw of a vehicle that is roaming my heightmap....

I have vector3d Pos, Direction, Gravity...
where: Pos += Direction-Gravity;

To find a angle in the X,Z plane, I use:
180 * (1 + atan2(From.z-To.z, From.x-To.x) / PI);

But one cant simply use the same function on the Y plane, because the X,Z are not in the same plane, correct..? <-- not sure thou...

#### Share this post

##### Share on other sites
Ok that is more clear. Then I'll venture a guess:
+ <-- Ay||||------+ <-- By

Is the angle of this triangle perhaps what you are looking for? Imagine the triangle being rotated about the Y axis such that the facing is already correct (according to your XZ calculations). Then this would yield the pitch right? If so the trig is pretty easy.

Illco

#### Share this post

##### Share on other sites
Exactly, and what I orinally, rather stupidly, questioned was how to achieve this "triangle rotation" ... :)

I can find the angle (or direction) on a single plane, I just dont know how to transform it according to the second plane... sort of.

EDIT:

since I got the Direction, A and B points as vectors, shouldn't there be some simple addition or something to achieve what I want? Maybe if I lerp'ed the direction towards the new position.... ? hmm... be right back... :)

#### Share this post

##### Share on other sites
Here's a possible solution:

// input vectors are a and b

angle1 = atan2(sqrt(a.x*a.x+a.z*a.z),a.y);
angle2 = atan2(sqrt(b.x*b.x+b.z*b.z),b.y);
pitch_delta = angle2-angle1; // Or angle1-angle2

Again, that's assuming I'm understanding the problem correctly.

#### Share this post

##### Share on other sites

• Advertisement