Click here to Skip to main content
15,883,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello experts!

I have 4 vector3:
C#
Vector3 posFront = PositionBlocks.front.GetPosition();
Vector3 posRear = PositionBlocks.rear.GetPosition();
Vector3 posLeft = PositionBlocks.left.GetPosition();
Vector3 posRight = PositionBlocks.right.GetPosition();


posFront is the nose.
posRear is the tail.
posLeft is the left wing tip.
posRight is the right wing tip.

These vector3 are global coordinates.

At the moment I just try to get the pitch angle (up/down).
I have this code:
C#
const int X = 0;
const int Y = 1;
const int Z = 2;

Vector3 dir = Vector3.Subtract(posFront, posRear);
double x = dir.GetDim(X);
double y = dir.GetDim(Y);
double z = dir.GetDim(Z);
double angle = Math.Atan2(z, Math.Sqrt(y * y + x * x)) * 180.0 / Math.PI;

Logger.log(angle.ToString());


But this gives me a range of:
0 to 90, back to 0, then to -90 and back to 0

What I need is a range from -180 to 180.


I hope someone can help me
Thanks
Posted
Updated 27-Feb-15 4:35am
v3

1 solution

"Pitch angle" is the aviation term, if is not defined for just two vectors. You can calculate just the angle between them. The vector algebra is explained in so many places, look at any of them. Such as http://www.ltcconline.net/greenl/courses/107/vectors/dotcros.htm[^].

Anyway, such problems are solved not by asking questions, but by education. In this case, education in this relatively simple field of mathematics, linear algebra:
http://en.wikipedia.org/wiki/Linear_algebra[^],
http://en.wikipedia.org/wiki/Vector_algebra[^].

Please make yourself familiar with this field.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900