Difference between revisions of "IC Python API:RLPy RQuaternion"
Chuck (RL) (Talk | contribs) m (→Operator) |
Chuck (RL) (Talk | contribs) m |
||
Line 15: | Line 15: | ||
|- | |- | ||
|RQuaternion.ZERO | |RQuaternion.ZERO | ||
− | |4D x unit vector: (0, 0, 0, 0) | + | |4D x unit vector: (0, 0, 0, 0) initialization value |
|} | |} | ||
== Constructor & Destructor == | == Constructor & Destructor == | ||
− | === __init__( self ) === | + | === __init__ ( self ) === |
The constructor. Initialize a new [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] object without initialization. | The constructor. Initialize a new [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] object without initialization. | ||
− | <syntaxhighlight lang="python"> | + | <syntaxhighlight lang="python" line='line'> |
q = RLPy.RQuaternion() | q = RLPy.RQuaternion() | ||
Line 30: | Line 30: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === __init__( self, vV ) === | + | === __init__ ( self, vV ) === |
The constructor. Initialize a new [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] object from a 4D vector. | The constructor. Initialize a new [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] object from a 4D vector. | ||
Line 37: | Line 37: | ||
:'''vV''' [IN] a 4D vector - [[IC_Python_API:RLPy_RVector4|RVector4]] | :'''vV''' [IN] a 4D vector - [[IC_Python_API:RLPy_RVector4|RVector4]] | ||
− | <syntaxhighlight lang="python"> | + | <syntaxhighlight lang="python" line='line'> |
v = RLPy.RVector4(1, 2, 3, 4) | v = RLPy.RVector4(1, 2, 3, 4) | ||
q = RLPy.RQuaternion(v) | q = RLPy.RQuaternion(v) | ||
Line 44: | Line 44: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === __init__( self, qQ ) === | + | === __init__ ( self, qQ ) === |
==== Parameters ==== | ==== Parameters ==== | ||
:'''qQ''' [IN] a quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] | :'''qQ''' [IN] a quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] | ||
− | <syntaxhighlight lang="python"> | + | <syntaxhighlight lang="python" line='line'> |
v = RLPy.RVector4(1, 2, 3, 4) | v = RLPy.RVector4(1, 2, 3, 4) | ||
q = RLPy.RQuaternion(v) | q = RLPy.RQuaternion(v) | ||
Line 57: | Line 57: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === __init__( self, kAxis, fAngle ) === | + | === __init__ ( self, kAxis, fAngle ) === |
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. | 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. | ||
Line 65: | Line 65: | ||
:'''fAngle''' [IN] the rotation angle - float | :'''fAngle''' [IN] the rotation angle - float | ||
− | <syntaxhighlight lang="python"> | + | <syntaxhighlight lang="python" line='line'> |
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 73: | Line 73: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === __init__( self, kRot ) === | + | === __init__ ( self, kRot ) === |
The constructor. Initialize a new [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] object with a 3x3 rotation matrix. | The constructor. Initialize a new [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] object with a 3x3 rotation matrix. | ||
Line 80: | Line 80: | ||
:'''kRot''' [IN] a 3x3 rotation matrix - [[IC_Python_API:RLPy_RMatrix3|RMatrix3]] | :'''kRot''' [IN] a 3x3 rotation matrix - [[IC_Python_API:RLPy_RMatrix3|RMatrix3]] | ||
− | <syntaxhighlight lang="python"> | + | <syntaxhighlight lang="python" line='line'> |
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" line='line'> |
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"> | + | See Also: [[#==|==]] |
+ | |||
+ | <syntaxhighlight lang="python" line='line'> | ||
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 121: | ||
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"> | + | See Also: [[#<=|<=]] |
+ | |||
+ | <syntaxhighlight lang="python" line='line'> | ||
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 146: | ||
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"> | + | See Also: [[#>=|>=]] |
+ | |||
+ | <syntaxhighlight lang="python" line='line'> | ||
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 171: | ||
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"> | + | See Also: [[#<|<]] |
+ | |||
+ | <syntaxhighlight lang="python" line='line'> | ||
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 196: | ||
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"> | + | See Also: [[#>|>]] |
+ | |||
+ | <syntaxhighlight lang="python" line='line'> | ||
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 221: | ||
The "addition" operator. Perform quaternion addition. | The "addition" operator. Perform quaternion addition. | ||
− | <syntaxhighlight lang="python"> | + | See Also: [[#+=|+=]] |
+ | |||
+ | <syntaxhighlight lang="python" line='line'> | ||
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 237: | ||
The "subtraction" operator. Perform quaternion subtraction. | The "subtraction" operator. Perform quaternion subtraction. | ||
− | <syntaxhighlight lang="python"> | + | See Also: [[#-=|-=]] |
+ | |||
+ | <syntaxhighlight lang="python" line='line'> | ||
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 253: | ||
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"> | + | See Also: [[#*=|*=]] |
+ | |||
+ | <syntaxhighlight lang="python" line='line'> | ||
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 269: | ||
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"> | + | See Also: [[#/=|/=]] |
+ | |||
+ | <syntaxhighlight lang="python" line='line'> | ||
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 283: | ||
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" line='line'> |
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 295: | ||
The "addition assignment" operator. | The "addition assignment" operator. | ||
− | <syntaxhighlight lang="python"> | + | <syntaxhighlight lang="python" line='line'> |
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 309: | ||
The "subtraction assignment" operator. | The "subtraction assignment" operator. | ||
− | <syntaxhighlight lang="python"> | + | <syntaxhighlight lang="python" line='line'> |
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 323: | ||
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"> | + | See Also: [[#*|*]] |
+ | |||
+ | <syntaxhighlight lang="python" line='line'> | ||
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 337: | ||
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"> | + | See Also: [[#/|/]] |
+ | |||
+ | <syntaxhighlight lang="python" line='line'> | ||
a = RLPy.RVector4(1, 2, 3, 4) | a = RLPy.RVector4(1, 2, 3, 4) | ||
p = RLPy.RQuaternion(a) | p = RLPy.RQuaternion(a) | ||
Line 327: | Line 349: | ||
== Member Functions == | == Member Functions == | ||
− | === AlmostEqual( self, qQ ) === | + | === AlmostEqual ( self, qQ ) === |
Determine if two quaternions are almost the same within a tolerance of 0.00001. | Determine if two quaternions are almost the same within a tolerance of 0.00001. | ||
Line 337: | Line 359: | ||
:'''True''' if the two quaternions are almost the same, else '''False''' - bool | :'''True''' if the two quaternions are almost the same, else '''False''' - bool | ||
− | <syntaxhighlight lang="python"> | + | <syntaxhighlight lang="python" line='line'> |
a = RLPy.RVector4(1, 2, 3, 4) | a = RLPy.RVector4(1, 2, 3, 4) | ||
p = RLPy.RQuaternion(a) | p = RLPy.RQuaternion(a) | ||
Line 352: | Line 374: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === Conjugate( self ) === | + | === Conjugate ( self ) === |
Get the conjugate of this quaternion. The result is a quaternion whose x, y, and z values have been negated. | Get the conjugate of this quaternion. The result is a quaternion whose x, y, and z values have been negated. | ||
Line 359: | Line 381: | ||
:The conjugated quaternion. - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] | :The conjugated quaternion. - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] | ||
− | <syntaxhighlight lang="python"> | + | <syntaxhighlight lang="python" line='line'> |
a = RLPy.RVector4(1, 2, 3, 4) | a = RLPy.RVector4(1, 2, 3, 4) | ||
p = RLPy.RQuaternion(a) | p = RLPy.RQuaternion(a) | ||
Line 367: | Line 389: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === Dot( self, qQ ) === | + | === Dot ( self, qQ ) === |
Calculate the dot product of two quaternions. | Calculate the dot product of two quaternions. | ||
Line 377: | Line 399: | ||
:Value of the dot product - float | :Value of the dot product - float | ||
− | <syntaxhighlight lang="python"> | + | <syntaxhighlight lang="python" line='line'> |
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 387: | Line 409: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === FromAxisAngle( self, rkAxis, fAngle ) === | + | === FromAxisAngle ( self, rkAxis, fAngle ) === |
Create a quaternion from axis angle. | Create a quaternion from axis angle. | ||
Line 398: | Line 420: | ||
:Return a new quaternion from a axis angle - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] | :Return a new quaternion from a axis angle - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] | ||
− | <syntaxhighlight lang="python"> | + | <syntaxhighlight lang="python" line='line'> |
p = RLPy.RQuaternion() | p = RLPy.RQuaternion() | ||
v = RLPy.RVector3(0, 0, 1) | v = RLPy.RVector3(0, 0, 1) | ||
Line 406: | Line 428: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === FromRotationMatrix( self, rkRot ) === | + | === FromRotationMatrix ( self, rkRot ) === |
Create a quaternion from a rotation matrix. | Create a quaternion from a rotation matrix. | ||
Line 416: | Line 438: | ||
:Return a new quaternion from a rotation matrix - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] | :Return a new quaternion from a rotation matrix - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] | ||
− | <syntaxhighlight lang="python"> | + | <syntaxhighlight lang="python" line='line'> |
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 425: | Line 447: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === Inverse( self, rkRot ) === | + | === Inverse ( self, rkRot ) === |
Get the inverse of this quaternion. | Get the inverse of this quaternion. | ||
Line 432: | Line 454: | ||
:The inversed quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] | :The inversed quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] | ||
− | <syntaxhighlight lang="python"> | + | <syntaxhighlight lang="python" line='line'> |
a = RLPy.RVector4(1, 1, 1, 1) | a = RLPy.RVector4(1, 1, 1, 1) | ||
p = RLPy.RQuaternion(a) | p = RLPy.RQuaternion(a) | ||
Line 440: | Line 462: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === Multiply( self, qQ ) === | + | === Multiply ( self, qQ ) === |
Multiply this quaternion by another quaternion. | Multiply this quaternion by another quaternion. | ||
Line 450: | Line 472: | ||
:Returns the multiplied quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] | :Returns the multiplied quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] | ||
− | <syntaxhighlight lang="python"> | + | <syntaxhighlight lang="python" line='line'> |
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 461: | Line 483: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === MultiplyEqual( self, qQ ) === | + | === MultiplyEqual ( self, qQ ) === |
==== Parameters ==== | ==== Parameters ==== | ||
Line 469: | Line 491: | ||
:Returns the multiplied quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] | :Returns the multiplied quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] | ||
− | <syntaxhighlight lang="python"> | + | <syntaxhighlight lang="python" line='line'> |
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 480: | Line 502: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === Normalize( self ) === | + | === Normalize ( self ) === |
Normalize this quaternion, e.g. with a magnitude of 2. | Normalize this quaternion, e.g. with a magnitude of 2. | ||
Line 487: | Line 509: | ||
:The normalized quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] | :The normalized quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] | ||
− | <syntaxhighlight lang="python"> | + | <syntaxhighlight lang="python" line='line'> |
a = RLPy.RVector4(1, 1, 1, 1) | a = RLPy.RVector4(1, 1, 1, 1) | ||
p = RLPy.RQuaternion(a) | p = RLPy.RQuaternion(a) | ||
Line 496: | Line 518: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === Rotate180( self ) === | + | === Rotate180 ( self ) === |
Rotate this quaternion by 180 degrees. | Rotate this quaternion by 180 degrees. | ||
Line 503: | Line 525: | ||
:The rotated quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] | :The rotated quaternion - [[IC_Python_API:RLPy_RQuaternion|RQuaternion]] | ||
− | <syntaxhighlight lang="python"> | + | <syntaxhighlight lang="python" line='line'> |
a = RLPy.RVector4(1, 1, 1, 1) | a = RLPy.RVector4(1, 1, 1, 1) | ||
p = RLPy.RQuaternion(a) | p = RLPy.RQuaternion(a) | ||
Line 512: | Line 534: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === SetX( self, tX ) === | + | === SetX ( self, tX ) === |
Set the value of the x-axis. | Set the value of the x-axis. | ||
Line 519: | Line 541: | ||
:'''tX''' [IN] the value of the x-axis - float | :'''tX''' [IN] the value of the x-axis - float | ||
− | <syntaxhighlight lang="python"> | + | <syntaxhighlight lang="python" line='line'> |
a = RLPy.RVector4(1, 2, 3, 4) | a = RLPy.RVector4(1, 2, 3, 4) | ||
p = RLPy.RQuaternion(a) | p = RLPy.RQuaternion(a) | ||
Line 527: | Line 549: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === SetY( self, tY ) === | + | === SetY ( self, tY ) === |
Set the value of the y-axis. | Set the value of the y-axis. | ||
Line 534: | Line 556: | ||
:'''tY''' [IN] the value of the y-axis - float | :'''tY''' [IN] the value of the y-axis - float | ||
− | <syntaxhighlight lang="python"> | + | <syntaxhighlight lang="python" line='line'> |
a = RLPy.RVector4(1, 2, 3, 4) | a = RLPy.RVector4(1, 2, 3, 4) | ||
p = RLPy.RQuaternion(a) | p = RLPy.RQuaternion(a) | ||
Line 542: | Line 564: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === SetZ( self, tZ ) === | + | === SetZ ( self, tZ ) === |
Set the value of the z-axis. | Set the value of the z-axis. | ||
Line 549: | Line 571: | ||
:'''tZ''' [IN] the value of the z-axis - float | :'''tZ''' [IN] the value of the z-axis - float | ||
− | <syntaxhighlight lang="python"> | + | <syntaxhighlight lang="python" line='line'> |
a = RLPy.RVector4(1, 2, 3, 4) | a = RLPy.RVector4(1, 2, 3, 4) | ||
p = RLPy.RQuaternion(a) | p = RLPy.RQuaternion(a) | ||
Line 557: | Line 579: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === SetW( self, tW ) === | + | === SetW ( self, tW ) === |
Set the value of the w-axis. | Set the value of the w-axis. | ||
Line 564: | Line 586: | ||
:'''tW''' [IN] the value of the w-axis - float | :'''tW''' [IN] the value of the w-axis - float | ||
− | <syntaxhighlight lang="python"> | + | <syntaxhighlight lang="python" line='line'> |
a = RLPy.RVector4(1, 2, 3, 4) | a = RLPy.RVector4(1, 2, 3, 4) | ||
p = RLPy.RQuaternion(a) | p = RLPy.RQuaternion(a) |
Latest revision as of 19:50, 13 April 2020
Contents
- 1 Detailed Description
- 2 Constructor & Destructor
- 3 Operators
- 4 Member Functions
- 4.1 AlmostEqual ( self, qQ )
- 4.2 Conjugate ( self )
- 4.3 Dot ( self, qQ )
- 4.4 FromAxisAngle ( self, rkAxis, fAngle )
- 4.5 FromRotationMatrix ( self, rkRot )
- 4.6 Inverse ( self, rkRot )
- 4.7 Multiply ( self, qQ )
- 4.8 MultiplyEqual ( self, qQ )
- 4.9 Normalize ( self )
- 4.10 Rotate180 ( self )
- 4.11 SetX ( self, tX )
- 4.12 SetY ( self, tY )
- 4.13 SetZ ( self, tZ )
- 4.14 SetW ( self, tW )
- 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