Difference between revisions of "IC Python API:RLPy RQuaternion"

From Reallusion Wiki!
Jump to: navigation, search
m
m
Line 5: Line 5:
 
== Detailed Description ==
 
== Detailed Description ==
  
This class represents a quaternion in mathematics.  Quaternions represetn directions as a single rotation, just as rectangular coordinates represent positions as single vector.  RQuaternion also defines some constants that can be used directly:
+
This class represents a quaternion in mathematics.  Quaternions represetn directions as a single rotation, just as rectangular coordinates represent positions as single vector.  [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]also defines some constants that can be used directly:
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 22: Line 22:
 
=== __init__( self ) ===
 
=== __init__( self ) ===
  
The constructor. Initialize a new RQuaternion object without initialization.
+
The constructor. Initialize a new [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]object without initialization.
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
q = RLPy.RQuaternion()
 
q = RLPy.RQuaternion()
  
Line 32: Line 32:
 
=== __init__( self, vV ) ===
 
=== __init__( self, vV ) ===
  
The constructor. Initialize a new RQuaternion object from a 4D vector RVector4.
+
The constructor. Initialize a new [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]object from a 4D vector.
  
 
==== Parameters ====
 
==== Parameters ====
:'''vV''' [IN]  a 4D vector - RLPy.RVector4
+
:'''vV''' [IN]  a 4D vector - [[IC_Python_API:RLPy_RVector4|RVector4]]
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
v = RLPy.RVector4(1, 2, 3, 4)
 
v = RLPy.RVector4(1, 2, 3, 4)
 
q = RLPy.RQuaternion(v)
 
q = RLPy.RQuaternion(v)
Line 47: Line 47:
  
 
==== Parameters ====
 
==== Parameters ====
:'''qQ''' [IN]  a quaternion - RLPy.RQuaternion
+
:'''qQ''' [IN]  a quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
v = RLPy.RVector4(1, 2, 3, 4)
 
v = RLPy.RVector4(1, 2, 3, 4)
 
q = RLPy.RQuaternion(v)
 
q = RLPy.RQuaternion(v)
Line 59: Line 59:
 
=== __init__( self, kAxis, fAngle ) ===
 
=== __init__( self, kAxis, fAngle ) ===
  
The constructor. Initialize a new RQuaternion object with Axis-angle. The axis is specified by a 3D vector, and the angle is specified by a float value.
+
The constructor. Initialize a new [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]object with Axis-angle. The axis is specified by a 3D vector, and the angle is specified by a float value.
  
 
==== Parameters ====
 
==== Parameters ====
:'''kAxis''' [IN]  the rotation axis - RLPy.RVector3
+
:'''kAxis''' [IN]  the rotation axis - [[IC_Python_API:RLPy_RVector3|RVector3]]
 
:'''fAngle''' [IN] the rotation angle - float
 
:'''fAngle''' [IN] the rotation angle - float
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
v = RLPy.RVector3(0, 0, 1)
 
v = RLPy.RVector3(0, 0, 1)
 
q = RLPy.RQuaternion(v, math.pi/2)
 
q = RLPy.RQuaternion(v, math.pi/2)
Line 75: Line 75:
 
=== __init__( self, kRot ) ===
 
=== __init__( self, kRot ) ===
  
The constructor. Initialize a new RQuaternion object with a 3x3 rotation matrix.
+
The constructor. Initialize a new [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]object with a 3x3 rotation matrix.
  
 
==== Parameters ====
 
==== Parameters ====
:'''kRot''' [IN]  a 3x3 rotation matrix - RLPy.RMatrix3
+
:'''kRot''' [IN]  a 3x3 rotation matrix - [[IC_Python_API:RLPy_RMatrix3|RMatrix3]]
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
v = RLPy.RVector3(0, 0, 1)
 
v = RLPy.RVector3(0, 0, 1)
 
m = RLPy.RMatrix3(v, math.pi/2)
 
m = RLPy.RMatrix3(v, math.pi/2)
Line 95: Line 95:
 
The "equal to" operator.
 
The "equal to" operator.
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
q = RLPy.RQuaternion()
 
q = RLPy.RQuaternion()
 
p = q
 
p = q
Line 106: Line 106:
 
The "not equal to" operator.
 
The "not equal to" operator.
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(1, 2, 3, 4)
 
a = RLPy.RVector4(1, 2, 3, 4)
 
