本文整理汇总了Python中UM.Math.Quaternion.Quaternion类的典型用法代码示例。如果您正苦于以下问题:Python Quaternion类的具体用法?Python Quaternion怎么用?Python Quaternion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Quaternion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_toMatrix
def test_toMatrix(self):
q1 = Quaternion()
q1.setByAngleAxis(math.pi / 2, Vector.Unit_Z)
m1 = q1.toMatrix()
m2 = Matrix()
m2.setByRotationAxis(math.pi / 2, Vector.Unit_Z)
self.assertTrue(Float.fuzzyCompare(m1.at(0, 0), m2.at(0, 0), 1e-6))
self.assertTrue(Float.fuzzyCompare(m1.at(0, 1), m2.at(0, 1), 1e-6))
self.assertTrue(Float.fuzzyCompare(m1.at(0, 2), m2.at(0, 2), 1e-6))
self.assertTrue(Float.fuzzyCompare(m1.at(0, 3), m2.at(0, 3), 1e-6))
self.assertTrue(Float.fuzzyCompare(m1.at(1, 0), m2.at(1, 0), 1e-6))
self.assertTrue(Float.fuzzyCompare(m1.at(1, 1), m2.at(1, 1), 1e-6))
self.assertTrue(Float.fuzzyCompare(m1.at(1, 2), m2.at(1, 2), 1e-6))
self.assertTrue(Float.fuzzyCompare(m1.at(1, 3), m2.at(1, 3), 1e-6))
self.assertTrue(Float.fuzzyCompare(m1.at(2, 0), m2.at(2, 0), 1e-6))
self.assertTrue(Float.fuzzyCompare(m1.at(2, 1), m2.at(2, 1), 1e-6))
self.assertTrue(Float.fuzzyCompare(m1.at(2, 2), m2.at(2, 2), 1e-6))
self.assertTrue(Float.fuzzyCompare(m1.at(2, 3), m2.at(2, 3), 1e-6))
self.assertTrue(Float.fuzzyCompare(m1.at(3, 0), m2.at(3, 0), 1e-6))
self.assertTrue(Float.fuzzyCompare(m1.at(3, 1), m2.at(3, 1), 1e-6))
self.assertTrue(Float.fuzzyCompare(m1.at(3, 2), m2.at(3, 2), 1e-6))
self.assertTrue(Float.fuzzyCompare(m1.at(3, 3), m2.at(3, 3), 1e-6))
示例2: process
def process(self):
# Based on https://github.com/daid/Cura/blob/SteamEngine/Cura/util/printableObject.py#L207
# Note: Y & Z axis are swapped
transformed_vertices = self._node.getMeshDataTransformed().getVertices()
min_y_vertex = transformed_vertices[transformed_vertices.argmin(0)[1]]
dot_min = 1.0
dot_v = None
for v in transformed_vertices:
diff = v - min_y_vertex
length = math.sqrt(diff[0] * diff[0] + diff[2] * diff[2] + diff[1] * diff[1])
if length < 5:
continue
dot = (diff[1] / length)
if dot_min > dot:
dot_min = dot
dot_v = diff
self._emitProgress(1)
if dot_v is None:
self._emitProgress(len(transformed_vertices))
return
rad = math.atan2(dot_v[2], dot_v[0])
self._node.rotate(Quaternion.fromAngleAxis(rad, Vector.Unit_Y), SceneNode.TransformSpace.Parent)
rad = -math.asin(dot_min)
self._node.rotate(Quaternion.fromAngleAxis(rad, Vector.Unit_Z), SceneNode.TransformSpace.Parent)
transformed_vertices = self._node.getMeshDataTransformed().getVertices()
min_y_vertex = transformed_vertices[transformed_vertices.argmin(0)[1]]
dot_min = 1.0
dot_v = None
for v in transformed_vertices:
diff = v - min_y_vertex
length = math.sqrt(diff[2] * diff[2] + diff[1] * diff[1])
if length < 5:
continue
dot = (diff[1] / length)
if dot_min > dot:
dot_min = dot
dot_v = diff
self._emitProgress(1)
if dot_v is None:
self._node.setOrientation(self._old_orientation)
return
if dot_v[2] < 0:
rad = -math.asin(dot_min)
else:
rad = math.asin(dot_min)
self._node.rotate(Quaternion.fromAngleAxis(rad, Vector.Unit_X), SceneNode.TransformSpace.Parent)
self._new_orientation = self._node.getOrientation()
示例3: test_setByAxis
def test_setByAxis(self):
q = Quaternion()
q.setByAngleAxis(math.pi / 2, Vector.Unit_Z)
self.assertEqual(q.x, 0.0)
self.assertEqual(q.y, 0.0)
self.assertTrue(Float.fuzzyCompare(q.z, math.sqrt(2.0) / 2.0, 1e-6))
self.assertTrue(Float.fuzzyCompare(q.w, math.sqrt(2.0) / 2.0, 1e-6))
示例4: _updateLocalTransformation
def _updateLocalTransformation(self):
translation, euler_angle_matrix, scale, shear = self._transformation.decompose()
self._position = translation
self._scale = scale
self._shear = shear
orientation = Quaternion()
orientation.setByMatrix(euler_angle_matrix)
self._orientation = orientation
示例5: test_rotateVector
def test_rotateVector(self):
q1 = Quaternion()
q1.setByAngleAxis(math.pi / 2, Vector.Unit_Z)
v = Vector(0, 1, 0)
v = q1.rotate(v)
self.assertTrue(Float.fuzzyCompare(v.x, -1.0, 1e-6))
self.assertTrue(Float.fuzzyCompare(v.y, 0.0, 1e-6))
self.assertTrue(Float.fuzzyCompare(v.z, 0.0, 1e-6))
示例6: test_rotate
def test_rotate(self):
node = SceneNode()
self.assertEqual(node.getOrientation(), Quaternion())
node.rotate(Quaternion.fromAngleAxis(math.pi / 4, Vector.Unit_Z))
self.assertEqual(node.getOrientation(), Quaternion.fromAngleAxis(math.pi / 4, Vector.Unit_Z))
node.rotate(Quaternion.fromAngleAxis(math.pi / 4, Vector.Unit_Z))
self.assertEqual(node.getOrientation(), Quaternion.fromAngleAxis(math.pi / 2, Vector.Unit_Z))
示例7: test_fromMatrix
def test_fromMatrix(self):
m = Matrix()
m.setByRotationAxis(math.pi / 2, Vector.Unit_Z)
q1 = Quaternion.fromMatrix(m)
q2 = Quaternion()
q2.setByAngleAxis(math.pi / 2, Vector.Unit_Z)
self.assertTrue(Float.fuzzyCompare(q1.x, q2.x, 1e-6))
self.assertTrue(Float.fuzzyCompare(q1.y, q2.y, 1e-6))
self.assertTrue(Float.fuzzyCompare(q1.z, q2.z, 1e-6))
self.assertTrue(Float.fuzzyCompare(q1.w, q2.w, 1e-6))
示例8: __init__
def __init__(self, parent: Optional["SceneNode"] = None, visible: bool = True, name: str = "") -> None:
super().__init__() # Call super to make multiple inheritance work.
self._children = [] # type: List[SceneNode]
self._mesh_data = None # type: Optional[MeshData]
# Local transformation (from parent to local)
self._transformation = Matrix() # type: Matrix
# Convenience "components" of the transformation
self._position = Vector() # type: Vector
self._scale = Vector(1.0, 1.0, 1.0) # type: Vector
self._shear = Vector(0.0, 0.0, 0.0) # type: Vector
self._mirror = Vector(1.0, 1.0, 1.0) # type: Vector
self._orientation = Quaternion() # type: Quaternion
# World transformation (from root to local)
self._world_transformation = Matrix() # type: Matrix
# Convenience "components" of the world_transformation
self._derived_position = Vector() # type: Vector
self._derived_orientation = Quaternion() # type: Quaternion
self._derived_scale = Vector() # type: Vector
self._parent = parent # type: Optional[SceneNode]
# Can this SceneNode be modified in any way?
self._enabled = True # type: bool
# Can this SceneNode be selected in any way?
self._selectable = False # type: bool
# Should the AxisAlignedBoundingBox be re-calculated?
self._calculate_aabb = True # type: bool
# The AxisAligned bounding box.
self._aabb = None # type: Optional[AxisAlignedBox]
self._bounding_box_mesh = None # type: Optional[MeshData]
self._visible = visible # type: bool
self._name = name # type: str
self._decorators = [] # type: List[SceneNodeDecorator]
# Store custom settings to be compatible with Savitar SceneNode
self._settings = {} # type: Dict[str, Any]
## Signals
self.parentChanged.connect(self._onParentChanged)
if parent:
parent.addChild(self)
示例9: __init__
def __init__(self, parent = None, **kwargs):
super().__init__() # Call super to make multiple inheritance work.
self._children = [] # type: List[SceneNode]
self._mesh_data = None # type: MeshData
# Local transformation (from parent to local)
self._transformation = Matrix() # type: Matrix
# Convenience "components" of the transformation
self._position = Vector() # type: Vector
self._scale = Vector(1.0, 1.0, 1.0) # type: Vector
self._shear = Vector(0.0, 0.0, 0.0) # type: Vector
self._mirror = Vector(1.0, 1.0, 1.0) # type: Vector
self._orientation = Quaternion() # type: Quaternion
# World transformation (from root to local)
self._world_transformation = Matrix() # type: Matrix
# Convenience "components" of the world_transformation
self._derived_position = Vector() # type: Vector
self._derived_orientation = Quaternion() # type: Quaternion
self._derived_scale = Vector() # type: Vector
self._parent = parent # type: Optional[SceneNode]
# Can this SceneNode be modified in any way?
self._enabled = True # type: bool
# Can this SceneNode be selected in any way?
self._selectable = False # type: bool
# Should the AxisAlignedBounxingBox be re-calculated?
self._calculate_aabb = True # type: bool
# The AxisAligned bounding box.
self._aabb = None # type: Optional[AxisAlignedBox]
self._bounding_box_mesh = None # type: Optional[MeshData]
self._visible = kwargs.get("visible", True) # type: bool
self._name = kwargs.get("name", "") # type: str
self._decorators = [] # type: List[SceneNodeDecorator]
## Signals
self.boundingBoxChanged.connect(self.calculateBoundingBoxMesh)
self.parentChanged.connect(self._onParentChanged)
if parent:
parent.addChild(self)
示例10: test_multiply
def test_multiply(self):
q1 = Quaternion()
q1.setByAngleAxis(math.pi / 2, Vector.Unit_Z)
q2 = Quaternion()
q2.setByAngleAxis(math.pi / 2, Vector.Unit_Z)
q3 = q1 * q2
q4 = Quaternion()
q4.setByAngleAxis(math.pi, Vector.Unit_Z)
self.assertEqual(q3, q4)
示例11: __init__
def __init__(self, parent=None):
super().__init__() # Call super to make multiple inheritence work.
self._children = []
self._mesh_data = None
self._position = Vector()
self._scale = Vector(1.0, 1.0, 1.0)
self._orientation = Quaternion()
self._transformation = None
self._world_transformation = None
self._derived_position = None
self._derived_orientation = None
self._derived_scale = None
self._inherit_orientation = True
self._inherit_scale = True
self._parent = parent
self._enabled = True
self._selectable = False
self._calculate_aabb = True
self._aabb = None
self._aabb_job = None
self._visible = True
self._name = ""
self._decorators = []
self._bounding_box_mesh = None
self.boundingBoxChanged.connect(self.calculateBoundingBoxMesh)
self.parentChanged.connect(self._onParentChanged)
if parent:
parent.addChild(self)
示例12: test_rotate
def test_rotate(self):
node = SceneNode()
self.assertEqual(node.getOrientation(), Quaternion())
node.rotate(Quaternion.fromAngleAxis(math.pi / 4, Vector.Unit_Z))
node_orientation = deepcopy(node.getOrientation())
node_orientation.normalize() #For fair comparison.
self.assertEqual(node_orientation, Quaternion.fromAngleAxis(math.pi / 4, Vector.Unit_Z))
node.rotate(Quaternion.fromAngleAxis(math.pi / 4, Vector.Unit_Z))
node_orientation = deepcopy(node.getOrientation())
node_orientation.normalize()
self.assertEqual(node_orientation, Quaternion.fromAngleAxis(math.pi / 2, Vector.Unit_Z))
示例13: __init__
def __init__(self, parent = None):
super().__init__() # Call super to make multiple inheritence work.
self._children = []
self._mesh_data = None
self._position = Vector()
self._scale = Vector(1.0, 1.0, 1.0)
self._orientation = Quaternion()
self._transformation = None
self._world_transformation = None
self._derived_position = None
self._derived_orientation = None
self._derived_scale = None
self._inherit_orientation = True
self._inherit_scale = True
self._parent = parent
self._enabled = True
self._selectable = False
self._calculate_aabb = True
self._aabb = None
self._aabb_job = None
self._visible = True
self._name = ""
if parent:
parent.addChild(self)
示例14: lookAt
def lookAt(self, target, up=Vector.Unit_Y):
if not self._enabled:
return
eye = self.getWorldPosition()
f = (target - eye).normalize()
up.normalize()
s = f.cross(up).normalize()
u = s.cross(f).normalize()
m = Matrix([[s.x, u.x, -f.x, 0.0], [s.y, u.y, -f.y, 0.0], [s.z, u.z, -f.z, 0.0], [0.0, 0.0, 0.0, 1.0]])
if self._parent:
self._orientation = self._parent._getDerivedOrientation() * Quaternion.fromMatrix(m)
else:
self._orientation = Quaternion.fromMatrix(m)
self._transformChanged()
示例15: test_invert
def test_invert(self):
q1 = Quaternion()
q1.setByAngleAxis(math.pi, Vector.Unit_Z)
q1.invert()
q2 = Quaternion()
q2.setByAngleAxis(math.pi, -Vector.Unit_Z)
self.assertEqual(q1, q2)