I've been digging on this site and through google, but I can't find an arccos function anywhere; all I find are discussions about it and about dot products which I don't understand, it's all theory behind arccos which I would like to understand and would use to make the function if I could.
All I want to do is find the angle of one object relative to another object's location and heading, and to do so I'm trying to find the difference between the reference's heading and the angle made by the location of the reference and target.
Does anyone know where I can find either a premade arccos function or a simple explanation of it that would allow me to program my own for use in my GetAngle function?
Here's my simple function I'm using it in.
Thanks in advance for any explanation you might be able to provide.
float GetAngle(object targ, object ref)
float x = targ.loc.x - ref.loc.x;
float y = targ.loc.y - ref.loc.y;
float r = sqrt(x*x + y*y);
float theta = arccos((y*y + r*r - x*x)/(2*y*r));
return theta - ref.heading;
That math.h it mentioned did the trick. Thanks again.
I feel my headache going away already.
It's been a while, but didn't there used to be a way to mark my thread as resolved? The thread tools only seems to have printing, emailing, subscribing and adding a poll to the thread now. How do I tag it now?