q = RLPy.RQuaternion(a)
 
q = RLPy.RQuaternion(a)
Line 119: Line 119:
 
The "less than" operator. Similar to string comparison: Returns '''True''' upon the first match that is less than and '''False''' if it is greater than.  If the current comparison is equal, continue onto the next element.  If all elements are equal then return '''False'''.
 
The "less than" operator. Similar to string comparison: Returns '''True''' upon the first match that is less than and '''False''' if it is greater than.  If the current comparison is equal, continue onto the next element.  If all elements are equal then return '''False'''.
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(0, 1, 5, 2)
 
a = RLPy.RVector4(0, 1, 5, 2)
 
b = RLPy.RVector4(0, 1, 5, 3)
 
b = RLPy.RVector4(0, 1, 5, 3)
Line 142: Line 142:
 
The "greater than" operator. Similar to string comparison: Returns '''True''' upon the first match that is greater than and '''False''' if it is less than.  If the current comparison is equal, continue onto the next element.  If all elements are equal then return '''False'''.
 
The "greater than" operator. Similar to string comparison: Returns '''True''' upon the first match that is greater than and '''False''' if it is less than.  If the current comparison is equal, continue onto the next element.  If all elements are equal then return '''False'''.
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(0, 1, 5, 2)
 
a = RLPy.RVector4(0, 1, 5, 2)
 
b = RLPy.RVector4(0, 1, 5, 3)
 
b = RLPy.RVector4(0, 1, 5, 3)
Line 165: Line 165:
 
The "less than or equal" operator. Similar to string comparison: Returns '''True''' upon the first match that is less than and '''False''' if it is greater than.  If the current comparison is equal, continue onto the next element.  If all elements are equal then return '''True'''.
 
The "less than or equal" operator. Similar to string comparison: Returns '''True''' upon the first match that is less than and '''False''' if it is greater than.  If the current comparison is equal, continue onto the next element.  If all elements are equal then return '''True'''.
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(0, 1, 5, 2)
 
a = RLPy.RVector4(0, 1, 5, 2)
 
b = RLPy.RVector4(0, 1, 5, 3)
 
b = RLPy.RVector4(0, 1, 5, 3)
Line 188: Line 188:
 
The "greater than or equal" operator. Similar to string comparison: Returns '''True''' upon the first match that is greater than and '''False''' if it is less than.  If the current comparison is equal, continue onto the next element.  If all elements are equal then return '''True'''.
 
The "greater than or equal" operator. Similar to string comparison: Returns '''True''' upon the first match that is greater than and '''False''' if it is less than.  If the current comparison is equal, continue onto the next element.  If all elements are equal then return '''True'''.
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(0, 1, 5, 2)
 
a = RLPy.RVector4(0, 1, 5, 2)
 
b = RLPy.RVector4(0, 1, 5, 3)
 
b = RLPy.RVector4(0, 1, 5, 3)
Line 211: Line 211:
 
The "addition" operator. Perform quaternion addition.
 
The "addition" operator. Perform quaternion addition.
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(0, 1, 2, 3)
 
a = RLPy.RVector4(0, 1, 2, 3)
 
b = RLPy.RVector4(1, 2, 3, 4)
 
b = RLPy.RVector4(1, 2, 3, 4)
Line 225: Line 225:
 
The "subtraction" operator. Perform quaternion subtraction.
 
The "subtraction" operator. Perform quaternion subtraction.
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(0, 1, 2, 3)
 
a = RLPy.RVector4(0, 1, 2, 3)
 
b = RLPy.RVector4(3, 2, 1, 0)
 
b = RLPy.RVector4(3, 2, 1, 0)
Line 239: Line 239:
 
The "multiplication" operator. Perform a scalar multiplication when the second operand is an integer or float. If the second operand is another quaternion, then the respective elements are multiplied.
 
The "multiplication" operator. Perform a scalar multiplication when the second operand is an integer or float. If the second operand is another quaternion, then the respective elements are multiplied.
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(1, 2, 3, 4)
 
a = RLPy.RVector4(1, 2, 3, 4)
 
p = RLPy.RQuaternion(a)
 
p = RLPy.RQuaternion(a)
Line 253: Line 253:
 
The "division" operator. Perform a scalar division with a int or float value which the second operand is limited to.
 
The "division" operator. Perform a scalar division with a int or float value which the second operand is limited to.
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(1, 2, 3, 4)
 
