2 Boolean geometry utilities.
6 from __future__ import absolute_import
8 from fabmetheus_utilities.vector3 import Vector3
9 from fabmetheus_utilities.vector3index import Vector3Index
10 from fabmetheus_utilities import euclidean
14 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
15 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
16 __date__ = '$Date: 2008/02/05 $'
17 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
20 def _getAccessibleAttribute(attributeName):
21 'Get the accessible attribute.'
22 if attributeName in globalAccessibleAttributeDictionary:
23 return globalAccessibleAttributeDictionary[attributeName]
26 def getComplex(x=0.0, y=0.0):
30 def getCylindrical(azimuthDegrees, radius=1.0, z=0.0):
31 'Get the cylindrical vector3 by degrees.'
32 return getCylindricalByRadians(math.radians(azimuthDegrees), radius, z)
34 def getCylindricalByRadians(azimuthRadians, radius=1.0, z=0.0):
35 'Get the cylindrical vector3 by radians.'
36 polar = radius * euclidean.getWiddershinsUnitPolar(azimuthRadians)
37 return Vector3(polar.real, polar.imag, z)
39 def getNestedVectorTestExample(x=0.0, y=0.0, z=0.0):
40 'Get the NestedVectorTestExample.'
41 return NestedVectorTestExample(Vector3(x, y, z))
43 def getPolar(angleDegrees, radius=1.0):
44 'Get the complex polar by degrees.'
45 return radius * euclidean.getWiddershinsUnitPolar(math.radians(angleDegrees))
47 def getPolarByRadians(angleRadians, radius=1.0):
48 'Get the complex polar by radians.'
49 return radius * euclidean.getWiddershinsUnitPolar(angleRadians)
51 def getSpherical(azimuthDegrees, elevationDegrees, radius=1.0):
52 'Get the spherical vector3 unit by degrees.'
53 return getSphericalByRadians(math.radians(azimuthDegrees), math.radians(elevationDegrees), radius)
55 def getSphericalByRadians(azimuthRadians, elevationRadians, radius=1.0):
56 'Get the spherical vector3 unit by radians.'
57 elevationComplex = euclidean.getWiddershinsUnitPolar(elevationRadians)
58 azimuthComplex = euclidean.getWiddershinsUnitPolar(azimuthRadians) * elevationComplex.real
59 return Vector3(azimuthComplex.real, azimuthComplex.imag, elevationComplex.imag) * radius
61 def getVector3(x=0.0, y=0.0, z=0.0):
63 return Vector3(x, y, z)
65 def getVector3Index(index=0, x=0.0, y=0.0, z=0.0):
67 return Vector3Index(index, x, y, z)
70 class NestedVectorTestExample(object):
71 'Class to test local attribute.'
72 def __init__(self, vector3):
73 'Get the accessible attribute.'
74 self.vector3 = vector3
76 def _getAccessibleAttribute(self, attributeName):
77 "Get the accessible attribute."
78 if attributeName == 'vector3':
79 return getattr(self, attributeName, None)
83 globalAccessibleAttributeDictionary = {
84 'complex' : getComplex,
85 'getCylindrical' : getCylindrical,
86 'getCylindricalByRadians' : getCylindricalByRadians,
87 'getPolar' : getPolar,
88 'getPolarByRadians' : getPolarByRadians,
89 'getSpherical' : getSpherical,
90 'getSphericalByRadians' : getSphericalByRadians,
91 'NestedVectorTestExample' : getNestedVectorTestExample,
92 'Vector3' : getVector3,
93 'Vector3Index' : getVector3Index}