The below formula calculates the X/Y coordinates around an X/Y center point, based on angle and distance. Now I need to reverse this formula to do the opposite: Calculate the angle/distance based on its X/Y coordinates.
This was written in Delphi, but I think this code speaks for itself:
function AroundPoint(Center: TPoint; Distance: Single; Degrees: Single): TPoint;
var
Radians: Real;
begin
Radians:= (Degrees - 135) * Pi / 180;
Result.X:= (Distance*Cos(Radians)-Distance*Sin(Radians))+Center.X;
Result.Y:= (Distance*Sin(Radians)+Distance*Cos(Radians))+Center.Y;
end;
Center= X/Y coordinates of the center point.Distance= Distance away from the center point.Degrees= Angle around center point, upward being 0 degrees.Result= X/Y coordinates of resulting point.
Basically, I need to calculate based on these parameters instead:
Center= X/Y coordinates of the center point.Position= X/Y coordinates of the current point.Result= Distance and Degrees of point, relative to Center.
How do I calculate the reverse of this formula? I'm not looking for Delphi code, but the formula itself.
Just some background on the reason: I'm creating a sample app in Delphi which simulates flying at warp speed through stars. The star positions are based on angle/distance from the center of the screen. Instead, I'd like to base positions on X/Y(/Z) coordinates initially, then move them relative to the center point.
The problem with creating the stars from center/angle/distance is that it becomes obvious from a visual standpoint, and most of them are focused towards the center. So rather than randomizing from the center point, I will randomize new stars in X/Y coordinates, then still move them from the center point.
To compute an angle $\varphi$:
So: $$\varphi (x,y) = \begin{cases}\arccos \frac{x-x_0}{r} &, y\geq y_0\\2\pi-\arccos \frac{x-x_0}{r} &, y< y_0 \end{cases}$$
To compute your angle in degrees (and moved by $135^{\circ}$): $$\theta = 135^{\circ}+ 180^{\circ}\frac{\varphi}{\pi}$$