MAXScript Frequently Asked Questions
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?
This is a good place to use a Transform Script controller.
Create 3 Point Helpers - Point01, Point02 and Point03
Create a Plane primitive.
Go to Motion tab, select the Transform controller track, assign Transform Script
Enter the following Script:
dependsOn $Point01.pos.controller --update when Point01 moves
dependsOn $Point02.pos.controller --update when Point02 moves
dependsOn $Point03.pos.controller --update when Point03 moves
p1 = $Point01.pos --the position of Point01
p2 = $Point02.pos --the position of Point02
p3 = $Point03.pos --the position of Point03
v1 = normalize (p2-p1) --the vector from Point01 to Point02
v2 = normalize (p3-p1) --the vector from Point01 to Point03
nv1 = cross v1 v2 --the cross product, the normal to the plane
nv2 = cross nv1 v1 --the cross product of the normal and vector 1
--Create a matrix3 value using he first vector, the vector perpendicular
--to it and the normal to the plane and the normal vector itself.
--The translation part (.row4 which is the position) is the middle point
--of the 3 points' positions:
matrix3 v1 nv2 nv1 ((p1+p2+p3)/3)
Move / animate the points - the Plane should follow.
See also