Odd angle / graphing problem

gummby8

New member
Joined
Sep 22, 2014
Messages
15
I have an odd trig question, that I hope my poor drawing skills can illustrate and perhaps I can coax some help with how to solve it out of someone :)

2e2eddt.png


I am trying to solve a problem for an AI that will follow a straight path to an objective. The Object needs to turn to face the destination and then move forward.

1)Unfortunately the engine used does not put the 0r / 360 degree mark on the right / East arm of a graph like one would expect, it places it at the top, or North on a compass.

2) 0 faces directly North on the compas going clockwise all the way to 6.28r / 360 degrees

3) the coordinates function like a normal graph, North / South being Positive / negative and the same for East / West

If you can see the picture I am trying to solve for X so I know what direction, in degrees, the object needs to turn to

Any help is appreciated.

Thank you
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    6.4 KB · Views: 5
Last edited:
If y is the angle from the AI's perspective and x is the angle from the normal x-y co-ordinate system perspective then, in degrees,
y = 90 - x
Of course you can always add 360 to y if you like so that if x were 360 degrees, y would be 90 degrees and not -270 degrees. Code to return angles between 180 (inclusive) and minus 180 (exclusive) might look something like
Code:
while(x < 0.0){
  x += 360.0;
}
while(x > 360.0){
  x -= 360.0;
if(x < 270.0){
  y = 90.0 - x;
}else{
  y = 450.0 - x;
}
 
If y is the angle from the AI's perspective and x is the angle from the normal x-y co-ordinate system perspective then, in degrees,
y = 90 - x
Of course you can always add 360 to y if you like so that if x were 360 degrees, y would be 90 degrees and not -270 degrees. Code to return angles between 180 (inclusive) and minus 180 (exclusive) might look something like
Code:
while(x < 0.0){
  x += 360.0;
}
while(x > 360.0){
  x -= 360.0;
if(x < 270.0){
  y = 90.0 - x;
}else{
  y = 450.0 - x;
}

I am not sure what you mean "normal x-y co-ordinate system". In the picture I provided I have 1 variable, "X" drawn. I am trying to solve for that angle which needs to be between 0 and 360 degrees, or 0-6.28r, either way.

Maybe I am just not understanding what you are trying to say. Could you possibly use the example coordinates I provided in the picture so I can better understand?

Thank you,
 
I'm not sure of the numbers so I'll use
Point A is AI at (50, -50)
Point B is Object at (-80, 50)

The arc-tangent of the slope of the line connecting A and B is atan2(-130,100) is 142.43 degrees. That means the AI would have the object at -52.43 degrees (= 90 - 142.43) and have to turn -52.43 (or 307.57) degrees to face the target.

Notice that the line from point A to point B is a directed vector and it is important to get the initial x value (142.43 degrees in this case) in the proper quadrant. That is you went -130 x units and +100 y units in going from A to B. Had the AI and object been interchanged (AI at B, object at A), you would have gone +130 x units and -100 y units in going from B to A. The angle would be atan2(130,-100)=-37.57 degrees and the AI would see the object at 127.57 degrees.
 
I'm not sure of the numbers so I'll use
Point A is AI at (50, -50)
Point B is Object at (-80, 50)

The arc-tangent of the slope of the line connecting A and B is atan2(-130,100) is 142.43 degrees. That means the AI would have the object at -52.43 degrees (= 90 - 142.43) and have to turn -52.43 (or 307.57) degrees to face the target.

Notice that the line from point A to point B is a directed vector and it is important to get the initial x value (142.43 degrees in this case) in the proper quadrant. That is you went -130 x units and +100 y units in going from A to B. Had the AI and object been interchanged (AI at B, object at A), you would have gone +130 x units and -100 y units in going from B to A. The angle would be atan2(130,-100)=-37.57 degrees and the AI would see the object at 127.57 degrees.

I think I follow now, I had to go and re-write some of the AI to compensate and I think I got it. I'll follow up in a bit.
 
Top