scripted/manipulatorMath.py
39 import maya.OpenMaya
as OpenMaya
56 def setPlane(self,pointOnPlane,normalToPlane):
57 _normalToPlane = normalToPlane
58 _normalToPlane.normalize()
61 self.a = _normalToPlane.x
62 self.b = _normalToPlane.y
63 self.c = _normalToPlane.z
64 self.d = -(self.a*pointOnPlane.x + self.b*pointOnPlane.y + self.c*pointOnPlane.z)
66 def intersect(self,linePoint,lineDirection):
68 denominator = self.a*lineDirection.x + self.b*lineDirection.y + self.c*lineDirection.z
70 if denominator < .00001:
71 return (
False,intersectionPoint)
73 t = -(self.d + self.a*linePoint.x + self.b*linePoint.y + self.c*linePoint.z) / denominator
76 scaledLineDirection =
OpenMaya.MVector(lineDirection.x*t,lineDirection.y*t,lineDirection.z*t)
77 intersectionPoint = linePoint + scaledLineDirection
79 return (
True,intersectionPoint)
90 def setLine(self,linePoint,lineDirection):
91 self.point = linePoint
92 self.direction = lineDirection
93 self.direction.normalize()
95 def closestPoint(self,toPoint):
96 t = self.direction * ( toPoint - self.point )
97 closest = self.point + ( self.direction * t )
103 class degreeRadianConverter:
104 M_PI = 3.14159265358979323846
105 def degreesToRadians(self,degrees):
106 return degrees * ( self.M_PI / 180.0 )
107 def radiansToDegrees(self,radians):
108 return radians * ( 180.0 / self.M_PI)
114 def maxOfAbsThree(a,b,c):
118 if aa > ab
and aa > ac:
120 if ab > aa
and ab > ac:
129 drc = degreeRadianConverter()
130 r = drc.degreesToRadians( 45 )
133 d = drc.radiansToDegrees( drc.M_PI/4.0 )
140 lm.setLine( point, direction )
142 (worked,closestPoint) = lm.closestPoint(toPoint)
144 print "closest point to line: %g %g %g" % (closestPoint.x,closestPoint.y,closestPoint.z)
146 print "Failed to find closest point to line"
152 if __name__ ==
"__main__":