a = RLPy.RVector4(1, 2, 3, 4)
 
p = RLPy.RQuaternion(a)
 
p = RLPy.RQuaternion(a)
Line 265: Line 265:
 
The "unary minus" operator. Inverse the sign of each element.
 
The "unary minus" operator. Inverse the sign of each element.
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(1, 2, 3, 4)
 
a = RLPy.RVector4(1, 2, 3, 4)
 
p = RLPy.RQuaternion(a)
 
p = RLPy.RQuaternion(a)
Line 277: Line 277:
 
The "addition assignment" operator.
 
The "addition assignment" operator.
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(0, 1, 2, 3)
 
a = RLPy.RVector4(0, 1, 2, 3)
 
b = RLPy.RVector4(1, 2, 3, 4)
 
b = RLPy.RVector4(1, 2, 3, 4)
Line 291: Line 291:
 
The "subtraction assignment" operator.
 
The "subtraction assignment" operator.
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(0, 1, 4, 5)
 
a = RLPy.RVector4(0, 1, 4, 5)
 
b = RLPy.RVector4(1, 2, 3, 1)
 
b = RLPy.RVector4(1, 2, 3, 1)
Line 305: Line 305:
 
The "multiplication assignment" operator. For calculation method, refer to the '''*''' operator.
 
The "multiplication assignment" operator. For calculation method, refer to the '''*''' operator.
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(1, 2, 3, 4)
 
a = RLPy.RVector4(1, 2, 3, 4)
 
p = RLPy.RQuaternion(a)
 
p = RLPy.RQuaternion(a)
Line 317: Line 317:
 
The "division assignment" operator. For calculation method, refer to the '''/''' operator.
 
The "division assignment" operator. For calculation method, refer to the '''/''' operator.
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(1, 2, 3, 4)
 
a = RLPy.RVector4(1, 2, 3, 4)
 
p = RLPy.RQuaternion(a)
 
p = RLPy.RQuaternion(a)
Line 329: Line 329:
 
=== AlmostEqual( self, qQ ) ===
 
=== AlmostEqual( self, qQ ) ===
  
Determine the two quaternions are almost the same with tolerance: 0.00001.
+
Determine the two quaternions are almost the same within a tolerance of 0.00001.
  
 
==== Parameters ====
 
==== Parameters ====
:'''qQ''' [IN] The target quaternion to check for equivalence - RLPy.RQuaternion
+
:'''qQ''' [IN] The target quaternion to check for equivalence - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
  
 
==== Returns ====
 
==== Returns ====
:True if the two quaternions are almost the same - bool
+
:'''True''' if the two quaternions are almost the same, else '''False''' - bool
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(1, 2, 3, 4)
 
a = RLPy.RVector4(1, 2, 3, 4)
 
p = RLPy.RQuaternion(a)
 
p = RLPy.RQuaternion(a)
Line 357: Line 357:
  
 
==== Returns ====
 
==== Returns ====
:Returns the conjugated quaternion. The result is a quaternion whose x, y, and z values have been negated - RLPy.RQuaternion
+
:Returns the conjugated quaternion. The result is a quaternion whose x, y, and z values have been negated - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(1, 2, 3, 4)
 
a = RLPy.RVector4(1, 2, 3, 4)
 
p = RLPy.RQuaternion(a)
 
p = RLPy.RQuaternion(a)
Line 372: Line 372:
  
 
==== Parameters ====
 
==== Parameters ====
:'''qQ''' [IN] The quaternion to compute dot product - RLPy.RQuaternion
+
:'''qQ''' [IN] The quaternion to compute dot product - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
  
 
==== Returns ====
 
==== Returns ====
 
:Returns the value of the dot product - float
 
:Returns the value of the dot product - float
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(1, 2, 3, 4)
 
a = RLPy.RVector4(1, 2, 3, 4)
 
b = RLPy.RVector4(1, 2, 3, 0)
 
b = RLPy.RVector4(1, 2, 3, 0)
Line 392: Line 392:
  
 
==== Parameters ====
 
==== Parameters ====
:'''rkAxis''' [IN] axis vector - RLPy.RVector3
+
:'''rkAxis''' [IN] axis vector - [[IC_Python_API:RLPy_RVector3|RVector3]]
 
:'''fAngle''' [IN] angle in radians - float
 
:'''fAngle''' [IN] angle in radians - float
  
 
==== Returns ====
 
==== Returns ====
:Return a new quaternion from a axis angle - RLPy.RQuaternion
+
:Return a new quaternion from a axis angle - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
p = RLPy.RQuaternion()
 
p = RLPy.RQuaternion()
 
v = RLPy.RVector3(0, 0, 1)
 
v = RLPy.RVector3(0, 0, 1)
Line 411: Line 411:
  
 
==== Parameters ====
 
==== Parameters ====
:rkRot [IN] Rotation matrix - RLPy.RMatrix3
+
:'''rkRot''' [IN] Rotation matrix - [[IC_Python_API:RLPy_RMatrix3|RMatrix3]]
  
 
==== Returns ====
 
==== Returns ====
:Return a new quaternion from a rotation matrix - RLPy.RQuaternion
+
:Return a new quaternion from a rotation matrix - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
v = RLPy.RVector3(0, 0, 1)
 
v = RLPy.RVector3(0, 0, 1)
 
m = RLPy.RMatrix3(v, math.pi/2)
 
m = RLPy.RMatrix3(v, math.pi/2)
Line 430: Line 430:
  
 
==== Returns ====
 
==== Returns ====
:The inversed quaternion - RLPy.RQuaternion
+
:The inversed quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(1, 1, 1, 1)
 
a = RLPy.RVector4(1, 1, 1, 1)
 
p = RLPy.RQuaternion(a)
 
p = RLPy.RQuaternion(a)
Line 445: Line 445:
  
 
==== Parameters ====
 
==== Parameters ====
:'''qQ''' [IN] The quaternion to multiply - RLPy.RQuaternion
+
:'''qQ''' [IN] The quaternion to multiply - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
  
 
==== Returns ====
 
==== Returns ====
:Returns the multiplied quaternion - RLPy.RQuaternion
+
:Returns the multiplied quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(1, 2, 3, 4)
 
a = RLPy.RVector4(1, 2, 3, 4)
 
b = RLPy.RVector4(1, 2, 2, 1)
 
b = RLPy.RVector4(1, 2, 2, 1)
Line 464: Line 464:
  
 
==== Parameters ====
 
==== Parameters ====
:'''qQ''' [IN] The quaternion to multiply - RLPy.RQuaternion
+
:'''qQ''' [IN] The quaternion to multiply - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
  
 
==== Returns ====
 
==== Returns ====
:Returns the multiplied quaternion - RLPy.RQuaternion
+
:Returns the multiplied quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(1, 2, 3, 4)
 
a = RLPy.RVector4(1, 2, 3, 4)
 
b = RLPy.RVector4(1, 2, 2, 1)
 
b = RLPy.RVector4(1, 2, 2, 1)
Line 482: Line 482:
 
=== Normalize( self ) ===
 
=== Normalize( self ) ===
  
Normalizes this quaternion.
+
Normalize this quaternion, e.g. with a magnitude of 2.
  
 
==== Returns ====
 
==== Returns ====
:Returns the normalized quaternion - RLPy.RQuaternion
+
:The normalized quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(1, 1, 1, 1)
 
a = RLPy.RVector4(1, 1, 1, 1)
 
p = RLPy.RQuaternion(a)
 
p = RLPy.RQuaternion(a)
Line 498: Line 498:
 
=== Rotate180( self ) ===
 
=== Rotate180( self ) ===
  
Rotate 180 degree of this quaternion.
+
Rotate this quaternion by 180 degrees.
  
 
==== Returns ====
 
==== Returns ====
:Returns the rotated quaternion - RLPy.RQuaternion
+
:The rotated quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(1, 1, 1, 1)
 
a = RLPy.RVector4(1, 1, 1, 1)
 
p = RLPy.RQuaternion(a)
 
p = RLPy.RQuaternion(a)
Line 519: Line 519:
 
:'''tX''' [IN] the value of the x-axis - float
 
:'''tX''' [IN] the value of the x-axis - float
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(1, 2, 3, 4)
 
a = RLPy.RVector4(1, 2, 3, 4)
 
p = RLPy.RQuaternion(a)
 
p = RLPy.RQuaternion(a)
Line 534: Line 534:
 
:'''tY''' [IN] the value of the y-axis - float
 
:'''tY''' [IN] the value of the y-axis - float
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(1, 2, 3, 4)
 
a = RLPy.RVector4(1, 2, 3, 4)
 
p = RLPy.RQuaternion(a)
 
