2 Boolean geometry utilities.
6 from __future__ import absolute_import
7 #Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module.
10 from fabmetheus_utilities.vector3 import Vector3
11 from fabmetheus_utilities.vector3index import Vector3Index
12 from fabmetheus_utilities import euclidean
16 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
17 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
18 __date__ = '$Date: 2008/02/05 $'
19 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
22 def _getAccessibleAttribute(attributeName):
23 'Get the accessible attribute.'
24 if attributeName in globalAccessibleAttributeDictionary:
25 return globalAccessibleAttributeDictionary[attributeName]
28 def getComplex(x=0.0, y=0.0):
32 def getCylindrical(azimuthDegrees, radius=1.0, z=0.0):
33 'Get the cylindrical vector3 by degrees.'
34 return getCylindricalByRadians(math.radians(azimuthDegrees), radius, z)
36 def getCylindricalByRadians(azimuthRadians, radius=1.0, z=0.0):
37 'Get the cylindrical vector3 by radians.'
38 polar = radius * euclidean.getWiddershinsUnitPolar(azimuthRadians)
39 return Vector3(polar.real, polar.imag, z)
41 def getNestedVectorTestExample(x=0.0, y=0.0, z=0.0):
42 'Get the NestedVectorTestExample.'
43 return NestedVectorTestExample(Vector3(x, y, z))
45 def getPolar(angleDegrees, radius=1.0):
46 'Get the complex polar by degrees.'
47 return radius * euclidean.getWiddershinsUnitPolar(math.radians(angleDegrees))
49 def getPolarByRadians(angleRadians, radius=1.0):
50 'Get the complex polar by radians.'
51 return radius * euclidean.getWiddershinsUnitPolar(angleRadians)
53 def getSpherical(azimuthDegrees, elevationDegrees, radius=1.0):
54 'Get the spherical vector3 unit by degrees.'
55 return getSphericalByRadians(math.radians(azimuthDegrees), math.radians(elevationDegrees), radius)
57 def getSphericalByRadians(azimuthRadians, elevationRadians, radius=1.0):
58 'Get the spherical vector3 unit by radians.'
59 elevationComplex = euclidean.getWiddershinsUnitPolar(elevationRadians)
60 azimuthComplex = euclidean.getWiddershinsUnitPolar(azimuthRadians) * elevationComplex.real
61 return Vector3(azimuthComplex.real, azimuthComplex.imag, elevationComplex.imag) * radius
63 def getVector3(x=0.0, y=0.0, z=0.0):
65 return Vector3(x, y, z)
67 def getVector3Index(index=0, x=0.0, y=0.0, z=0.0):
69 return Vector3Index(index, x, y, z)
72 class NestedVectorTestExample:
73 'Class to test local attribute.'
74 def __init__(self, vector3):
75 'Get the accessible attribute.'
76 self.vector3 = vector3
78 def _getAccessibleAttribute(self, attributeName):
79 "Get the accessible attribute."
80 if attributeName == 'vector3':
81 return getattr(self, attributeName, None)
85 globalAccessibleAttributeDictionary = {
86 'complex' : getComplex,
87 'getCylindrical' : getCylindrical,
88 'getCylindricalByRadians' : getCylindricalByRadians,
89 'getPolar' : getPolar,
90 'getPolarByRadians' : getPolarByRadians,
91 'getSpherical' : getSpherical,
92 'getSphericalByRadians' : getSphericalByRadians,
93 'NestedVectorTestExample' : getNestedVectorTestExample,
94 'Vector3' : getVector3,
95 'Vector3Index' : getVector3Index}