1 from __future__
import division
40 from builtins
import object
41 import maya.OpenMaya
as OpenMaya
46 class planeMath(object):
58 def setPlane(self,pointOnPlane,normalToPlane):
59 _normalToPlane = normalToPlane
60 _normalToPlane.normalize()
63 self.a = _normalToPlane.x
64 self.b = _normalToPlane.y
65 self.c = _normalToPlane.z
66 self.d = -(self.a*pointOnPlane.x + self.b*pointOnPlane.y + self.c*pointOnPlane.z)
68 def intersect(self,linePoint,lineDirection):
70 denominator = self.a*lineDirection.x + self.b*lineDirection.y + self.c*lineDirection.z
72 if denominator < .00001:
73 return (
False,intersectionPoint)
75 t = -(self.d + self.a*linePoint.x + self.b*linePoint.y + self.c*linePoint.z) / denominator
78 scaledLineDirection =
OpenMaya.MVector(lineDirection.x*t,lineDirection.y*t,lineDirection.z*t)
79 intersectionPoint = linePoint + scaledLineDirection
81 return (
True,intersectionPoint)
87 class lineMath(object):
92 def setLine(self,linePoint,lineDirection):
93 self.point = linePoint
94 self.direction = lineDirection
95 self.direction.normalize()
97 def closestPoint(self,toPoint):
98 t = self.direction * ( toPoint - self.point )
99 closest = self.point + ( self.direction * t )
100 return (
True,closest)
105 class degreeRadianConverter(object):
106 M_PI = 3.14159265358979323846
107 def degreesToRadians(self,degrees):
108 return degrees * ( self.M_PI / 180.0 )
109 def radiansToDegrees(self,radians):
110 return radians * ( 180.0 / self.M_PI)
116 def maxOfAbsThree(a,b,c):
120 if aa > ab
and aa > ac:
122 if ab > aa
and ab > ac:
131 drc = degreeRadianConverter()
132 r = drc.degreesToRadians( 45 )
135 d = drc.radiansToDegrees( drc.M_PI/4.0 )
142 lm.setLine( point, direction )
144 (worked,closestPoint) = lm.closestPoint(toPoint)
146 print(
"closest point to line: %g %g %g" % (closestPoint.x, closestPoint.y, closestPoint.z))
148 print(
"Failed to find closest point to line")
154 if __name__ ==
"__main__":