How do I keep a Plane aligned to 3 Point Helpers?

A user asked:

I have 3 Point Helpers which determines a plane in 3d space and I animated all of them randomly.

How can I keep a Plane object always oriented exactly to the plane determined by the Points?

Answer:

This is a good place to use a Transform Script controller because we can control both the rotation (orientation) and position of the plane with it.

The following script

If you would move or animate the points, the Plane should follow.

SCRIPT:

   --Create a plane and 3 point helper
   thePlane = Plane()
   p1 = point pos:[40,-10,30]
   p2 = point pos:[20,30,40]
   p3 = point pos:[-10,-20,30]
   --Create a Transform Script and assign it to the Plane
   ctrl = transform_script()
   thePlane.transform.controller = ctrl
   --Create three Node variables and assign the Helpers to them
   ctrl.addNode"p1" p1
   ctrl.addNode"p2" p2
   ctrl.addNode"p3" p3
   --We create a variable to hold the expression
   --We calculate the vector from Point01 to Point02
   txt ="v1 = normalize (p2.pos-p1.pos)\n"
   --and the vector from Point01 to Point03
   txt +="v2 = normalize (p3.pos-p1.pos)\n"
   --The cross productof the two vectors is the normal to the plane
   txt +="nv1 = normalize (cross v1 v2)\n"
   --Thecross product ofthenormal and vector 1gives us a third axis
   txt +="nv2=normalize(cross nv1 v1)\n"
   --We create a matrix3 value using he first vector,
   --and the two cross products which are all orthogonal to each-other.
   --The translation part .row4 is the middle point
   --of the 3 points' positions:
   txt +="matrix3 v1 nv2 nv1 ((p1.pos+p2.pos+p3.pos)/3)"
   --Assign the expression to the script controller
   ctrl.setExpression txt