1
$\begingroup$

I've finished my math at the Uni more than 10 years ago and now I have to code a formula for finding subj. I've done a couple of searches and people there suggest solutions like "find a normal vector", "solve the system of equations" or "derive a formula form the determinant of this matrix".

Yes I could do it, but I terribly don't want to loose a sign somewhere and spend another day debugging.

I just can't believe there isn't somewhere some simple formula which I could simply code.

Thanks in advance.

EDIT: Ok, let's define it more strict. Let's say there is a point $P=(x0,y0,z0)$ and a plane $m$, defined by three other points (i.e. which it contains): $M1=(x1,y1,z1), M2=(x2,y2,z2), M3=(x3,y3,z3)$

I would like to find a distance between the point $P$ and a plane $m$.

$\endgroup$
10
  • 1
    $\begingroup$ Is the formula $$\frac{\begin{vmatrix}x_1&y_1&z_1\\x_2&y_2&z_2\\x_3&y_3&z_3\end{vmatrix}}{\sqrt{\begin{vmatrix}x_1&y_1\\x_2&y_2\end{vmatrix}^2+\begin{vmatrix}z_1&x_1\\z_2&x_2\end{vmatrix}^2+\begin{vmatrix}y_1&z_1\\y_2&z_2\end{vmatrix}^2}}$$ sufficiently simple? $\endgroup$
    – user
    Mar 28, 2023 at 13:39
  • $\begingroup$ @user But what is this? Where is the fourth point? $\endgroup$ Mar 28, 2023 at 16:20
  • $\begingroup$ @TedShifrin The forth point (in the plane) is the reference one. $\endgroup$
    – user
    Mar 28, 2023 at 16:29
  • $\begingroup$ @user Reread the question. The fourth point is certainly not in the plane, and the plane won’t pass through it. $\endgroup$ Mar 28, 2023 at 16:54
  • $\begingroup$ @TedShifrin I read the question correctly. The forth point (which is not explicitely present in my formula) is the one of three points which determine the plane. If you'd like let it be the zero-th point. The point outside the plane is in my formula the third one. $\endgroup$
    – user
    Mar 28, 2023 at 17:59

2 Answers 2

1
$\begingroup$

The distance between a point and a plane is defined as: $$ d(P,\pi) = \frac {|Ax_0 +By_0+Cz_0+D|}{\sqrt{A^2+B^2+C^2}}, $$ where $\pi : Ax +By+Cz+D=0 $ and $P(x_0,y_0,z_0)$.

Being given three non collinear points, my suggestion is to write a function to calculate the distance and a function that outputs the coefficients of the plane (with the input: the coordinates of the known points).

Let $M_1(x_1,y_1,z_1), \; M_2(x_2,y_2,z_2), \; M_3(x_3,y_3,z_3)$. Then you can find the coefficients in the plane equation (Ax+By+Cz+D= 0) by: $$ \begin{bmatrix} x_1\;\; y_1 \;\; z_1 \;\;1 \\ x_2\;\; y_2 \;\; z_2 \;\;1 \\ x_3\;\; y_3 \;\; z_3 \;\;1 \end{bmatrix} \begin{bmatrix} A \\ B \\ C \\ D \end{bmatrix} =0 $$

$\endgroup$
2
  • 2
    $\begingroup$ This is not a definition. This is a formula to be derived by projecting a vector from $P$ to any point of $\pi$ onto the normal vector of $\pi$. $\endgroup$ Mar 28, 2023 at 18:46
  • $\begingroup$ Exactly As I've written. "Simply solve the system of equations'. $\endgroup$
    – dredkin
    Mar 29, 2023 at 9:55
0
$\begingroup$

Let the points have the coordinates $P_i=(X_i,Y_i,Z_i)$ with $i=0\dots 3$, where the points $P_0,P_1,P_2$ define the plane. Let now: $$ (x_i,y_i,z_i)=(X_i-X_0,Y_i-Y_0,Z_i-Z_0),\quad i=1,2,3. $$

Then the distance from the point $P_3$ to the plane is the absolute value of: $$\frac{x_3\cdot\begin{vmatrix}y_1&z_1\\y_2&z_2\end{vmatrix}+ y_3\cdot\begin{vmatrix}z_1&x_1\\z_2&x_2\end{vmatrix}+z_3\cdot\begin{vmatrix}x_1&y_1\\x_2&y_2\end{vmatrix}}{\sqrt{\begin{vmatrix}y_1&z_1\\y_2&z_2\end{vmatrix}^2+\begin{vmatrix}z_1&x_1\\z_2&x_2\end{vmatrix}^2+\begin{vmatrix}x_1&y_1\\x_2&y_2\end{vmatrix}^2}}.$$

$\endgroup$
2
  • $\begingroup$ Thank you, that is what I was looking for. I'm marking it as answer, I'll try to check if it works some later. $\endgroup$
    – dredkin
    Mar 31, 2023 at 6:54
  • $\begingroup$ The example values match, so I guess I did it correctly. Thank you again. Let's leave it for future programmers. $\endgroup$
    – dredkin
    Mar 31, 2023 at 14:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .