Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 985
blur959 Avatar asked Dec 02 '22 06:12

blur959


1 Answers

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
like image 70
Mike T Avatar answered Dec 03 '22 18:12

Mike T