This has been giving my quite a bit of trouble lately…
Take the function:
function gridRD(a,b,c)
{
var result = 0.0;
// calculating the 3 distances
var ab = Vector2.Distance(a, b);
var bc = Vector2.Distance(b, c);
var ac = Vector2.Distance(a, c);
var cosB = Mathf.Pow(ac, 2) - Mathf.Pow(ab, 2) - Mathf.Pow(bc, 2);
cosB /= (2 * ab * bc);
result = (Mathf.Acos(cosB) * 180 / Mathf.PI);
return result;
}
This function gets the angle between three points, as displayed in this graph:
If the graph DIDN’T do it for you, let me explain.
Let’s say you have three cubes, all on the same Y position.
This in essence puts us in 2D, so we don’t have to worry about the y position any more.
The three cubes are named p1, p2, and p3.
If you were to draw two lines, from p3, and p1, to p2, ou would get what looks like a geometry arc.
Then, you simply get the angle between th two lines, and viola (I am assuming that’s how you spell it), that is what the function does.
If you still don’t get what I’m saying (Not because you are stupid, but because I am a bad communicator :lol:), please ask for clarification.
If you do… Continue reading.
The problem with the equation, is that it stops at 180, and then starts going back down to 0. For instance, when the actual rotation is 270, the function would return 90. I need it to return 270, and likewise be able to make it to the full 360/359 in a rotation.
This is because it is based on the distance between all three points, and once you get to 180, the points don’t get any further apart.
Could someone present an equation that either modifies the one I have displayed above, or one that pulls of the same effect - except without the 180 degree peak?