Recalculating a point onto a custom plane

73 Views Asked by At

This is my coordinate system:

enter image description here______

Essentially, I want to know if it's possible to recalculate a point 'A' from 1 plane (ZY plane) onto another plane (B plane) more efficiently than the way I'm current doing so.

The way I'm current recalculating point A to lie on the B plane:

  1. get the vector projection of point B onto the XZ plane
    • B_XZ_PROJ = [B.x, 0, B.z]
  2. then I get the angle (theta) between The -Z axis and B_XZ_PROJ
  3. then using Rodrigues' rotation formula, I rotate point A around the +Y axis by theta to get point A'

How do I recalculate A onto plane B directly without using this rotation method?

from reading online, my guess to this approach would be:

  1. create the B plane equation using 3 points: +Y unit vector, origin, point B
  2. substitute components of A into this plane equation to get A' on plane B

is this the correct thinking?

1

There are 1 best solutions below

0
On BEST ANSWER

There does exist a more efficient method. If $\vec{p}$ is a 3D point on a source plane, we can obtain the planar coordinates $(u, v)$ via $$\vec{p} = \vec{o} + u \, \vec{u} + v \, \vec{v} \quad \iff \quad \left\lbrace \begin{aligned} u &= \vec{p} \cdot \vec{U} + U_0 = ( \vec{p} - \vec{o} ) \cdot \vec{U} \\ v &= \vec{p} \cdot \vec{V} + V_0 = ( \vec{p} - \vec{o} ) \cdot \vec{V} \\ \end{aligned} \right.$$ and use those coordinates to get the corresponding point on the second plane, $$\begin{aligned} \vec{p}^\prime &= \vec{o}^\prime + u \, \vec{u}^\prime + v \, \vec{v}^\prime \\ ~ &= \vec{o}^\prime + \bigl((\vec{p} - \vec{o})\cdot\vec{U}\bigr)\vec{u}^\prime + \bigl((\vec{p} - \vec{o})\cdot\vec{V}\bigr)\vec{v}^\prime \\ \end{aligned}$$ where$$\begin{array}{c|l|l} \text{Variable} & \text{Description} \\ \hline \vec{p} & \text{ point on original plane } \\ \vec{p}^\prime & \text{ point on other plane } \\ \vec{o} & \text{ origin on original plane } \\ \vec{o}^\prime & \text{ origin on second plane } \\ \vec{u} & u \text{ unit vector on original plane } \\ \vec{v} & v \text{ unit vector on original plane } \\ \vec{u}^\prime & u \text{ unit vector on second plane } \\ \vec{v}^\prime & v \text{ unit vector on second plane } \\ U_0 & u \text{ origin constant}, ~ - \vec{o} \cdot \vec{U} \\ V_0 & v \text{ origin constant}, ~ - \vec{o} \cdot \vec{V} \\ \vec{U} & \text{ inverse } u \text{ axis vector } \\ \vec{V} & \text{ inverse } v \text{ axis vector } \\ \end{array}$$ The $(u, v)$ coordinates correspond to 3D vectors $$\begin{array}{c|l} (u, v) & \text{ 3D Vector } \\ \hline (0, 0) & \vec{o} \\ (1, 0) & \vec{o} + \vec{u} \\ (0, 1) & \vec{o} + \vec{v} \\ (1, 1) & \vec{o} + \vec{u} + \vec{v} \\ \end{array}$$ The inverse axis vectors $\vec{U}$ and $\vec{V}$ are a bit complicated to compute, however; we have three equations and only two variables, and numerical stability should also be considered. Here is one way, derived from dropping the least useful Cartesian coordinate axis:

