# ----------------------------------------------------------------------------# SymForce - Copyright 2022, Skydio, Inc.# This source code is under the Apache 2.0 license found in the LICENSE file.# ----------------------------------------------------------------------------from__future__importannotationsfromsymforceimporttypingasTfromsymforce.ops.interfacesimportGroupfrom.quaternionimportQuaternion
[docs]classDualQuaternion(Group):""" Dual quaternions can be used for rigid motions in 3D. Similar to the way that rotations in 3D space can be represented by quaternions of unit length, rigid motions in 3D space can be represented by dual quaternions of unit length. This fact is used in theoretical kinematics, and in applications to 3D computer graphics, robotics and computer vision. References: https://en.wikipedia.org/wiki/Dual_quaternion """def__init__(self,real_q:Quaternion,inf_q:Quaternion)->None:""" Construct from two quaternions - a real one and an infinitesimal one. """self.real_q=real_qself.inf_q=inf_q# -------------------------------------------------------------------------# Storage concept - see symforce.ops.storage_ops# -------------------------------------------------------------------------def__repr__(self)->str:return"<DQ real={}, inf={}>".format(repr(self.real_q),repr(self.inf_q))
# -------------------------------------------------------------------------# Group concept - see symforce.ops.group_ops# -------------------------------------------------------------------------
[docs]defsquared_norm(self)->T.Scalar:""" Squared norm when considering the dual quaternion as 8-tuple. """returnself.real_q.squared_norm()+self.inf_q.squared_norm()