x y angle calculation [question]

11/16/2008 12:52 syron198#1
Hey guys,

I'd like to ask something about a calculation which I was thinking of.

I got 2 points, 1 point is the point where I am and the other point is the point to which I want to move. But first I have to look towards this point ( face angle ). It is about a game, called warhammer.

I heared, that there is a possibility to calculate the angle.

Let's say the point is (which I was reading out CE):
x1 = 27802.375;
y1 = 17086.75;
x2 = 27520;
y2 = 18296.4375;

I know how to calculate the distance between two points, it must be something like.

X = x2 - x1;
Y = y2 - y1;
Distance = Math.sqrt(pow(X, 2) + pow(Y, 2));

Angle:
Angle = Math.Acos(-Y, Distance) / 6.28 * 360;

But I'm not sure and maybe someone has another solution to find out the face angle


best regards
11/16/2008 14:12 unknownone#2
What you have is fine, but you could cut out the distance caclucation by using Atan(X, Y). I assume you need the distance for other calculations though anyway.
11/16/2008 14:21 syron198#3
oh yes... you're right... Thanks!

This is my function and it works perfectly.

public double angle(double x1, double y1, double x2, double y2)
{
double X = x1 - x2;
double Y = y1 - y2;

double distance = Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2));
// double result = Math.Acos(-Y / distance) / 6.28 * 360;
double result = Math.Atan(X / Y) / 6.28 * 360;
if (result < 0) result = result * -1;

return result;
}