views:

145

answers:

5

I've got a arbitrary collection of 3d points, i know they're coplanar, but how do i calculate that plane?

+2  A: 

Assuming that they are co-planar, pick three points, and try this:

http://www.jtaylor1142001.net/calcjat/Solutions/VPlanes/VP3Pts.htm

Dycey
Careful! It only works if the three points are not colinear.
Martinho Fernandes
+14  A: 

Take any three distinct points, and form a triangle of non-zero area. Compute the cross product of two of the triangle's sides. That gives you the plane's normal, and you can use the common point as a point on the plane.

A point on a plane plus a normal defines a plane.

unwind
Ça plane pour toi!
bzlm
Of course the three points should be non-linear.
Niyaz
@Niyaz: Of course. I edited to make it clearer what is required of the points selected.
unwind
The easy way to check that three points are distinct and not colinear is that the cross-product of those vectors is non-zero. No need for the code to calculate the area of the triangle.
Steve Jessop
@onebyone: True. I didn't mean that literally, I meant "the points must form a triangle with non-zero area". How to do the testing is a separate question, piggy-backing on the cross product sounds like a great choice.
unwind
@bzlm: nice to see French on this barbaric site from times to times!
Matthieu M.
+3  A: 

If they're not all planar, calculate the coefficients of the plane using a least squares fit.

The equation for a plane is Ax + By + Cz = D, so plug in your points and solve for the four unknown coefficients.

UPDATE: Just curious - how do you "know" that all the points are in the same plane? What makes you so certain?

duffymo
+2  A: 

Because any three non-colinear points define a plane, a possible answer is...

Simply grab the first three points that are not colinear.

Martinho Fernandes
+1  A: 

Another way to define a plane is a function from two parameters to a point. If you have three points A,B,C, then the function f(i,j) = A + (B-A)i + (C-A)j covers all the points on the plane.

Depending on your application it may be useful to normalise the b = (B-A) and c = (C-A) vectors to be perpendicular and of unit length. Unit length is easy.

In order to make them perpendicular, first normalise b, then take the dot product of b and c. This is the amount the the c vector points in the same direction as b, so substract this from c. c = c - (b.c)b Finally normalise c (i.e. divide by it's length)

Phil