Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

so I have the x,y,z value for 3 points to define a plane in 3d space.

I need to find the z value of an arbitrary point given the x,y.

I can sort of see some ways to calculate this, but they seem like they might be doing a lot of extra steps.

I eventually need to encapsulate the process in a algorithm for a computer program, so the fewer steps the better.

share|cite|improve this question
up vote 4 down vote accepted

The simplest way is to first find the equation of the plane.

So, suppose you are given three points, $$ (a_1,b_1,c_1),\quad (a_2,b_2,c_2),\quad (a_3,b_3,c_3).$$

I'm first going to assume everything will work out fine; I'll point out the possible problems later.

  1. First, construct two vectors determined by these three points: $$\begin{align*} \mathbf{v}_1 &= (a_1,b_1,c_1) - (a_2,b_2,c_2) = (a_1-a_2, b_1-b_2, c_1-c_2).\\ \mathbf{v}_2 &= (a_1,b_1,c_1) - (a_3,b_3,c_3) = (a_1-a_3, b_1-b_3, c_1-c_3). \end{align*}$$

  2. Then, compute their cross product: $$\mathbf{n} = \mathbf{v}_1\times\mathbf{v}_2 = (r,s,t).$$

  3. The plane you want has equation $rx + sy + tz = k$ for some $k$. To find $k$, plug in one of the points you have, say $(a_1,b_1,c_1)$, so you know that $$k = ra_1 + sb_1 + tc_1.$$

  4. Finally, given the $x$ and $y$ coordinate of a point, you can find the value of $z$ by solving: $$z = \frac{1}{t}\left( ra_1 + sb_1 + tc_1 - rx - sy\right).$$

What can go wrong?

  • For three points to determine a unique plane, you need the three points to not be collinear (not lie on the same line). You will find this when you compute the vector $\mathbf{n}$. If $\mathbf{n}=(0,0,0)$, then $\mathbf{v}_1$ and $\mathbf{v}_2$ are parallel, so that means that the three points are collinear and don't determine a unique plane. So you can just test $\mathbf{n}$ to see if it is nonzero before proceedings.

  • It's possible for there to not be a unique value of $z$ that goes with the given $x$ and $y$. This will happen if $\mathbf{n}$ has the form $\mathbf{n}=(r,s,0)$. Then either the given $x$ and $y$ satisfy the equation you get, in which case every value of $z$ works; or else the given $x$ and $y$ do not satisfy the equation you get and no value of $z$ works.

Example. Suppose you are given $(1,2,3)$, $(1,0,1)$, and $(-2,1,0)$. Then $$\begin{align*} \mathbf{v}_1 &= (1,2,3) - (1,0,1) = (0,2,2).\\ \mathbf{v}_2 &= (1,2,3) - (-2,1,0) = (3,1,3). \end{align*}$$ Then $$\begin{align*} \mathbf{n} &= \mathbf{v}_1\times\mathbf{v}_2 = \left|\begin{array}{rrr} \mathbf{i} & \mathbf{j} & \mathbf{k}\\ 0 & 2 & 2\\ 3 & 1 & 3 \end{array}\right|\\ &= ( 6-2, 6- 0, 0-6) \\ &= (4,6,-6). \end{align*}$$ So the plane has equation $4x + 6y - 6z = k$. To find $k$, we plug in $(1,2,3)$: $$ 4(1) + 6(2) - 6(3) = -2,$$ so the plane has equation $$4x + 6y - 6z = -2$$ or $$2x + 3y - 3z = -1.$$

Then, given two values of $x$ and $y$, say, $x=7$ and $y=-2$, you plug them in and solve for $z$: $$z = \frac{1}{-3}(-1 -2(7) -3(-2)) = \frac{1 + 14 - 6}{3} = 3,$$ so the point is $(7,-2,3)$.

share|cite|improve this answer
Thank you so much. It worked perfectly. – Joel Barsotti Mar 20 '11 at 16:28

If you have three points, you can represent the plane by finding vectors $z-x$ and $y-x$, and converting them into an equation (cross product produces a normal vector that defines the plane). Now given that equation, you plug in the $x$, $y$ values of a point, and tell the computer to solve for $z$ such that the equation of $Ax+By+Cz+D=0$ holds true, where $A$, $B$, and $C$ are coordinates of your normal vector. Alternatively, you can just tell the computer to solve the equation of $z=\frac{-D-Ax-By}{C}$.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.