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

From Reallusion Wiki!
Jump to: navigation, search
(Created page with "{{TOC}} {{Parent|IC_Python_API:RL_Python_Modules|Modules}} ==Detailed Description== This class represent the quaternion in math. Quaternions represent orientations as a single...")
 
m
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{TOC}}
 
{{TOC}}
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
==Detailed Description==
+
{{last_modified}}
This class represent the quaternion in math.
+
 
Quaternions represent orientations as a single rotation, just as
+
== Detailed Description ==
rectangular co- ordinates represent position as a single vector.
+
 
==Operators==
+
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:
This class supports the following operators:
+
 
 
{| class="wikitable"
 
{| class="wikitable"
!Member
+
!Constant
!Operation
+
!Syntax
+
 
!Description
 
!Description
!Example
 
|-
 
! scope="row"|__add__
 
|Addition
 
|a + b
 
|Adds values on either side of the operator.
 
|a + b = 30
 
|-
 
! scope="row"|__sub__
 
|Subtraction
 
|a - b
 
|Subtracts right hand operand from left hand operand.
 
|a – b = -10
 
 
|-
 
|-
! scope="row"|__mul__
+
|RQuaternion.IDENTITY
|Multiplication
+
|4D zero vector: (0, 0, 0, 1)
|a * b
+
|Multiplies values on either side of the operator.
+
|a * b = 200
+
 
|-
 
|-
! scope="row"|__truediv__
+
|RQuaternion.ZERO
|Division
+
|4D x unit vector: (0, 0, 0, 0) initialization value
|a / b
+
|Divides left hand operand by right hand operand.
+
|b / a = 2
+
|-
+
! scope="row"|__neg__
+
|Negation
+
| -a
+
|Return the value negated.
+
| a = -b
+
|-
+
! scope="row"|__eq__
+
|Equality
+
|a == b
+
|If the values of two operands are equal, then the condition becomes true.
+
|(a == b) is not true.
+
|-
+
! scope="row"|__ne__
+
|Difference
+
|a != b
+
|If values of two operands are not equal, then condition becomes true.
+
|(a != b) is true.
+
|-
+
! scope="row"|__gt__
+
|Greater Than
+
|a > b
+
|If the value of left operand is greater than the value of right operand, then condition becomes true.
+
|(a > b) is not true.
+
|-
+
! scope="row"|__lt__
+
|Less Than
+
|a < b
+
|If the value of left operand is less than the value of right operand, then condition becomes true.
+
|(a < b) is true.
+
|-
+
! scope="row"|__ge__
+
|Greater Than or Equal
+
|a >= b
+
|If the value of left operand is greater than or equal to the value of right operand, then condition becomes true.
+
|(a >= b) is not true.
+
|-
+
! scope="row"|__le__
+
|Less or Equal
+
|a <= b
+
|If the value of left operand is less than or equal to the value of right operand, then condition becomes true.
+
|(a <= b) is true.
+
|-
+
! scope="row"|__iadd__
+
|Addition (Inplace)
+
|a += b
+
|It adds right operand to the left operand and assign the result to left operand.
+
|c += a is equivalent to c = c + a
+
|-
+
! scope="row"|__isub__
+
|Subtraction (Inplace)
+
|a -= b
+
|It subtracts right operand from the left operand and assign the result to left operand.
+
|c -= a is equivalent to c = c - a
+
|-
+
! scope="row"|__imul__
+
|Multiply (Inplace)
+
|a *= b
+
|It multiplies right operand with the left operand and assign the result to left operand.
+
|c *= a is equivalent to c = c * a
+
|-
+
! scope="row"|__itruediv__
+
|Divide (Inplace)
+
|a /= b
+
|It divides left operand with the right operand and assign the result to left operand.
+
|c /= a is equivalent to c = c / ac /= a is equivalent to c = c / a
+
 
|}
 
|}
==Member Functions==
+
 
===AlmostEquel===
+
== Constructor & Destructor ==
<syntaxhighlight lang="Python">
+
 
RLPy.RQuaternion.AlmostEquel ( self, qQ )
+
=== __init__ ( self ) ===
 +
 
 +
