View Full Version : How to align a plane from 4 points?

04 April 2012, 07:20 AM
Hi all, i need a help please:
How to align a plane from 4 points?
I found this script but only for 3 points:

thePlane = Plane()
p1 = point pos:[40,-10,30]
p2 = point pos:[20,30,40]
p3 = point pos:[-10,-20,30]
ctrl = transform_script()
thePlane.transform.controller = ctrl
ctrl.addNode "p1" p1
ctrl.addNode "p2" p2
ctrl.addNode "p3" p3
txt = "v1 = normalize (p2.pos-p1.pos)\n"
txt += "v2 = normalize (p3.pos-p1.pos)\n"
txt += "nv1 = normalize (cross v1 v2)\n"
txt += "nv2 = normalize(cross nv1 v1)\n"
txt += "matrix3 v1 nv2 nv1 ((p1.pos+p2.pos+p3.pos)/3)"
ctrl.setExpression txt

Thank, thanks in advance.

04 April 2012, 08:39 AM
any 3 points always form a plane, but not 4. You need to check if all of your 4 points are in the same plane and only then align your plane.
possible check:
if dot (cross (p2 - p1) (p3 - p1)) p4 == 0 then all your points are in one plane. And you can take any 3 from these 4 points to align your plane (use your script for example)

04 April 2012, 12:21 PM
3ak, thanks for the explanation

CGTalk Moderation
04 April 2012, 12:21 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.