Let $$\vec{u} = \left[ \begin{matrix} u_x \\ u_y \\ u_z \end{matrix} \right] , \quad \vec{v} = \left[ \begin{matrix} v_x \\ v_y \\ v_z \end{matrix} \right] , \quad \vec{U} = \left[ \begin{matrix} U_x \\ U_y \\ U_z \end{matrix} \right] , \quad \vec{V} = \left[ \begin{matrix} V_x \\ V_y \\ V_z \end{matrix} \right]$$

  • Calculate $$\begin{aligned} d_{x y} &= u_x v_y - u_y v_x \\ d_{x z} &= u_z v_x - u_x v_z \\ d_{y z} &= u_y v_z - u_z v_y \\ \end{aligned}$$ from the $\vec{u}$ and $\vec{v}$ we wish to invert.

  • If $d_{x y}$ has the largest magnitude (absolute value, $\lvert d_{x y} \rvert \ge \lvert d_{x z} \rvert$ and $\lvert d_{x y} \rvert \ge \lvert d_{y z} \lvert$), then $$\vec{U} = \left[ \begin{matrix} v_y / d_{x y} \\ - v_x / d_{x y} \\ 0 \end{matrix} \right], \quad \vec{V} = \left[ \begin{matrix} -u_y / d_{x y} \\ u_x / d_{x y} \\ 0 \end{matrix} \right]$$

  • Otherwise, if $d_{x z}$ has the largest magnitude ($\lvert d_{x z} \rvert \gt \lvert d_{x y} \rvert$, $\lvert d_{x z} \rvert \ge \lvert d_{y z} \rvert$), then $$\vec{U} = \left[ \begin{matrix} -v_z / d_{x z} \\ 0 \\ v_x / d_{x z} \end{matrix} \right], \quad \vec{V} = \left[ \begin{matrix} u_z / d_{x z} \\ 0 \\ -u_x / d_{x z} \end{matrix} \right]$$

  • Otherwise, $d_{y z}$ has the largest magnitude ($\lvert d_{y z} \rvert \gt \lvert d_{x y} \rvert$, $\lvert d_{y z} \rvert \gt \lvert d_{x z} \rvert$), and $$\vec{U} = \left[ \begin{matrix} 0 \\ v_z / d_{y z} \\ -v_y / d_{y z} \end{matrix} \right], \quad \vec{V} = \left[ \begin{matrix} 0 \\ -u_z / d_{y z} \\ u_y / d_{y z} \end{matrix} \right]$$

Obviously, $\vec{U}$ and $\vec{V}$ only need to be recomputed whenever the corresponding $\vec{u}$ and/or $\vec{v}$ change.


Mapping any cuboid to $(u, v, w)$ is actually simpler, because the forward transformation is $$\left[\begin{matrix} x \\ y \\ z \end{matrix}\right] = \left[\begin{matrix} u_x & v_x & w_x \\ u_y & v_y & w_y \\ u_z & v_z & w_z \end{matrix}\right] \left[\begin{matrix} u \\ v \\ w \end{matrix}\right] + \left[\begin{matrix} o_x \\ o_y \\ o_z \end{matrix}\right]$$ and we can just invert the matrix for the inverse, $$\left[\begin{matrix} u \\ v \\ w \end{matrix}\right] = \frac{1}{d} \left[\begin{matrix} v_y w_z - v_z w_y & v_z w_x - v_x w_z & v_x w_y - v_y w_x \\ u_z w_y - u_y w_z & u_x w_z - u_z w_x & u_y w_x - u_x w_y \\ u_y v_z - u_z v_y & u_z v_x - u_x v_z & u_x v_y - u_y v_x \\ \end{matrix}\right] \left[\begin{matrix} x - o_x \\ y - o_y \\ z - o_z \end{matrix}\right]$$ where $d$ is the triple product of the three basis vectors, $$\begin{aligned} d = \vec{u} \times \vec{v} \cdot \vec{w} & = u_x v_y w_z - u_y v_x w_z \\ ~ & - u_x v_z w_y + u_z v_x w_y \\ ~ & + u_y v_z w_x - u_z v_y w_x \\ \end{aligned}$$ If you define $\vec{w}$ perpendicular to the plane, you can use this to calculate the $(u, v)$ coordinates of the point on the plane where the plane normal passes through the specified point, with $w/\lVert\vec{w}\rVert$ being the signed distance along the normal; positive if in the same direction as $\vec{w}$, negative if in the opposite direction.

(Again, $\vec{o} = (o_x, o_y, o_z)$ is the origin in $(u, v, w)$ coordinates, and $\vec{u} = (u_x, u_y, u_z)$, $\vec{v} = (v_x, v_y, v_z)$, and $\vec{w} = (w_x, w_y, w_z)$ the 3D basis vectors for the $(u, v, w)$ coordinate system. $(u=0, v=0, w=0)$ is at $\vec{o}$, $(1, 0, 0)$ is at $\vec{o}+\vec{u}$, $(1,1,1)$ is at $\vec{o}+\vec{u}+\vec{v}+\vec{w}$, and so on.)