How to find the corresponding 2D Cartesian coordinates from 3D ellipsoid?

803 Views Asked by At

I want to implement trilateration algorithm in short distance (maximum 50 meters), so instead of calculating intersections among spheres, I can roughly deal with it as finding intersections among circles on a plain. And I can get the (lat,lon) from my gps and convert it into 3D Cartesian coordinates.(I'm projecting (lat,lon) to WGS84) I haven't played with geometry for a while, so my questions is, how to convert the 3D Cartesian coordinates on a sphere to 2D Cartesian coordinates on a circle?

1

There are 1 best solutions below

0
On BEST ANSWER

This is not an answer to the stated question; rather, this is a how-to for obtaining 2D or 3D coordinates via trilateration with quite simple math.

Although not very useful for GPS location data (due to jitter etc. at this scale), this could be used with e.g. ultrasonic transducers with timing info provided via wired or radio-frequency connection, using the delay between the two to detect the distance to each.

If you have three locators, and know the delay/distance between one pair, and between each to current location, you can obtain 2D or 3D coordinates (based on the plane defined by the locators) with just basic math as shown below. This is lightweight enough to do even on a weak microcontroller.


Trilateration is simple even in 3D, if you do the majority of the calculations in the plane defined by your three control points. You can trivially obtain the 2D coordinates with respect to that plane. To obtain the 3D coordinates, you additionally solve the distance to the plane, and project the obtained coordinates back to the original coordinate system.

(A long time ago I contributed the projection method (most of "preliminary computations") to the Wikipedia Trilateration article; before that, it used trigonometric functions to rotate and manipulate the coordinate system. If you see trilateration documentation that uses any trigonometric functions like $\sin$, $\cos$, $\tan$, or their inverses (arcus functions), don't rely on it; it is a ridiculously complicated way to do it.)

Let's assume you have three known points, $\vec{P}_1$, $\vec{P}_2$, and $\vec{P}_3$, whose coordinates (and distances to) are known.

First, we move to an easier coordinate system, with $z=0$ on the plane of the known points, origin at $\vec{P}_1$, and $x$ axis towards $\vec{P}_2$. $y$ axis will be perpendicular to $x$ of course, and increases to the side $\vec{P}_3$ is on. To get a normal Cartesian coordinate system ($x$ increasing right and $y$ up), assign the three known points in counterclockwise order.

The distance between $\vec{P}_1$ and $\vec{P}_2$ is $d$. The new $y$ axis increases towards $\vec{P}_3$, which will be at $(i,j)$ in the new coordinates. Note that the scale is the same in both old and new coordinates; only the origin and orientation differs. $$d = \left\lVert \vec{P}_2 - \vec{P}_1 \right\rVert$$ $$\hat{e}_x = \frac{ \vec{P}_2 - \vec{P}_1 }{ d }$$ $$i = \hat{e}_x \cdot \left ( \vec{P}_3 - \vec{P}_1 \right )$$ $$\hat{e}_y = \frac{ \vec{P}_3 - \vec{P}_1 - i \hat{e}_x }{ \left\lVert \vec{P}_3 - \vec{P}_1 - i \hat{e}_x \right\rVert }$$ $$j = \hat{e}_y \cdot \left ( \vec{P}_3 - \vec{P}_1 \right )$$

The direction perpendicular to the plane formed by the three known points in the original coordinate system is $\hat{e}_z = \hat{e}_x \times \hat{e}_y$.

Note that if $j = 0$, the three known points $\vec{P}_1$, $\vec{P}_2$, and $\vec{P}_3$ are collinear, and are not a suitable triplet for trilateration.

If we know the distances to the three known points, say $r_1$, $r_2$, and $r_3$, we can calculate the coordinates in the new coordinate system trivially. Note that $r_1$, $r_2$, and $r_3$ are in new coordinate system units, i.e. the distance between $\vec{P}_1$ and $\vec{P}_2$ is $1$. If you instead have direct propagation times $t_1$, $t_2$, and $t_3$, and you know that the propagation time from $\vec{P}_1$ to $\vec{P}_2$ is $\tau$, then $$r_1 = \frac{t_1}{\tau}, \; r_2 = \frac{t_2}{\tau}, \; r_3 = \frac{t_3}{\tau}$$ $$\begin{cases} x = \frac{r_1^2 - r_2^2 + d^2}{2 d} \\ y = \frac{r_1^2 - r_3^2 + i^2 + j^2}{2 j} \\ z = \pm\sqrt{r_1^2 - x^2 - y^2} \end{cases}$$ If you are only interested in the planar coordinates, in the plane formed by the three known points, just ignore the $z$ coordinate here.

Also remember that in these new coordinates, $\vec{P}_1$ is at $(0,0,0)$, $\vec{P}_2$ is at $(d,0,0)$, and $\vec{P}_3$ is at $(i,j,0)$. This is very useful for planar mapping.

If you want to map the coordinates $(x,y,z)$ to the original coordinates, use $$\vec{p} = \vec{P}_1 + x \hat{e}_x + y \hat{e}_y + z \hat{e}_z$$

Note that you only need basic math operations to implement all the above: addition, subtraction, multiplication, division, and square root.