p = RLPy.RQuaternion(a)
Line 549: Line 549:
 
:'''tZ''' [IN] the value of the z-axis - float
 
:'''tZ''' [IN] the value of the z-axis - float
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(1, 2, 3, 4)
 
a = RLPy.RVector4(1, 2, 3, 4)
 
p = RLPy.RQuaternion(a)
 
p = RLPy.RQuaternion(a)
Line 564: Line 564:
 
:'''tW''' [IN] the value of the w-axis - float
 
:'''tW''' [IN] the value of the w-axis - float
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector4(1, 2, 3, 4)
 
a = RLPy.RVector4(1, 2, 3, 4)
 
p = RLPy.RQuaternion(a)
 
p = RLPy.RQuaternion(a)

Revision as of 01:41, 7 April 2020

Main article: Modules. Last modified: 04/7/2020

Detailed Description

This class represents a quaternion in mathematics. Quaternions represetn directions as a single rotation, just as rectangular coordinates represent positions as single vector. RQuaternionalso defines some constants that can be used directly:

Constant Description
RQuaternion.IDENTITY 4D zero vector: (0, 0, 0, 1)
RQuaternion.ZERO 4D x unit vector: (0, 0, 0, 0)init

Constructor & Destructor

__init__( self )

The constructor. Initialize a new RQuaternionobject without initialization.

q = RLPy.RQuaternion()

print(str(q.x) + ', ' + str(q.y) + ', ' + str(q.z) + ', ' + str(q.w)) # random values

__init__( self, vV )

The constructor. Initialize a new RQuaternionobject from a 4D vector.

Parameters

vV [IN] a 4D vector - RVector4
v = RLPy.RVector4(1, 2, 3, 4)
q = RLPy.RQuaternion(v)

print(str(q.x) + ', ' + str(q.y) + ', ' + str(q.z) + ', ' + str(q.w)) # 1.0, 2.0, 3.0, 4.0

__init__( self, qQ )

Parameters

qQ [IN] a quaternion - RQuaternion
v = RLPy.RVector4(1, 2, 3, 4)
q = RLPy.RQuaternion(v)
p = RLPy.RQuaternion(q)

print(str(p.x) + ', ' + str(p.y) + ', ' + str(p.z) + ', ' + str(p.w)) # 1.0, 2.0, 3.0, 4.0

__init__( self, kAxis, fAngle )

The constructor. Initialize a new RQuaternionobject with Axis-angle. The axis is specified by a 3D vector, and the angle is specified by a float value.

Parameters

kAxis [IN] the rotation axis - RVector3
fAngle [IN] the rotation angle - float
v = RLPy.RVector3(0, 0, 1)
q = RLPy.RQuaternion(v, math.pi/2)

print(str(q.x) + ', ' + str(q.y) + ', ' + str(q.z) + ', ' + str(q.w))
    # 0.0, 0.0, 0.7071067094802856, 0.7071067690849304

__init__( self, kRot )

The constructor. Initialize a new RQuaternionobject with a 3x3 rotation matrix.

Parameters

kRot [IN] a 3x3 rotation matrix - RMatrix3
v = RLPy.RVector3(0, 0, 1)
m = RLPy.RMatrix3(v, math.pi/2)
q = RLPy.RQuaternion(m)

print(str(q.x) + ', ' + str(q.y) + ', ' + str(q.z) + ', ' + str(q.w))
    # 0.0, 0.0, 0.7071067690849304, 0.7071067690849304

Operator

=

The "equal to" operator.

q = RLPy.RQuaternion()
p = q
if q == p:                         # True
    print("equal")

!=

The "not equal to" operator.

a = RLPy.RVector4(1, 2, 3, 4)
q = RLPy.RQuaternion(a)
b = RLPy.RVector4(2, 2, 3, 4)
p = RLPy.RQuaternion(b)
if a != b:                         #True
    print("not equal")

<

The "less than" operator. Similar to string comparison: Returns True upon the first match that is less than and False if it is greater than. If the current comparison is equal, continue onto the next element. If all elements are equal then return False.

a = RLPy.RVector4(0, 1, 5, 2)
b = RLPy.RVector4(0, 1, 5, 3)
c = RLPy.RVector4(1, 0, 1, 0)
d = RLPy.RVector4(0, 1, 5, 2)

p = RLPy.RQuaternion(a)
q = RLPy.RQuaternion(b)
r = RLPy.RQuaternion(c)
s = RLPy.RQuaternion(d)

