# Transform from global coordinate system to a local

I have a plane in $\mathbb R^3$, defined by a direction vector $$\vec n= \langle n_x,n_y,n_z\rangle$$ and a point $C(X_1,Y_1,Z_1)$. The direction of the normal unit vector $\vec n$ is described from plane's altitude and azimuth angles $\alpha, A$ respectively as: $$\vec n = \langle\cos(\alpha) \sin(A), \cos(\alpha)\cos(A), \sin(\alpha)\rangle.$$ Assume a point $P(X_P, Y_P, Z_P)$ which lies on the plane (e.g intersection point between a line and plane).

How can I convert point $P(X_P,Y_P,Z_P)$ from the global coordinate system to plane's local coordinate system and finally get $p(x_p, y_p, 0)$?

All uppercase $X,Y,Z$ refer to global coordinate system.

All lowercase $x,y,z$ to plane's local coordinate system.

• In case it matters to you, the formulas in my answer give a set of plane coordinates, not the set of plane coordinates. (There does not exist a unique choice of plane coordinates.) These formulas are numerically unstable for planes whose normal vector is close to $\pm(0, 0, 1)$; for topological reasons, there's no way to avoid this issue entirely. Apr 29, 2015 at 17:12
• @user86418 Thank you for the clarification.
– T81
Apr 30, 2015 at 10:53

If $n = \pm\langle 0, 0, 1\rangle$, then $Z_{P} = 0$ and your point is already in the desired form.

Otherwise, $u_{1} = \langle -\cos(A), \sin(A), 0\rangle$ and $u_{2} = n \times u_{1} = \langle -\sin(\alpha) \sin(A), -\sin(\alpha) \cos(A), \cos(\alpha)\rangle$ are an orthonormal basis for your plane, and \begin{align*} x_{P} &= (P - C) \cdot u_{1} = -(X_{P} - X_{1}) \cos(A) + (Y_{P} - Y_{1}) \sin(A), \\ y_{P} &= (P - C) \cdot u_{2} = -(X_{P} - X_{1})\sin(\alpha) \sin(A) - (Y_{P} - Y_{1})\sin(\alpha) \cos(A) + (Z_{P} - Z_{1})\cos(\alpha). \end{align*}

• Thank you very much! I'm trying a case: tube.geogebra.org/student/m1110279 Plane from: Point: $C = (-4, 2, 1)$ Normal vector: $H = \langle-0.12, -0.24, 0.86\rangle$ Point A on plane: $A = (2.67, -1.51, 0.95)$ I compute: $a = arcsin(H_2) = 1.03$ $A = \begin{cases} 2\pi - \frac{H_1}{cos(a)}, & \text{if A$\lt$0} \\ \frac{H_1}{cos(a)}, & \text{if A$\ge$0} \end{cases} = 4.22$ $u_1 = \langle-0.47, -0.88, 0\rangle, u_2 = \langle0.76, 0.4, 0.22\rangle$ And at last: $x_e = 6.12$, $y_e = 3.63$ But $\lVert e\rVert = 7.22 \ne \lVert CE\rVert = 7.54$ Did I get something wrong?
– T81
Apr 30, 2015 at 10:51
• @T81: It appears your $H$ isn't a unit vector. (To fix this, divide $H$ by $\|H\|$. :) Possibly as a result, $u_{1}$ and $u_{2}$ aren't unit vectors. (With $u_{1}$ the issue may be round-off error, but $\|u_{2}\| \approx 0.8866$.) Actually, your $u_{1}$ and $u_{2}$ aren't orthogonal, either.... Apr 30, 2015 at 11:20
• I'd assumed you knew the altitude and azimuth of your plane. :) Rather than using inverse trig functions: If $n = (a, b, c)$ is a unit vector, then $$u_{1} = \frac{(-b, a, 0)}{\sqrt{a^{2} + b^{2}}},\qquad u_{2} = n \times u_{1} = \frac{(-ca, -cb, a^{2} + b^{2})}{\sqrt{a^{2} + b^{2}}}.$$Then use $x_{P} = (P - C) \cdot u_{1}$ and $y_{P} = (P - C) \cdot u_{2}$. Apr 30, 2015 at 11:27
• Great! Indeed $H$ was not a unit vector. When converted and proceed either with the invert trig functions or using the above recommendation, I got $x_e = 7.54$, $y_e = -0.16$ and $\lVert e\rVert = 7.54$. Actually I prefer to avoid inverse trig functions. Thank you again! :)
– T81
Apr 30, 2015 at 12:03
• In case I want the result $x_e = -7.54$, $y_e = +0.16$ can I go: $u_1 = \frac{(b, -a, 0)}{\sqrt{a^2 + b^2}}$?
– T81
Apr 30, 2015 at 12:15