The constructor. Initialize a new [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] object without initialization.
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
q = RLPy.RQuaternion()
 +
 
 +
print(str(q.x) + ', ' + str(q.y) + ', ' + str(q.z) + ', ' + str(q.w)) # random values
 
</syntaxhighlight>
 
</syntaxhighlight>
Equality test.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''qQ''' [IN] The quaternion - RLPy.RQuaternion
+
=== __init__ ( self, vV ) ===
</div>
+
 
====Returns====
+
The constructor. Initialize a new [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] object from a 4D vector.
<div style="margin-left: 2em;">True if each of the elements of the quaternion is almost equal to the corresponding element in the second matrix - bool
+
 
</div>
+
==== Parameters ====
-----
+
:'''vV''' [IN]  a 4D vector - [[IC_Python_API:RLPy_RVector4|RVector4]]
===Conjugate===
+
 
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python" line='line'>
RLPy.RQuaternion.Conjugate ( self )
+
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
 
</syntaxhighlight>
 
</syntaxhighlight>
Conjugate this quaternion.
+
 
====Returns====
+
=== __init__ ( self, qQ ) ===
<div style="margin-left: 2em;">The conjugated quaternion. The result is a quaternion whose x, y, and z values have been negated - RLPy.RQuaternion
+
 
</div>
+
==== Parameters ====
-----
+
:'''qQ''' [IN]  a quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
===Dot===
+
 
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python" line='line'>
RLPy.RQuaternion.Dot ( self, qQ )
+
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
 
</syntaxhighlight>
 
</syntaxhighlight>
Calculate dot production of the two quaternion.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''qQ''' [IN] The quaternion - RLPy.RQuaternion
+
=== __init__ ( self, kAxis, fAngle ) ===
</div>
+
 
====Returns====
+
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.
<div style="margin-left: 2em;">The value of the dot production - float
+
 
</div>
+
==== Parameters ====
-----
+
:'''kAxis''' [IN]  the rotation axis - [[IC_Python_API:RLPy_RVector3|RVector3]]
===FromAxisAngle===
+
:'''fAngle''' [IN] the rotation angle - float
<syntaxhighlight lang="Python">
+
 
RLPy.RQuaternion.FromAxisAngle ( self, rkAxis, fAngle )
+
<syntaxhighlight lang="python" line='line'>
 +
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
 
</syntaxhighlight>
 
</syntaxhighlight>
Quaternion from a axis angle.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''rkAxis''' [IN] axis vector - RLPy.RVector3
+
=== __init__ ( self, kRot ) ===
 +
 
 +
The constructor. Initialize a new [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] object with a 3x3 rotation matrix.
 +
 
 +
==== Parameters ====
 +
:'''kRot''' [IN] a 3x3 rotation matrix - [[IC_Python_API:RLPy_RMatrix3|RMatrix3]]
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
v = RLPy.RVector3(0, 0, 1)
 +
m = RLPy.RMatrix3(v, math.pi/2)
 +
q = RLPy.RQuaternion(m)
  
'''fAngle''' [IN] angle in radians - float
+
print(str(q.x) + ', ' + str(q.y) + ', ' + str(q.z) + ', ' + str(q.w))
</div>
+
    # 0.0, 0.0, 0.7071067690849304, 0.7071067690849304
====Returns====
+
<div style="margin-left: 2em;">Return a new quaternion from a axis angle - RLPy.RQuaternion
+
</div>
+
-----
+
===FromRotationMatrix===
+
<syntaxhighlight lang="Python">
+
RLPy.RQuaternion.FromRotationMatrix ( self, rkRot )
+
 
</syntaxhighlight>
 
</syntaxhighlight>
Quaternion from a rotation matrix.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''rkRot''' [IN] Rotation matrix - RLPy.RMatrix3
+
== Operators ==
</div>
+
 
====Returns====
+
=== = ===
<div style="margin-left: 2em;">Return a new quaternion from a rotation matrix - RLPy.RQuaternion
+
 
</div>
+
The "equal to" operator.
-----
+
 
===Inverse===
+
<syntaxhighlight lang="python" line='line'>
<syntaxhighlight lang="Python">
+
q = RLPy.RQuaternion()
RLPy.RQuaternion.Inverse ( self )
+
p = q
 +
