#### Archived

This topic is now archived and is closed to further replies.

# Angle between two Vertices

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

## Recommended Posts

I am trying to figure this out I have Vertex one thats 3D(x,y,z) and number 2. For simplicity lets say one = (1,1,1) two = (100,100,1000) two is the destination point. I need to find the yaw, pitch, and roll angles to achieve that point. This is a jet and I dont care about gravity or anything else just weightless space. I think I use a cross product of the 2 vertices but it comes out 0. Or do I use a dot product of each x,y,x? Can someone help I know its simple, but I''m pretty new to matrices. Nick

##### Share on other sites
Okay so maybe I''m looking at it wrong.

I have a jet with a matrix. I understand what each row is for. So If I have a vertex point of his next position to move for(part of a pattern to fly).

I would think I need to calculate the cross product of each the Look, Up, and Right vector in that matrix?

Can someone help my book explained the matrices and how to move them but not how to get to a defined point.

Nick

##### Share on other sites
I wrote a flocking demo where the ''birds'' had to be able to turn and head toward any arbitrary point in space - here''s how I did it.

The bird''s local matrix (i.e. side, up, and forward vectors, and translation) define the bird''s local space. So the first step was to take the target point and transform it into the bird''s local space by multiplying by this matrix.

Now, with the target point in local space, you have some useful information. If target.x < 0, you need to turn left (or right, depending on your coordinate system). If target.x > 0, turn the other way. If target.y > 0, pitch up, and if target.y < 0, pitch down. Roll doesn''t affect heading, so you can ignore it for now. In practice you''ll probably want to use < -epsilon and > epsilon to keep the ship from ''wobbling'' once it''s homed in on its target.

This is a pretty cursory explanation, but I can provide more detail if you want.

##### Share on other sites
I understand but I need an exact angle for the x,y,z so that way I can slowly maeuver the pitch,roll, etc.

I read in one book buut cant remember that for following you calculate the cross product of 2 vertices and that gives the angle you need to get that far. And you can use the dot product between 2 pointsto get the length. But I''m not sure how.

##### Share on other sites
OK so I know I need a dot product of each angle I would assume

##### Share on other sites
A few things, you can't actually take dot or cross products of two vertices, but only two vectors. The vectors will have initial points at (0,0,0) and end points at the points you listed as the positions for your vertices.

vec1 = (1,1,1)
vec2 = (100, 100, 1000)

Now, as far as dot products go, if you use a dot product to find the angle between two vectors, this angle is between them on the plane they define. Any two vectors are guaranteed to be coplanar, and the normal of the plane they're on is defined by the cross product of the two vectors.

N is the normal for the plane both vec1 and vec2 lie on.
N is equal to the cross product of vec1 and vec2.

The cosine of the angle between the two vectors is
cos theta = ([mag vec1]*[mag vec2])/(vec1.x*vec2.x+vec1.y*vec2.y+vec1.z*vec2.z)

Hopefully you can follow what I've said and find the solution on your own.

[edited by - digitec devil on May 29, 2004 11:27:40 AM]

##### Share on other sites
one = (1,1,1)
two = (100,100,1000)

two is the destination point. I need to find the yaw, pitch, and roll angles to achieve that point.

two-one and you have a vector B...
(two-one)+point(one)=point(two)
if you need angles, just arccos(B.x)=roll B.y=pitch B.z=yaw
if you want to multiply an escalar to this vector and have velocity, just normalize 2-1 .

##### Share on other sites
Ok so I understand and I went to the bookstore and read a lot.

And your calculation I''ve seen hundreds of times in the last day from reading web sites all over the place.

What I dont get:
How is mag defined although I could probably find it.

What I think I dont get:
From these to vectors I need to build a 4x4 matrix so the jet will have its Look,Up,Right vectors defined for the new direction.

So do I get the cross product for the normal they are linked on. Whixh will more than likely be the Look plane. How do I get the other 2 planes. Do I create a vector based on the new matrix magnitude?

Nick

1. 1
Rutin
49
2. 2
3. 3
4. 4
5. 5

• 10
• 28
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633410
• Total Posts
3011723
• ### Who's Online (See full list)

There are no registered users currently online

×