if p< q:                       #True
    print('p< q')
if q< r:                       #True
    print('q< r')
if p< s:                       #False
    print('p< s')

>

The "greater than" operator. Similar to string comparison: Returns True upon the first match that is greater than and False if it is less than. If the current comparison is equal, continue onto the next element. If all elements are equal then return False.

a = RLPy.RVector4(0, 1, 5, 2)
b = RLPy.RVector4(0, 1, 5, 3)
c = RLPy.RVector4(1, 0, 1, 0)
d = RLPy.RVector4(0, 1, 5, 2)

p = RLPy.RQuaternion(a)
q = RLPy.RQuaternion(b)
r = RLPy.RQuaternion(c)
s = RLPy.RQuaternion(d)

if q >p:                       #True
    print('q >p')
if r >q:                       #True
    print('r >q')
if p >s:                       #False
    print('p >s')

<=

The "less than or equal" operator. Similar to string comparison: Returns True upon the first match that is less than and False if it is greater than. If the current comparison is equal, continue onto the next element. If all elements are equal then return True.

a = RLPy.RVector4(0, 1, 5, 2)
b = RLPy.RVector4(0, 1, 5, 3)
c = RLPy.RVector4(1, 0, 1, 0)
d = RLPy.RVector4(0, 1, 5, 2)

p = RLPy.RQuaternion(a)
q = RLPy.RQuaternion(b)
r = RLPy.RQuaternion(c)
s = RLPy.RQuaternion(d)

if p<= q:                       #True
    print('p<= q')
if q<= r:                       #True
    print('q<= r')
if p<= s:                       #True
    print('p<= s')

>=

The "greater than or equal" operator. Similar to string comparison: Returns True upon the first match that is greater than and False if it is less than. If the current comparison is equal, continue onto the next element. If all elements are equal then return True.

a = RLPy.RVector4(0, 1, 5, 2)
b = RLPy.RVector4(0, 1, 5, 3)
c = RLPy.RVector4(1, 0, 1, 0)
d = RLPy.RVector4(0, 1, 5, 2)

p = RLPy.RQuaternion(a)
q = RLPy.RQuaternion(b)
r = RLPy.RQuaternion(c)
s = RLPy.RQuaternion(d)

if q >= p:                       #True
    print('q >= p')
if r >= q:                       #True
    print('r >= q')
if p >= s:                       #True
    print('p >= s')

+

The "addition" operator. Perform quaternion addition.

a = RLPy.RVector4(0, 1, 2, 3)
b = RLPy.RVector4(1, 2, 3, 4)
p = RLPy.RQuaternion(a)
q = RLPy.RQuaternion(b)
r = p + q

print(str(r.x) + ', ' + str(r.y) + ', ' + str(r.z) + ', ' + str(r.w))  # 1.0, 3.0, 5.0, 7.0

-

The "subtraction" operator. Perform quaternion subtraction.

a = RLPy.RVector4(0, 1, 2, 3)
b = RLPy.RVector4(3, 2, 1, 0)
p = RLPy.RQuaternion(a)
q = RLPy.RQuaternion(b)
r = q - p

print(str(r.x) + ', ' + str(r.y) + ', ' + str(r.z) + ', ' + str(r.w)) # 3.0, 1.0, -1.0, -3.0

*

The "multiplication" operator. Perform a scalar multiplication when the second operand is an integer or float. If the second operand is another quaternion, then the respective elements are multiplied.

a = RLPy.RVector4(1, 2, 3, 4)
p = RLPy.RQuaternion(a)
q = p * 2
r = p * p

print(str(q.x) + ', ' + str(q.y) + ', ' + str(q.z) + ', ' + str(q.w)) # 2.0, 4.0, 6.0, 8.0
print(str(r.x) + ', ' + str(r.y) + ', ' + str(r.z) + ', ' + str(r.w)) # 1.0, 4.0, 9.0, 16.0

/

The "division" operator. Perform a scalar division with a int or float value which the second operand is limited to.

a = RLPy.RVector4(1, 2, 3, 4)
p = RLPy.RQuaternion(a)
q = p / 2

print(str(q.x) + ', ' + str(q.y) + ', ' + str(q.z) + ', ' + str(q.w)) # 0.5, 1.0, 1.5, 2.0

-

The "unary minus" operator. Inverse the sign of each element.