if q == p:                        # True
 +
    print("equal")
 
</syntaxhighlight>
 
</syntaxhighlight>
Inverse this quaternion.
+
 
====Returns====
+
=== != ===
<div style="margin-left: 2em;">The inversed quaternion - RLPy.RQuaternion
+
 
</div>
+
The "not equal to" operator.
-----
+
 
===Multiply===
+
See Also: [[#==|==]]
<syntaxhighlight lang="Python">
+
 
RLPy.RQuaternion.Multiply ( self, qQ )
+
<syntaxhighlight lang="python" line='line'>
 +
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")
 
</syntaxhighlight>
 
</syntaxhighlight>
Multiply quaternion.
+
 
====Returns====
+
=== < ===
<div style="margin-left: 2em;">The multiplied quaternion - RLPy.RQuaternion
+
 
</div>
+
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'''.
-----
+
 
===MultiplyEqual===
+
See Also: [[#<=|<=]]
<syntaxhighlight lang="Python">
+
 
RLPy.RQuaternion.MultiplyEqual ( self, qQ )
+
<syntaxhighlight lang="python" line='line'>
 +
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')
 
</syntaxhighlight>
 
</syntaxhighlight>
Multiply quaternion.
+
 
====Returns====
+
=== > ===
<div style="margin-left: 2em;">The multiplied quaternion - RLPy.RQuaternion
+
 
</div>
+
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'''.
-----
+
 
===Normalize===
+
See Also: [[#>=|>=]]
<syntaxhighlight lang="Python">
+
 
RLPy.RQuaternion.Normalize ( self )
+
<syntaxhighlight lang="python" line='line'>
 +
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')
 
</syntaxhighlight>
 
</syntaxhighlight>
Normalizes this quaternion.
+
 
====Returns====
+
=== <= ===
<div style="margin-left: 2em;">The normalized quaternion - RLPy.RQuaternion
+
 
</div>
+
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'''.
-----
+
 
===Rotate180===
+
See Also: [[#<|<]]
<syntaxhighlight lang="Python">
+
 
RLPy.RQuaternion.Rotate180 ( self )
+
<syntaxhighlight lang="python" line='line'>
 +
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')
 
</syntaxhighlight>
 
</syntaxhighlight>
Rotate 180 degree of this quaternion.
+
 
====Returns====
+
=== >= ===
<div style="margin-left: 2em;">The rotated quaternion - RLPy.RQuaternion
+
 
</div>
+
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'''.
-----
+
 
===SetW===
+
See Also: [[#>|>]]
<syntaxhighlight lang="Python">
+
 
RLPy.RQuaternion.SetW ( self, tW )
+
<syntaxhighlight lang="python" line='line'>
 +
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')
 
</syntaxhighlight>
 
</syntaxhighlight>
Set the w value of the quaternion.
+
 
====Returns====
+
=== + ===
<div style="margin-left: 2em;">The value of the w - RLPy.void
+
 
</div>
+
The "addition" operator. Perform quaternion addition.
-----
+
 
===SetX===
+
See Also: [[#+=|+=]]
<syntaxhighlight lang="Python">
+
 
RLPy.RQuaternion.SetX ( self, tX )
+
<syntaxhighlight lang="python" line='line'>
 +
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
 
</syntaxhighlight>
 
</syntaxhighlight>
Set the x value of the quaternion.
+
 
====Returns====
+
=== - ===
<div style="margin-left: 2em;">The value of the x - RLPy.void
+
 
</div>
+
The "subtraction" operator. Perform quaternion subtraction.
-----
+
 
===SetY===
+
See Also: [[#-=|-=]]
<syntaxhighlight lang="Python">
+
 
RLPy.RQuaternion.SetY ( self, tY )
+
<syntaxhighlight lang="python" line='line'>
 +
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
 
</syntaxhighlight>
 
</syntaxhighlight>
Set the y value of the quaternion.
+
 
====Returns====
+
=== * ===
<div style="margin-left: 2em;">The value of the y - RLPy.void
+
 
</div>
+
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.
-----
+
 
===SetZ===
+
See Also: [[#*=|*=]]
<syntaxhighlight lang="Python">
+
 
RLPy.RQuaternion.SetZ ( self, tZ )
+
<syntaxhighlight lang="python" line='line'>
 +
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
 
</syntaxhighlight>
 
</syntaxhighlight>
Set the z value of the quaternion.
+
 
====Returns====
+
=== / ===
<div style="margin-left: 2em;">The value of the z - RLPy.void
+
 
</div>
+
The "division" operator. Perform a scalar division with a int or float value which the second operand is limited to.
-----
+
 
===ToAxisAngle===
+
See Also: [[#/=|/=]]
<syntaxhighlight lang="Python">
+
 
RLPy.RQuaternion.ToAxisAngle ( self, rkAxis, rfAngle )
+
<syntaxhighlight lang="python" line='line'>
 +
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
 
</syntaxhighlight>
 
</syntaxhighlight>
Convert quaternion to axis angle.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''rkAxis''' [OUT] Returns axis vector - RLPy.RVector3
+
=== - ===
  
'''fAngle''' [OUT] Returns angle in radians.
+
The "unary minus" operator. Inverse the sign of each element.
</div>
+
 
-----
+
<syntaxhighlight lang="python" line='line'>
===ToRotationMatrix===
+
a = RLPy.RVector4(1, 2, 3, 4)
<syntaxhighlight lang="Python">
+
p = RLPy.RQuaternion(a)
RLPy.RQuaternion.ToRotationMatrix ( self )
+
q = -p
 +
 
 +
print(str(q.x) + ', ' + str(q.y) + ', ' + str(q.z) + ', ' + str(q.w)) # -1.0, -2.0, -3.0, -4.0
 
</syntaxhighlight>
 
</syntaxhighlight>
Convert quaternion to a rotation matrix.
+
 
====Returns====
+
=== + ====
<div style="margin-left: 2em;">Return a new 3x3 matrix from a quaternion - RLPy.RMatrix3
+
 
</div>
+
The "addition assignment" operator.
-----
+
 
===W===
+
<syntaxhighlight lang="python" line='line'>
<syntaxhighlight lang="Python">
+
a = RLPy.RVector4(0, 1, 2, 3)
RLPy.RQuaternion.W ( self, args )
+
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
 
</syntaxhighlight>
 
</syntaxhighlight>
Get the w value of the quaternion.
+
 
====Returns====
+
=== - ====
<div style="margin-left: 2em;">The value of the w - float
+
 
</div>
+
The "subtraction assignment" operator.
-----
+
 
===X===
+
<syntaxhighlight lang="python" line='line'>
<syntaxhighlight lang="Python">
+
a = RLPy.RVector4(0, 1, 4, 5)
RLPy.RQuaternion.X ( self, args )
+
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
 
</syntaxhighlight>
 
</syntaxhighlight>
Get the x value of the quaternion.
+
 
====Returns====
+
=== *= ===
<div style="margin-left: 2em;">The value of the x - float
+
 
</div>
+
The "multiplication assignment" operator. For calculation method, refer to the '''*''' operator.
-----
+
 
===Y===
+
See Also: [[#*|*]]
<syntaxhighlight lang="Python">
+
 
RLPy.RQuaternion.Y ( self, args )
+
<syntaxhighlight lang="python" line='line'>
 +
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
 
</syntaxhighlight>
 
</syntaxhighlight>
Get the y value of the quaternion.
+
 
====Returns====
+
=== /= ===
<div style="margin-left: 2em;">The value of the y - float
+
 
</div>
+
The "division assignment" operator. For calculation method, refer to the '''/''' operator.
-----
+
 
===Z===
+
See Also: [[#/|/]]
<syntaxhighlight lang="Python">
+
 
RLPy.RQuaternion.Z ( self, args )
+
<syntaxhighlight lang="python" line='line'>
 +
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
 +
</syntaxhighlight>
 +
 
 +
== Member Functions ==
 +
 
 +
=== AlmostEqual ( self, qQ ) ===
 +
 
 +
Determine if two quaternions are almost the same within a tolerance of 0.00001.
 +
 
 +
==== Parameters ====
 +
:'''qQ''' [IN] The target quaternion to check for equivalence - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
 +
 
 +
==== Returns ====
 +
:'''True''' if the two quaternions are almost the same, else '''False''' - bool
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
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")
 +
</syntaxhighlight>
 +
 
 +
=== Conjugate ( self ) ===
 +
 
 +
Get the conjugate of this quaternion. The result is a quaternion whose x, y, and z values have been negated.
 +
 
 +
==== Returns ====
 +
:The conjugated quaternion. - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
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
 +
</syntaxhighlight>
 +
 
 +
=== Dot ( self, qQ ) ===
 +
 
 +
Calculate the dot product of two quaternions.
 +
 
 +
==== Parameters ====
 +
:'''qQ''' [IN] The quaternion to compute dot product - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
 +
 
 +
==== Returns ====
 +
:Value of the dot product - float
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
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
 +
</syntaxhighlight>
 +
 
 +
=== FromAxisAngle ( self, rkAxis, fAngle ) ===
 +
 
 +
Create a quaternion from axis angle.
 +
 
 +
==== Parameters ====
 +
:'''rkAxis''' [IN] axis vector - [[IC_Python_API:RLPy_RVector3|RVector3]]
 +
:'''fAngle''' [IN] angle in radians - float
 +
 
 +
==== Returns ====
 +
:Return a new quaternion from a axis angle - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
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
 +
</syntaxhighlight>
 +
 
 +
=== FromRotationMatrix ( self, rkRot ) ===
 +
 
 +
Create a quaternion from a rotation matrix.
 +
 
 +
==== Parameters ====
 +
:'''rkRot''' [IN] Rotation matrix - [[IC_Python_API:RLPy_RMatrix3|RMatrix3]]
 +
 
 +
==== Returns ====
 +
:Return a new quaternion from a rotation matrix - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
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
 +
</syntaxhighlight>
 +
 
 +
=== Inverse ( self, rkRot ) ===
 +
 
 +
Get the inverse of this quaternion.
 +
 
 +
==== Returns ====
 +
:The inversed quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
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
 +
</syntaxhighlight>
 +
 
 +
=== Multiply ( self, qQ ) ===
 +
 
 +
Multiply this quaternion by another quaternion.
 +
 
 +
==== Parameters ====
 +
:'''qQ''' [IN] The quaternion to multiply - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
 +
 
 +
==== Returns ====
 +
:Returns the multiplied quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
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
 +
</syntaxhighlight>
 +
 
 +
=== MultiplyEqual ( self, qQ ) ===
 +
 
 +
==== Parameters ====
 +
:'''qQ''' [IN] The quaternion to multiply - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
 +
 
 +
==== Returns ====
 +
:Returns the multiplied quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
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
 +
</syntaxhighlight>
 +
 
 +
=== Normalize ( self ) ===
 +
 
 +
Normalize this quaternion, e.g. with a magnitude of 2.
 +
 
 +
==== Returns ====
 +
:The normalized quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
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
 +
</syntaxhighlight>
 +
 
 +
=== Rotate180 ( self ) ===
 +
 
 +
Rotate this quaternion by 180 degrees.
 +
 
 +
==== Returns ====
 +
:The rotated quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]]
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
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
 +
</syntaxhighlight>
 +
 
 +
=== SetX ( self, tX ) ===
 +
 
 +
Set the value of the x-axis.
 +
 
 +
==== Parameters ====
 +
:'''tX''' [IN] the value of the x-axis - float
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
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
 +
</syntaxhighlight>
 +
 
 +
=== SetY ( self, tY ) ===
 +
 
 +
Set the value of the y-axis.
 +
 
 +
==== Parameters ====
 +
:'''tY''' [IN] the value of the y-axis - float
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
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
 +
</syntaxhighlight>
 +
 
 +
=== SetZ ( self, tZ ) ===
 +
 
 +
Set the value of the z-axis.
 +
 
 +
==== Parameters ====
 +
:'''tZ''' [IN] the value of the z-axis - float
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
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
 +
</syntaxhighlight>
 +
 
 +
=== SetW ( self, tW ) ===
 +
 
 +
Set the value of the w-axis.
 +
 
 +
==== Parameters ====
 +
:'''tW''' [IN] the value of the w-axis - float
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
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
 
</syntaxhighlight>
 
</syntaxhighlight>
Get the z value of the quaternion.
 
====Returns====
 
<div style="margin-left: 2em;">The value of the z - float
 
</div>
 

Latest revision as of 20:50, 13 April 2020

Main article: Modules.
Last modified: 04/13/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. RQuaternion also 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) initialization value

Constructor & Destructor

__init__ ( self )

The constructor. Initialize a new RQuaternion object without initialization.

1 q = RLPy.RQuaternion()
2 
3 print(str(q.x) + ', ' + str(q.y) + ', ' + str(q.z) + ', ' + str(q.w)) # random values

__init__ ( self, vV )

The constructor. Initialize a new RQuaternion object from a 4D vector.

Parameters

vV [IN] a 4D vector - RVector4
1 v = RLPy.RVector4(1, 2, 3, 4)
2 q = RLPy.RQuaternion(v)
3 
4 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
1 v = RLPy.RVector4(1, 2, 3, 4)
2 q = RLPy.RQuaternion(v)
3 p = RLPy.RQuaternion(q)
4 
5 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 RQuaternion object 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
1 v = RLPy.RVector3(0, 0, 1)
2 q = RLPy.RQuaternion(v, math.pi/2)
3 
4 print(str(q.x) + ', ' + str(q.y) + ', ' + str(q.z) + ', ' + str(q.w))
5     # 0.0, 0.0, 0.7071067094802856, 0.7071067690849304

__init__ ( self, kRot )

The constructor. Initialize a new RQuaternion object with a 3x3 rotation matrix.

Parameters

kRot [IN] a 3x3 rotation matrix - RMatrix3
1 v = RLPy.RVector3(0, 0, 1)
2 m = RLPy.RMatrix3(v, math.pi/2)
3 q = RLPy.RQuaternion(m)
4 
5 print(str(q.x) + ', ' + str(q.y) + ', ' + str(q.z) + ', ' + str(q.w))
6     # 0.0, 0.0, 0.7071067690849304, 0.7071067690849304

Operators

=

The "equal to" operator.

1 q = RLPy.RQuaternion()
2 p = q
3 if q == p:                         # True
4     print("equal")

!=

The "not equal to" operator.

See Also: ==

1 a = RLPy.RVector4(1, 2, 3, 4)
2 q = RLPy.RQuaternion(a)
3 b = RLPy.RVector4(2, 2, 3, 4)
4 p = RLPy.RQuaternion(b)
5 if a != b:                         #True
6     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.

See Also: <=

 1 a = RLPy.RVector4(0, 1, 5, 2)
 2 b = RLPy.RVector4(0, 1, 5, 3)
 3 c = RLPy.RVector4(1, 0, 1, 0)
 4 d = RLPy.RVector4(0, 1, 5, 2)
 5 
 6 p = RLPy.RQuaternion(a)
 7 q = RLPy.RQuaternion(b)
 8 r = RLPy.RQuaternion(c)
 9 s = RLPy.RQuaternion(d)
10 
11 if p< q:                       #True
12     print('p< q')
13 if q< r:                       #True
14     print('q< r')
15 if p< s:                       #False
16     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.

See Also: >=

 1 a = RLPy.RVector4(0, 1, 5, 2)
 2 b = RLPy.RVector4(0, 1, 5, 3)
 3 c = RLPy.RVector4(1, 0, 1, 0)
 4 d = RLPy.RVector4(0, 1, 5, 2)
 5 
 6 p = RLPy.RQuaternion(a)
 7 q = RLPy.RQuaternion(b)
 8 r = RLPy.RQuaternion(c)
 9 s = RLPy.RQuaternion(d)
10 
11 if q >p:                       #True
12     print('q >p')
13 if r >q:                       #True
14     print('r >q')
15 if p >s:                       #False
16     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.

See Also: <

 1 a = RLPy.RVector4(0, 1, 5, 2)
 2 b = RLPy.RVector4(0, 1, 5, 3)
 3 c = RLPy.RVector4(1, 0, 1, 0)
 4 d = RLPy.RVector4(0, 1, 5, 2)
 5 
 6 p = RLPy.RQuaternion(a)
 7 q = RLPy.RQuaternion(b)
 8 r = RLPy.RQuaternion(c)
 9 s = RLPy.RQuaternion(d)
10 
11 if p<= q:                       #True
12     print('p<= q')
13 if q<= r:                       #True
14     print('q<= r')
15 if p<= s:                       #True
16     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.

See Also: >

 1 a = RLPy.RVector4(0, 1, 5, 2)
 2 b = RLPy.RVector4(0, 1, 5, 3)
 3 c = RLPy.RVector4(1, 0, 1, 0)
 4 d = RLPy.RVector4(0, 1, 5, 2)
 5 
 6 p = RLPy.RQuaternion(a)
 7 q = RLPy.RQuaternion(b)
 8 r = RLPy.RQuaternion(c)
 9 s = RLPy.RQuaternion(d)
10 
11 if q >= p:                       #True
12     print('q >= p')
13 if r >= q:                       #True
14     print('r >= q')
15 if p >= s:                       #True
16     print('p >= s')

+

The "addition" operator. Perform quaternion addition.

See Also: +=

1 a = RLPy.RVector4(0, 1, 2, 3)
2 b = RLPy.RVector4(1, 2, 3, 4)
3 p = RLPy.RQuaternion(a)
4 q = RLPy.RQuaternion(b)
5 r = p + q
6 
7 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.

See Also: -=

1 a = RLPy.RVector4(0, 1, 2, 3)
2 b = RLPy.RVector4(3, 2, 1, 0)
3 p = RLPy.RQuaternion(a)
4 q = RLPy.RQuaternion(b)
5 r = q - p
6 
7 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.

See Also: *=

1 a = RLPy.RVector4(1, 2, 3, 4)
2 p = RLPy.RQuaternion(a)
3 q = p * 2
4 r = p * p
5 
6 print(str(q.x) + ', ' + str(q.y) + ', ' + str(q.z) + ', ' + str(q.w)) # 2.0, 4.0, 6.0, 8.0
7 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.

See Also: /=

1 a = RLPy.RVector4(1, 2, 3, 4)
2 p = RLPy.RQuaternion(a)
3 q = p / 2
4 
5 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.

1 a = RLPy.RVector4(1, 2, 3, 4)
2 p = RLPy.RQuaternion(a)
3 q = -p
4 
5 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.

1 a = RLPy.RVector4(0, 1, 2, 3)
2 b = RLPy.RVector4(1, 2, 3, 4)
3 p = RLPy.RQuaternion(a)
4 q = RLPy.RQuaternion(b)
5 p += q
6 
7 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.

1 a = RLPy.RVector4(0, 1, 4, 5)
2 b = RLPy.RVector4(1, 2, 3, 1)
3 p = RLPy.RQuaternion(a)
4 q = RLPy.RQuaternion(b)
5 p -= q
6 
7 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.

See Also: *

1 a = RLPy.RVector4(1, 2, 3, 4)
2 p = RLPy.RQuaternion(a)
3 p *= 2
4 
5 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.

See Also: /

1 a = RLPy.RVector4(1, 2, 3, 4)
2 p = RLPy.RQuaternion(a)
3 p /= 2
4 
5 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 if 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
 1 a = RLPy.RVector4(1, 2, 3, 4)
 2 p = RLPy.RQuaternion(a)
 3 q = RLPy.RQuaternion(a)
 4 r = RLPy.RQuaternion(a)
 5 
 6 q.w = 4.000000001
 7 r.w = 4.00001
 8 
 9 if p.AlmostEqual(q):               #True
10     print("p ≈ q")
11 if q.AlmostEqual(r):               #False
12     print("p ≈ r")

Conjugate ( self )

Get the conjugate of this quaternion. The result is a quaternion whose x, y, and z values have been negated.

Returns

The conjugated quaternion. - RQuaternion
1 a = RLPy.RVector4(1, 2, 3, 4)
2 p = RLPy.RQuaternion(a)
3 q = p.Conjugate()
4 
5 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 the dot product of two quaternions.

Parameters

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

Returns

Value of the dot product - float
1 a = RLPy.RVector4(1, 2, 3, 4)
2 b = RLPy.RVector4(1, 2, 3, 0)
3 p = RLPy.RQuaternion(a)
4 q = RLPy.RQuaternion(b)
5 f = p.Dot(q)
6 
7 print(f)     # 14.0

FromAxisAngle ( self, rkAxis, fAngle )

Create a 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
1 p = RLPy.RQuaternion()
2 v = RLPy.RVector3(0, 0, 1)
3 p.FromAxisAngle(v, math.pi/2)
4 
5 print(str(p.x) + ', ' + str(p.y) + ', ' + str(p.z) + ', ' + str(p.w)) # 0.0, 0.0, 0.7071067094802856, 0.7071067690849304

FromRotationMatrix ( self, rkRot )

Create a quaternion from a rotation matrix.

Parameters

rkRot [IN] Rotation matrix - RMatrix3

Returns

Return a new quaternion from a rotation matrix - RQuaternion
1 v = RLPy.RVector3(0, 0, 1)
2 m = RLPy.RMatrix3(v, math.pi/2)
3 p = RLPy.RQuaternion()
4 p.FromRotationMatrix(m)
5 
6 print(str(p.x) + ', ' + str(p.y) + ', ' + str(p.z) + ', ' + str(p.w)) # 0.0, 0.0, 0.7071067690849304, 0.7071067690849304

Inverse ( self, rkRot )

Get the inverse of this quaternion.

Returns

The inversed quaternion - RQuaternion
1 a = RLPy.RVector4(1, 1, 1, 1)
2 p = RLPy.RQuaternion(a)
3 q = p.Inverse()
4 
5 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 this quaternion by another quaternion.

Parameters

qQ [IN] The quaternion to multiply - RQuaternion

Returns

Returns the multiplied quaternion - RQuaternion
1 a = RLPy.RVector4(1, 2, 3, 4)
2 b = RLPy.RVector4(1, 2, 2, 1)
3 
4 p = RLPy.RQuaternion(a)
5 q = RLPy.RQuaternion(b)
6 r = p.Multiply(q)
7 
8 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
1 a = RLPy.RVector4(1, 2, 3, 4)
2 b = RLPy.RVector4(1, 2, 2, 1)
3 
4 p = RLPy.RQuaternion(a)
5 q = RLPy.RQuaternion(b)
6 r = p.MultiplyEqual(q)
7 
8 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
1 a = RLPy.RVector4(1, 1, 1, 1)
2 p = RLPy.RQuaternion(a)
3 q = p.Normalize()
4 
5 print(str(q.x) + ', ' + str(q.y) + ', ' + str(q.z) + ', ' + str(q.w))
6     # 0.4999999701976776, 0.4999999701976776, 0.4999999701976776, 0.4999999701976776

Rotate180 ( self )

Rotate this quaternion by 180 degrees.

Returns

The rotated quaternion - RQuaternion
1 a = RLPy.RVector4(1, 1, 1, 1)
2 p = RLPy.RQuaternion(a)
3 q = p.Normalize()
4 
5 print(str(q.x) + ', ' + str(q.y) + ', ' + str(q.z) + ', ' + str(q.w))
6    #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
1 a = RLPy.RVector4(1, 2, 3, 4)
2 p = RLPy.RQuaternion(a)
3 p.SetX(9)
4 
5 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
1 a = RLPy.RVector4(1, 2, 3, 4)
2 p = RLPy.RQuaternion(a)
3 p.SetY(9)
4 print(str(p.x) + ', ' + str(p.y) + ', ' + str(p.z) + ', ' + str(p.w))
5     #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
1 a = RLPy.RVector4(1, 2, 3, 4)
2 p = RLPy.RQuaternion(a)
3 p.SetZ(9)
4 print(str(p.x) + ', ' + str(p.y) + ', ' + str(p.z) + ', ' + str(p.w))
5     #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
1 a = RLPy.RVector4(1, 2, 3, 4)
2 p = RLPy.RQuaternion(a)
3 p.SetW(9)
4 print(str(p.x) + ', ' + str(p.y) + ', ' + str(p.z) + ', ' + str(p.w))
5     #1.0, 2.0, 3.0, 9.0