'How to get coordinates of a point in a coordinate system based on angle and distance
How to get coordinates of a point in a coordinate system when all I have is the origin coordinates (x, y) and the angle from the origin to the point and the distance from the origin to the point?
Solution 1:[1]
If r is the distance from origin and a is the angle (in radians) between x-axis and the point you can easily calculate the coordinates with a conversion from polar coordinates:
x = r*cos(a)
y = r*sin(a)
(this assumes that origin is placed at (0,0), otherwise you should add the displacement to the final result).
The inverse result is made by computing the modulo of the vector (since a distance + angle make a vector) and the arctangent, which can be calculated by using the atan2 funcion.
r = sqrt(x*2+y*2)
a = atan2(y,x)
Solution 2:[2]
If d is the distance and A is the angle, than the coordnates of the point will be
(x+d*Cos(A), y+ d*Sin(A))
Solution 3:[3]
px = x + r * cos(phi)
py = y + r * sin(phi)
where [px py] is the point you are searching for, [x y] is the "origin", r is the distance and phi is the angle to the target from the origin.
EDIT: http://en.wikipedia.org/wiki/Polar_coordinate_system This link which was helpfully posted by Bart Kiers could yield some background information.
Solution 4:[4]
Short answer
// math equations
pointX = distance * cos(angle) + x
pointY = distance * sin(angle) + y
// java code [angle in radian]
double pointX = distance * Math.cos(Math.toRadians(angle)) + x;
double pointY = distance * Math.sin(Math.toRadians(angle)) + y;
Detailed answer
As per below diagram
// finding pointX let's start by
cos(angle) = (pointX - x) / distance
distance * cos(angle) = (pointX - x)
(pointX - x) = distance * cos(angle)
pointX = distance * cos(angle) + x
// finding pointY let's start by
sin(angle) = (pointY - y) / distance
distance * sin(angle) = (pointY - y)
(pointY - y) = distance * sin(angle)
pointY = distance * sin(angle) + y
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jack |
| Solution 2 | |
| Solution 3 | Hannes Ovrén |
| Solution 4 |

