We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all, I am having some trouble with this:
I am using the PVector class to define some moving elements in a sketch.
So an entity has:
PVector pos; //position
PVector vel; //velocity
PVector tar; //target position
PVector towardsTar; //direction from element to target
float heading = vel.heading(); //ok, I have the heading angle of my element
towardsTar.sub(pos); // pos + towardsTar = tar --> towardsTar = tar - pos so I have my desired direction
Now I have these two vectors (heading and towardsTar) and I want to find the angle between them, inorder to know if the element has to turn clockwise or counterclockwise inorder to head towards the target.
If I use this:
float angle = PVector.angleBetween(heading, towardsTar);
I will get the right angle, but it will always be positive.
So I will not know if the entity has to turn the one or the other way.
I have managed to make a workaround for that, but my algorithm is not so good...
Is there a good and elegant way to do that? Perhaps something I have missed from the PVector class?
Please do not refer me to a library, I am just looking for a simple way to do that by defining a small function at most.
Thanks in advance, Kostas