Calculating Relative angles
I am writing an edtior tool, and need some help with some Vector or angle math.
I have a a mesh of quads seen below. I've iterated over this mesh and generated the following data:
-The Center point of each quad (green cirle)
-The center point of the first edge (red circle)
-The direction vectors in 3D space (the blue arrows)
-and finally each quad has a list of what quads are attached to it so that I can iterate over them
What I want to do is loop over the list of neighbouring quads and calculate for each neighbour the direction (or angle) of the quads realtive to it.
Here are some examples of the results I want to achieve.
Quad 3 is surrounded on all for sides by:
Quad 4 - forward ( 0 degrees)
Quad 6 - left (270 degrees)
Quad 9 - right (90 degrees)
Quad 2 - back (180 degrees)
Quad 7 has
Quad 6 - Back (180 degrees)
Quad 8 - Right(90 degrees)
Quad 2 has
Quad 1 - Back (180 degrees)
Quad 3 - forward ( 0 degrees)
I've tried unsuccessfully a few times with caluating the angles various ways of using the Directions and/or points and can't figure it out.
Answer by Matt3D · Jun 07, 2020 at 03:05 AM
Turns out I answered my own question, I was on the right track in the first place but a syntax error was giving me the wrong angles because I was using the wrong point to calculate from.
Vector3 targetDir = NeighbourQuad.Center - Quad.Center;
Vector3.SignedAngle(Quad.FaceDirection, targetDir, Vector3.up));
This takes a Vector 3 direction and gives me the angle relative between it and a point.
Your answer
Follow this Question
Related Questions
How to calculate the tilt angle of an object? 0 Answers
Find a point in space using Vector3 angles and Raycast 1 Answer
How to get vector rotated by specyfic angle? 0 Answers
how to calculate the angle between two vectors? 6 Answers
Non physics determinism of floating point math across platforms 1 Answer