Trilaterating 2D cartesian coordinates, without Z

562 Views Asked by At

I have a ton of points and distances that I would like to trilaterate. This is not an issue. However, my program takes cartesian coordinates as input and it trilaterates positions X and Y because Z is always assumed to be 0 or non existant.

My question is, how to convert my longitude latitude pairs to the cartesian input that my program requires and then converting back to longitude latitude after trilateration.

Right now I convert longitude latitude to X, Y, Z in Scala:

    val R = 6371000
    val lat = 55.596345
    val long = 12.988397
    val latR = Math.toRadians(lat)
    val longR = Math.toRadians(long)

    val x = R * Math.cos(latR) * Math.cos(longR)
    val y = R * Math.cos(latR) * Math.sin(longR)
    val z = R * Math.sin(latR)

To convert this back I do:

val lat = Math.asin(z / R)
val long = Math.atan2(y, x)
println(Math.toDegrees(lat) + " " + Math.toDegrees(long))

However, these are 3D coordinates, how can I do this with only using X, Y (2D cartesian)? If I pass X, Y to my trilateration program I can afterwards only obtain longitude since I need Z to get latitude.

The area that I'm working with is extremely small, that is why we can assume earth is flat.

1

There are 1 best solutions below

0
On BEST ANSWER

If all points belong to a small area, you can choose one of the points (with latitude $\theta_0$ and longitude $\phi_0$) as origin ($X_0=0$ and $Y_0=0$) and define the coordinates $X$ and $Y$ of the other points (having latitude $\theta$ and longitude $\phi$) as follows: $$ Y=R(\theta-\theta_0),\quad X=R(\phi-\phi_0)\cos\theta_0, $$ where $R$ is the Earth radius and all angles are measured in radians.