a = RLPy.RVector4(1, 2, 3, 4)
p = RLPy.RQuaternion(a)
q = -p

print(str(q.x) + ', ' + str(q.y) + ', ' + str(q.z) + ', ' + str(q.w)) # -1.0, -2.0, -3.0, -4.0

+ =

The "addition assignment" operator.

a = RLPy.RVector4(0, 1, 2, 3)
b = RLPy.RVector4(1, 2, 3, 4)
p = RLPy.RQuaternion(a)
q = RLPy.RQuaternion(b)
p += q

print(str(p.x) + ', ' + str(p.y) + ', ' + str(p.z) + ', ' + str(p.w)) # 1.0, 3.0, 5.0, 7.0

- =

The "subtraction assignment" operator.

a = RLPy.RVector4(0, 1, 4, 5)
b = RLPy.RVector4(1, 2, 3, 1)
p = RLPy.RQuaternion(a)
q = RLPy.RQuaternion(b)
p -= q

print(str(p.x) + ', ' + str(p.y) + ', ' + str(p.z) + ', ' + str(p.w)) # -1.0, -1.0, 1.0, 4.0

*=

The "multiplication assignment" operator. For calculation method, refer to the * operator.

a = RLPy.RVector4(1, 2, 3, 4)
p = RLPy.RQuaternion(a)
p *= 2

print(str(p.x) + ', ' + str(p.y) + ', ' + str(p.z) + ', ' + str(p.w)) # 2.0, 4.0, 6.0, 8.0

/=

The "division assignment" operator. For calculation method, refer to the / operator.

a = RLPy.RVector4(1, 2, 3, 4)
p = RLPy.RQuaternion(a)
p /= 2

print(str(p.x) + ', ' + str(p.y) + ', ' + str(p.z) + ', ' + str(p.w)) # 0.5, 1.0, 1.5, 2.0

Member Functions

AlmostEqual( self, qQ )

Determine the two quaternions are almost the same within a tolerance of 0.00001.

Parameters

qQ [IN] The target quaternion to check for equivalence - RQuaternion

Returns

True if the two quaternions are almost the same, else False - bool
a = RLPy.RVector4(1, 2, 3, 4)
p = RLPy.RQuaternion(a)
q = RLPy.RQuaternion(a)
r = RLPy.RQuaternion(a)

q.w = 4.000000001
r.w = 4.00001

if p.AlmostEqual(q):               #True
    print("p ≈ q")
if q.AlmostEqual(r):               #False
    print("p ≈ r")

Conjugate( self )

Conjugate this quaternion.

Returns

Returns the conjugated quaternion. The result is a quaternion whose x, y, and z values have been negated - RQuaternion
a = RLPy.RVector4(1, 2, 3, 4)
p = RLPy.RQuaternion(a)
q = p.Conjugate()

print(str(q.x) + ', ' + str(q.y) + ', ' + str(q.z) + ', ' + str(q.w)) # -1.0, -2.0, -3.0, 4.0

Dot( self, qQ )

Calculate dot product of the two quaternions.

Parameters

qQ [IN] The quaternion to compute dot product - RQuaternion

Returns

Returns the value of the dot product - float
a = RLPy.RVector4(1, 2, 3, 4)
b = RLPy.RVector4(1, 2, 3, 0)
p = RLPy.RQuaternion(a)
q = RLPy.RQuaternion(b)
f = p.Dot(q)

print(f)     # 14.0

FromAxisAngle( self, rkAxis, fAngle )

Quaternion from axis angle.

Parameters

rkAxis [IN] axis vector - RVector3
fAngle [IN] angle in radians - float

Returns

Return a new quaternion from a axis angle - RQuaternion
p = RLPy.RQuaternion()
v = RLPy.RVector3(0, 0, 1)
p.FromAxisAngle(v, math.pi/2)

print(str(p.x) + ', ' + str(p.y) + ', ' + str(p.z) + ', ' + str(p.w)) # 0.0, 0.0, 0.7071067094802856, 0.7071067690849304

FromRotationMatrix( self, rkRot )

Quaternion from a rotation matrix.

Parameters

rkRot [IN] Rotation matrix - RMatrix3

Returns

Return a new quaternion from a rotation matrix - RQuaternion
v = RLPy.RVector3(0, 0, 1)
m = RLPy.RMatrix3(v, math.pi/2)
p = RLPy.RQuaternion()
p.FromRotationMatrix(m)

