- Home /
2D angle of two Vec3
How can I calculate 2D angle of two Vec3?
I am trying to find angle between wing forward vector and velocity vector. I found on forum nice code for angle between two vectors. My problem is when my object turns left or right the velocity vector does not turns with object. Of course it`s normal. I need to find plane (XY) angle or make new vector based on velocity vector and turning with plane. Because
this falsifies my angle.
Thank you.
The trick is to think of which 2D plane to measure over, which is usually called a projection. The second picture, it measures over the "real" 2D plane glued to the front of that wing (which is easy, and doesn't even use projection. Just Vector3.angle
)
The first picture, it looks maybe like the 2D plane is going straight down from the from of the fuselage (but not sure, it has to do with lift?) In that case, you project each vector onto that plane, and then measure.
But it starts with figuring out exactly which plane (does yours tilt when the plane rolls?)
From what i understand you should project velocity to the plane defined by airplane.up and airplane.forward vectors, and take the angle between that vector and airplane.forward.
@Nose$$anonymous$$ills seems right to me; in fact, for computing lift, you probably just need the dot product of the velocity and airplane.up (or wing.up if it's appreciably different).
I like the other comments, but let me try to explain a different way. The airstream vector you are looking for can be described as “the component of the velocity vector that is pointing forward”. $$anonymous$$uch like you would say the Y of the velocity vector can be described as “the component of the velocity vector that is pointing up.” Obviously you won’t be able to just extract a single coordinate here, ins$$anonymous$$d you will want to use a dot product of your velocity vector and your forward vector. This will tell you how fast you are moving in the forward direction. The dot product computation INCLUDES the angle you are looking for and is defined as |VectorSpeed| Cos(theta), where theta is the angle between the two vectors. $$anonymous$$ultiple this scalar (a non-vector) result with your VectorForward to get the final vector your looking for. You can also use this formula and the dot product result to deter$$anonymous$$e the angle theta.
This picture in the wiki for dot product has a great picture that describes this exactly.
http://en.wikipedia.org/wiki/Dot_product#mediaviewer/File:Dot_Product.svg
Thank you all. Should be some '+' or 'Thanks' button in comments.