本文整理汇总了Python中quaternion.Quaternion.conj方法的典型用法代码示例。如果您正苦于以下问题:Python Quaternion.conj方法的具体用法?Python Quaternion.conj怎么用?Python Quaternion.conj使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类quaternion.Quaternion
的用法示例。
在下文中一共展示了Quaternion.conj方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ratoation
# 需要导入模块: from quaternion import Quaternion [as 别名]
# 或者: from quaternion.Quaternion import conj [as 别名]
#.........这里部分代码省略.........
are ignored and rx's components are copied into this object.
Note that the vector will automatically be converted into a unit vector.
A RotationException is raised if input arguments are of invalid types.
"""
try:
self.__r = Point3D(rx, ry, rz)
except PointException:
raise RotationException("Invalid input argument")
self.__update()
def setAngle(self, angle=0.0):
"""
Sets a new angle of rotation.
Rotation vector's components remain unmodified.
Input:
- angle - angle of rotation in radians (default: 0)
A RotationException is raised if 'angle' is not a float or integer value.
"""
if not InstanceCheck.isFloat(angle):
raise RotationException("Angle must be float value")
self.__theta = angle
self.__update()
def __update(self):
# A private method, called after any rotation component (vector or angle)
# is modified. It normalizes the vector (its length must be 1),
# updates self.__r and recalculates the rotation quaternion (self.__q).
#
# A RotationException is raised if any quaternion operation fails.
try:
# copy vector's components into the quaternion and normalize it:
self.__q = Quaternion(0.0, self.__r.x, self.__r.y, self.__r.z).unit()
# update __r to a unit vector
self.__r.x = self.__q.getI()
self.__r.y = self.__q.getJ()
self.__r.z = self.__q.getK()
# Calculate the rotation quaternion, depending on rot. vector and angle:
# For more info, see::
# http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation
self.__q *= math.sin(0.5 * self.__theta)
self.__q += math.cos(0.5 * self.__theta)
except QuaternionException as qex:
raise RotationException("Could not generate a rotation quaternion: '{0}'".format(qex))
def getAxis(self, factor=1.0):
"""
Returns the axis of rotation, represented by a vector (an instance of Point3D).
Note that a unit vector, multiplied by the factor (default: 1) will be returned.
"""
return Point3D(self.__r.x * factor, self.__r.y * factor, self.__r.z * factor)
def getAngle(self):
"""Returns the angle of rotation in radians."""
return self.__theta
def getRotationQuaternion(self):
"""Returns a rotation quaternion."""
return self.__q
def rotate(self, p):
"""
Performs a rotation of point 'p' around the previously specified
axis of rotation by the previoulsy specifed angle.
Input:
- p - a point ot be rotated (an instance of Point3D)
Returns coordinates of the rotated point (an instance of Point3D).
A RotationException is raised if 'p' is not an instance of Point3D.
"""
if not Point3D.isPoint3D(p):
raise RotationException("Input must be an instance of Point3D")
# For more info about rotation using quaternions, see:
# http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation
pq = Quaternion(0, p.x, p.y, p.z)
pqr = self.__q * pq * self.__q.conj()
return Point3D(pqr.getI(), pqr.getJ(), pqr.getK())
@staticmethod
def deg2rad(deg):
"""Conversion from angle degrees to radians"""
return deg * math.pi / 180.0
@staticmethod
def rad2deg(rad):
"""Conversion from radians to angle degrees"""
return rad * 180.0 / math.pi