# Find Point with only angle and distance

I'm working on a school project and we have to create a tank team with the programming game Robocode (tank battle with self programmed bots in Java).

I have to program a scout bot that scans, finds enemies and reports this to the commander bot. Now I only can find out the distance and angle of the scanned enemy bot. How can I find the X and Y position of this bot with only the known variables?

Image is better then words, so:

-
This problem has been explained very well in this anser: Get position of point on circumference of circle, given an angle?. You should be able to solve your problem with that. –  bummzack Nov 9 '11 at 8:01
when you get the position of the tank... don't you already have to have gotten the object? (in other words) you should already have a pointer to the object if you've detected that an object exists at that point- otherwise what's the point of your system? I could be off base here, let me know. –  ultifinitus Nov 9 '11 at 9:13
@ultifinitus The function gets a on scanned Event object instead of a Robot object. So the X and Y methods are not there. –  Sven van Zoelen Nov 9 '11 at 19:29
@bummzack I'm gonna try that, thx! –  Sven van Zoelen Nov 9 '11 at 19:29

Simple?

``````NewPos = new Vector2(825 * sin(85 degrees), 825 * cos(85 degrees));
``````

Most libraries use radians not degrees, so:

``````radians = degrees * PI / 180
``````

If you want the coordinates in the world reference frame, you will need to get the direction of the Tank, subt add the centre Tanks origin to the result:

``````NewDir = TankDir + 85;
NewPos = new Vector2(825 * sin(NewDir), 825 * cos(NewDir));
NewWorldPos = NewPos + TankWorldPos
``````
-
I think this will compute bad NewPos vector. It takes angle as it is related with global coordinate system. But it's related to local tank coordinate system given by tank direction vector and vector perpendicular to it. You should first recompute angle - substract part of angle, which is under X axis. –  zacharmarz Nov 9 '11 at 9:49
@zacharmaz I already mentioned that, you first compute it in the source Tank's coordinate space, then to transfer it you just add the Tanks position in the world space (see end of my answer). –  Daniel Nov 9 '11 at 10:03
No. You understood me wrong. By this, you shift yout NewPos somewhere (you take tanks position), but you do not transfer it to global coordinate system, because you don't take tanks rotation into account. So your options are: compute transformation matrix, which recomputes vector from tanks coordinate system to global coordinate system. Or it should be enough just to recompute angle in the beginning of your computation. –  zacharmarz Nov 9 '11 at 10:49
@zacharmarz Fixed, forgot to write that in originally cheers. It was a simply as just offsetting the direction to begin with. No need to use matrices to transform the coordinate spaces; unless you start moving coordinate systems around arbitrarily. –  Daniel Nov 9 '11 at 11:40

I think this will be enough if you don't use scale.

``````float Angle = RotationTankA - RelativeAngle;

PosTankB = PosTankA + new Vector2(cos(Angle), sin(Angle)) * Distance;
``````
-

I have just made up an example in C#/XNA and got it to work perfectly.

Here is the current function

``````public Vector2 GetPosition(Vector2 CurPos, float angle, float distance)
{
//Get SOH
float op = (float)Math.Sin(angle) * distance;
//Get CAH
float ad = (float)Math.Cos(angle) * distance;
``````        batch.Draw(BaseSprite, Position, null, Color.White, BaseRotation, new Vector2(BaseSprite.Width / 2, BaseSprite.Height / 2), 1, SpriteEffects.None, 0);