print(str(p.x) + ', ' + str(p.y) + ', ' + str(p.z) + ', ' + str(p.w)) # 0.0, 0.0, 0.7071067690849304, 0.7071067690849304

Inverse( self, rkRot )

Obtain the inverse of this quaternion.

Returns

The inversed quaternion - RQuaternion
a = RLPy.RVector4(1, 1, 1, 1)
p = RLPy.RQuaternion(a)
q = p.Inverse()

print(str(q.x) + ', ' + str(q.y) + ', ' + str(q.z) + ', ' + str(q.w)) # -0.25, -0.25, -0.25, 0.25

Multiply( self, qQ )

Multiply by another quaternion.

Parameters

qQ [IN] The quaternion to multiply - RQuaternion

Returns

Returns the multiplied quaternion - RQuaternion
a = RLPy.RVector4(1, 2, 3, 4)
b = RLPy.RVector4(1, 2, 2, 1)

p = RLPy.RQuaternion(a)
q = RLPy.RQuaternion(b)
r = p.Multiply(q)

print(str(r.x) + ', ' + str(r.y) + ', ' + str(r.z) + ', ' + str(r.w)) # 3.0, 11.0, 11.0, -7.0

MultiplyEqual( self, qQ )

Parameters

qQ [IN] The quaternion to multiply - RQuaternion

Returns

Returns the multiplied quaternion - RQuaternion
a = RLPy.RVector4(1, 2, 3, 4)
b = RLPy.RVector4(1, 2, 2, 1)

p = RLPy.RQuaternion(a)
q = RLPy.RQuaternion(b)
r = p.MultiplyEqual(q)

print(str(r.x) + ', ' + str(r.y) + ', ' + str(r.z) + ', ' + str(r.w)) # 3.0, 11.0, 11.0, -7.0

Normalize( self )

Normalize this quaternion, e.g. with a magnitude of 2.

Returns

The normalized quaternion - RQuaternion
a = RLPy.RVector4(1, 1, 1, 1)
p = RLPy.RQuaternion(a)
q = p.Normalize()

print(str(q.x) + ', ' + str(q.y) + ', ' + str(q.z) + ', ' + str(q.w))
    # 0.4999999701976776, 0.4999999701976776, 0.4999999701976776, 0.4999999701976776

Rotate180( self )

Rotate this quaternion by 180 degrees.

Returns

The rotated quaternion - RQuaternion
a = RLPy.RVector4(1, 1, 1, 1)
p = RLPy.RQuaternion(a)
q = p.Normalize()

print(str(q.x) + ', ' + str(q.y) + ', ' + str(q.z) + ', ' + str(q.w))
   #0.4999999701976776, 0.4999999701976776, 0.4999999701976776, 0.4999999701976776

SetX( self, tX )

Set the value of the x-axis.

Parameters

tX [IN] the value of the x-axis - float
a = RLPy.RVector4(1, 2, 3, 4)
p = RLPy.RQuaternion(a)
p.SetX(9)

print(str(p.x) + ', ' + str(p.y) + ', ' + str(p.z) + ', ' + str(p.w)) # 9.0, 2.0, 3.0, 4.0

SetY( self, tY )

Set the value of the y-axis.

Parameters

tY [IN] the value of the y-axis - float
a = RLPy.RVector4(1, 2, 3, 4)
p = RLPy.RQuaternion(a)
p.SetY(9)
print(str(p.x) + ', ' + str(p.y) + ', ' + str(p.z) + ', ' + str(p.w))
    #1.0, 9.0, 3.0, 4.0

SetZ( self, tZ )

Set the value of the z-axis.

Parameters

tZ [IN] the value of the z-axis - float
a = RLPy.RVector4(1, 2, 3, 4)
p = RLPy.RQuaternion(a)
p.SetZ(9)
print(str(p.x) + ', ' + str(p.y) + ', ' + str(p.z) + ', ' + str(p.w))
    #1.0, 2.0, 9.0, 4.0

SetW( self, tW )

Set the value of the w-axis.

Parameters

tW [IN] the value of the w-axis - float
a = RLPy.RVector4(1, 2, 3, 4)
p = RLPy.RQuaternion(a)
p.SetW(9)
print(str(p.x) + ', ' + str(p.y) + ', ' + str(p.z) + ', ' + str(p.w))
    #1.0, 2.0, 3.0, 9.0