maths help wanted

Soldato
Joined
15 Feb 2011
Posts
10,234
Location
Slough
I'm working on a programming assignment for my evolutionary computing module and I'm getting very confused over a small part of it. We are programming robots for the game robocode, and I need to get the x and y co-ordinates of my opponents.

I know my robot's x and y co-ordinate; I know my robot's bearing (with the Y axis being north); I know the distance to my opponent and I know the angle I would need to turn to get to that robot. I'm sure there's an easy way to get my opponent's x and y co-ordinates from this information but what I thought would work is giving me totally wrong answers, so any help would be appreciated
 
SOH CAH TOA

Basic Trig though I am awful when it comes to pressing the correct buttons on a calculator. You will start with SOH or CAH as you know the hypotenuse (distance). Once you get one side of the triangles length I would think you can use Pythag to work out the length of the other side of the triangle. Add / subtract the lengths to your own coordinates to figure out where the other is.

Edit: For you angle you would have to adjust accordingly for the direction you are facing and the bearing that the other robot is on.
 
Last edited:
SOH CAH TOA

Basic Trig though I am awful when it comes to pressing the correct buttons on a calculator. You will start with SOH or CAH as you know the hypotenuse (distance). Once you get one side of the triangles length I would think you can use Pythag to work out the length of the other side of the triangle. Add / subtract the lengths to your own coordinates to figure out where the other is.

thats what i'm doing, but for some reason the results i'm getting are so vastly out that a robot that is near the right hand side edge of the battlefield is being given as off the battlefield on the left.

*edit*
i was hoping there might be some way to do this using vectors but its been years since i've used them


Are you treating your robot's starting position as the origin?

the origin is considered the bottom left of the battlefield, but i have already taken that into account to get the proper x and y coordinates
 
When I mention about pressing the buttons on the calc in the correct order are you simply going wrong here too? I can never remember the reason why but sometimes you have to press inverse? before the trig function.
 
When I mention about pressing the buttons on the calc in the correct order are you simply going wrong here too? I can never remember the reason why but sometimes you have to press inverse? before the trig function.

I already have the angle, so I dont need to do the inverse sin or cos anywhere. it was a good call though because I'm very likely to do that in my code (i'm programming this in c# for anyone that cares)
 
List your X, Y position. You bearing from North and the angle / distance. I'll see what I can come up with. Is the angle from your bearing or from North?
 
List your X, Y position. You bearing from North and the angle / distance. I'll see what I can come up with. Is the angle from your bearing or from North?

the angle it gives me is the amount my own robot would have to turn to face my opponent. The angle i want is the angle you would have to turn clockwise to face my opponent if you were facing north to start with.

this needs to work with all positions since the robots can move about in the battle, so i'm not sure what good giving an example would be. however, here is something picked out of the air.

my robot's position = (135, 270)
my robot's heading = 230 degrees
angle my robot would have to turn to face my opponent = 24 degrees (positive = clockwise, negative = anticlockwise) *fixed
distance to my opponent = 100

theoretically that should give my opponents position to be ~(38.9, 242.4) *fixed
(if you remember to use the correct angle :rolleyes:)
 
Last edited:
I can't see why SOC CAH TOA aren't working, you're remembering to apply signage according to quadrant?

If I were approaching it I'd take the view that the battlefield was moving around me rather than me moving around the battlefield (from a programming standpoint this is probably a 'bad thing' as there's an extra calculation step) so if you assume that you're always the origin and always facing along the x-axis then just base everything off that.
 
I can't see why SOC CAH TOA aren't working, you're remembering to apply signage according to quadrant?

If I were approaching it I'd take the view that the battlefield was moving around me rather than me moving around the battlefield (from a programming standpoint this is probably a 'bad thing' as there's an extra calculation step) so if you assume that you're always the origin and always facing along the x-axis then just base everything off that.

Yes, i'm calculating things separately depending on what quadrant it is in just to make sure of this. i also have separate calculations for exactly 0, 90, 180 or 270 degrees.

For the problem i have posed your suggestion of moving the origin to my robots position is a nice one, but it would make the rest of my program horrid
 
After correcting my rotation direction I too came up with 38.78, 242.44

I'm amazed my old brain still functions that well :D
 
After correcting my rotation direction I too came up with 38.78, 242.44

I'm amazed my old brain still functions that well :D
well, considering I calculated that by doing what my algorithm should be doing, it points towards a coding error. I've already found one place where i put a less than sign where a greater than should have been, but that was for the Y coordinates, and it was the x co-ordiante that was definitely wrong

thanks for the help guys. i dont think there's much you can do without me posting my code on here (which i really dont want to do considering how much this coursework is worth)
 
You know the coordinates of your robot in relation to the origin of the battlefield.

You know the distance/direction of your opponent in relation to your robot.

To get the coordinates of the opponent in relation to the battlefield, you need to calculate the coordinates of your opponent with your robot as the origin, then add these coordinates to the coordinates of your robot.
 
Back
Top Bottom