C
cwsullivan
Hi gang,
I have a grid full of particles in my program, and I want to find an
angle between two particles. I'm having trouble because it seems like
the answer depends on whether or not the target particle is above or
below, in front or behind the refernce particle.
If I have a reference particle at (10,10), and another particle at
(20,20), i'm currently finding the angle by:
angle = atan((10-20)/(10-20)) = 45 degrees. When I draw this out, I can
see that the (20,20) object is 45 degrees below the x-axis from the
(10,10) object. Fine.
But if I look at another particle and compare it's angle to (10,10),
for example a particle located at (2,20), I get something kind of
different:
atan((10-20)/(10-2)) = -51.34 degrees
When I take x and y components of these angles, things don't add up.
Somtimes it gives me a negative value of x when it should be positive.
I don't think I've been very clear here, but I'm hoping this is a
common enough mistake that someone knows what I'm trying to say. I'm
wondering also if there is a better way to find a angle between two
points that might be relative to a certain axis, because it seems like
my angle is relative to different axes at different times. Thanks guys
I have a grid full of particles in my program, and I want to find an
angle between two particles. I'm having trouble because it seems like
the answer depends on whether or not the target particle is above or
below, in front or behind the refernce particle.
If I have a reference particle at (10,10), and another particle at
(20,20), i'm currently finding the angle by:
angle = atan((10-20)/(10-20)) = 45 degrees. When I draw this out, I can
see that the (20,20) object is 45 degrees below the x-axis from the
(10,10) object. Fine.
But if I look at another particle and compare it's angle to (10,10),
for example a particle located at (2,20), I get something kind of
different:
atan((10-20)/(10-2)) = -51.34 degrees
When I take x and y components of these angles, things don't add up.
Somtimes it gives me a negative value of x when it should be positive.
I don't think I've been very clear here, but I'm hoping this is a
common enough mistake that someone knows what I'm trying to say. I'm
wondering also if there is a better way to find a angle between two
points that might be relative to a certain axis, because it seems like
my angle is relative to different axes at different times. Thanks guys