blur959
blur959

Reputation: 5601

Plane equation for 3D vectors

I want to find a 3D plane equation given 3 points. I have got the normal calculated after applying the cross product. But the equation of a plane is known to be the normal multiply by another vector which what I am taught to be as P.OP. I substitute my main reference point as OP and i want P to be in (x, y, z) form. So that I can get something like e.g,

OP = (1, 2, 3)

I want to get something like that:

(x-1)
(y-2)
(z-3)

May I know how? Below is my reference code.(Note: plane_point_1_x(), plane_point_1_y(), plane_point_1_z() are all functions asking for the user input of the respective points)

"""
I used Point P as my reference point so I will make use of it in this section
"""

vector_pop_x = int('x') - int(plane_point_1_x())
vector_pop_y = int('y') - int(plane_point_1_y())
vector_pop_z = int('z') - int(plane_point_1_z())

print vector_pop_x, vector_pop_y, vector_pop_z

All the above is what i did, but for some reason it did not work. I think the problem lies in the x, y , z part.

Upvotes: 4

Views: 10850

Answers (5)

kwerle
kwerle

Reputation: 2401

I wish this answer already existed. Coded from http://www.had2know.com/academics/equation-plane-through-3-points.html

Supposing 3 points p1, p2, p3 - consisting of [x1, y1, z1], etc.

vector1 = [x2 - x1, y2 - y1, z2 - z1]
vector2 = [x3 - x1, y3 - y1, z3 - z1]
cross_product = [vector1[1] * vector2[2] - vector1[2] * vector2[1], -1 * vector1[0] * v2[2] - vector1[2] * vector2[0], vector1[0] * vector2[1] - vector1[1] * vector2[0]]
d = cross_product[0] * x1 - cross_product[1] * y1 + cross_product[2] * z1

a = cross_product[0]
b = cross_product[1]
c = cross_product[2]
d = d

Upvotes: 2

MasterAler
MasterAler

Reputation: 1653

If I am not mistaken, one good solution here contains mistypes

vector1 = [x2 - x1, y2 - y1, z2 - z1]
vector2 = [x3 - x1, y3 - y1, z3 - z1]

cross_product = [vector1[1] * vector2[2] - vector1[2] * vector2[1], -1 * (vector1[0] * vector2[2] - vector1[2] * vector2[0]), vector1[0] * vector2[1] - vector1[1] * vector2[0]]

a = cross_product[0]
b = cross_product[1]
c = cross_product[2]
d = - (cross_product[0] * x1 + cross_product[1] * y1 + cross_product[2] * z1)

Tried previous (author's) version, but had to check it. With couple more minuses in formulas seems correct now.

Upvotes: 5

Mike T
Mike T

Reputation: 43742

Say you have three known points, each with (x, y, z). For example:

p1 = (1, 2, 3)
p2 = (4, 6, 9)
p3 = (12, 11, 9)

Make them into symbols that are easier to look at for further processing:

x1, y1, z1 = p1
x2, y2, z2 = p2
x3, y3, z3 = p3

Determine two vectors from the points:

v1 = [x3 - x1, y3 - y1, z3 - z1]
v2 = [x2 - x1, y2 - y1, z2 - z1]

Determine the cross product of the two vectors:

cp = [v1[1] * v2[2] - v1[2] * v2[1],
      v1[2] * v2[0] - v1[0] * v2[2],
      v1[0] * v2[1] - v1[1] * v2[0]]

A plane can be described using a simple equation ax + by + cz = d. The three coefficients from the cross product are a, b and c, and d can be solved by substituting a known point, for example the first:

a, b, c = cp
d = a * x1 + b * y1 + c * z1

Now do something useful, like determine the z value at x=4, y=5. Re-arrange the simple equation, and solve for z:

x = 4
y = 5
z = (d - a * x - b * y) / float(c)  # z = 6.176470588235294

Upvotes: 5

pavpanchekha
pavpanchekha

Reputation: 2103

One good way is:

| x1 y1 z2 1 |
| x2 y2 z2 1 |
| x3 y3 z3 1 | = 0
| x  y  z  1 |

Where the vertical pipes mean the determinant of the matrix, and (x1 y1 z1), (x2 y2 z2), and (x3 y3 z3) are your given points.

Upvotes: 4

Alex Budovski
Alex Budovski

Reputation: 18456

Plane implicit Eqn:

All points P = (x, y, z) satisfying

<n, QP> = 0

where

  • n is the plane normal vector,
  • Q is some point on the plane (any will do)
  • QP is the vector from Q to P
  • <a, b> is the scalar (dot) product operator.

(Remember that QP can be computed as P - Q)

Upvotes: 3

Related Questions