[Math] Convert 3d point onto a 2d coordinate plane of any angle and location within the 3D space

3dcoordinate systemslinear-transformations

I found this post…

Find coordinates of a 2D plane within a 3D plane

Edit: I rewrote the following for clarity…

I want to translate real-world X, Y, Z coordinates in 3d modeling software to an arbitrary 2d plane that lies within the 3d system of the software. All points in this problem will lie on the arbitrary 2d plane but are expressed as 3d points within the 3d system. I want the points expressed as 2d points within the 2d Cartesian plane, which has its own origin.

This is my best guess implementation, but I do not know if it works in all situations:

$x_o, y_o, z_o$ = given origin point of 2d plane expressed as a point in the 3d system.

$(X_u, Y_u, Z_u)$ = The transform for the 2d plane Y-direction/upwards vector relative to the 3d system; e.g. (0,0,1)

$(X_r, Y_r, Z_r)$ = The transform for the 2d plane X-direction/rightwards vector relative to the 3d system; e.g. (1,0,0)

$x_1, y_1, z_1$ = given coordinates for a point in the 3d system that lies on the 2d plane

$x_2, y_2$ = x, y of the above point as expressed as a point on the 2d Cartesian plane.

Equations:

$$x_2 = (X_r(x_1 – x_o) + Y_r(y_1 – y_o) + Z_r(z_1 – z_o))$$

$$y_2 = (X_u(x_1 – x_o) + Y_u(y_1 – y_o) + Z_u(z_1 – z_o))$$

Not remembering my high school math on the matter, I literally figured these equations out from scratch on a sheet of graph paper, so I have no idea if they are valid.

Any help is appreciated.

Best Answer

Let $(x_0, y_0, z_0)$ be the plane origin in 3D space; $(x_U, y_U, z_U)$ be the direction of the plane $u$ axis in 3D space; $(x_V, y_V, z_V)$ be the direction of the plane $v$ axis in 3D space, perpendicular to the $u$ axis; and point $(u, v)$ on the 2D plane corresponding to the same point $(x, y, z)$ in 3D space: $$\begin{cases} x = x_0 + u ~ x_U + v ~ x_V \\ y = y_0 + u ~ y_U + v ~ y_V \\ z = z_0 + u ~z_U + v ~ z_V \\ \end{cases}$$ Conversely, $$\begin{cases} \displaystyle u = \frac{(x - x_0) y_V - (y - y_0) x_V }{ x_U y_V - x_V y_U } = \frac{(x - x_0) z_V - (z - z_0) x_V }{ x_U z_V - x_V z_U } = \frac{(y - y_0) z_V - (z - z_0) y_V }{ y_U z_V - y_V z_U } \\ \displaystyle v = \frac{(y - y_0) x_U - (x - x_0) y_U }{ x_U y_V - x_V y_U } = \frac{(z - z_0) x_U - (x - x_0) z_U }{ x_U z_V - x_V z_U } = \frac{(z - z_0) y_U - (y - y_0) z_U }{ y_U z_V - y_V z_U } \\ \end{cases}$$ In a numerical application, first calculate the divisors, $x_U y_V - x_V y_U$, $x_U z_V - x_V z_U$, and $y_U z_V - y_V z_U$, and use the two with the highest magnitude. This way you get best numerical stability.

(That corresponds to using the two 3D coordinate axes most similar to the 2D plane $u$ and $v$ axes; i.e. dropping the 3D coordinate axis closest to perpendicular to the 2D plane.)

Related Question