Difference between revisions of "Quaternion Class"

From Derivative
Jump to navigation Jump to search
Line 8: Line 8:
 
     |name=w
 
     |name=w
 
     |type=float
 
     |type=float
     |set=0
+
     |set=1
     |text=Quaternion_w
+
     |text=Get or set the w component of the quaternion.
 
}}
 
}}
 
{{ClassMember
 
{{ClassMember
Line 15: Line 15:
 
     |name=x
 
     |name=x
 
     |type=float
 
     |type=float
     |set=0
+
     |set=1
     |text=Quaternion_x
+
     |text=Get or set the x component of the quaternion.
 
}}
 
}}
 
{{ClassMember
 
{{ClassMember
Line 22: Line 22:
 
     |name=y
 
     |name=y
 
     |type=float
 
     |type=float
     |set=0
+
     |set=1
     |text=Quaternion_y
+
     |text=Get or set the y component of the quaternion.
 
}}
 
}}
 
{{ClassMember
 
{{ClassMember
Line 29: Line 29:
 
     |name=z
 
     |name=z
 
     |type=float
 
     |type=float
     |set=0
+
     |set=1
     |text=Quaternion_z
+
     |text=Get or set the z component of the quaternion.
 
}}}}
 
}}}}
 
{{ClassMethodSection|empty=
 
{{ClassMethodSection|empty=
Line 39: Line 39:
 
     |class=tdu.Quaternion
 
     |class=tdu.Quaternion
 
     |name=lerp
 
     |name=lerp
     |call=lerp(q2, lerpF)
+
     |call=lerp(q2, factor)
 
     |returns=quaternion
 
     |returns=quaternion
     |text=Returns a quaternion as the linear interpolation of the current quaternion (q) and another quaternion (q2) using an interpolation factor (lerpF) in the range [0,1].
+
     |text=Returns the linear interpolation of the quaternion with another quaternion and an interpolation factor.
 +
The quaternion argument can be anything from which a quaternion can be derived ie. (x,y,z,w), Matrix, etc.
 +
The interpolation factor must be between 0 and 1.
 
<syntaxhighlight lang=python>
 
<syntaxhighlight lang=python>
l = q.lerp(q2, lerpF)
+
q3 = q.lerp(q2, factor)
 
</syntaxhighlight>
 
</syntaxhighlight>
 
}}
 
}}
Line 51: Line 53:
 
     |call=length()
 
     |call=length()
 
     |returns=float
 
     |returns=float
     |text=Returns the length of the current quaternion.
+
     |text=Returns the length of the quaternion.
 
<syntaxhighlight lang=python>
 
<syntaxhighlight lang=python>
 
l = q.length()
 
l = q.length()
Line 61: Line 63:
 
     |call=cross(q2)
 
     |call=cross(q2)
 
     |returns=vector
 
     |returns=vector
     |text=Returns the cross product of the current quaternion and another quaternion.
+
     |text=Returns the cross product of the quaternion and argument.
 +
The quaternion argument can be anything from which a quaternion can be derived ie. (x,y,z,w), Matrix, etc.
 
<syntaxhighlight lang=python>
 
<syntaxhighlight lang=python>
 
l = q.cross(q2)
 
l = q.cross(q2)
Line 71: Line 74:
 
     |call=rotate(vec)
 
     |call=rotate(vec)
 
     |returns=vector
 
     |returns=vector
     |text=Rotates a vector using the current quaternion and returns a new vector.  
+
     |text=Rotates a vector using the current quaternion. Returns a new vector.
 
<syntaxhighlight lang=python>
 
<syntaxhighlight lang=python>
l= q.rotate(vec)
+
v2 = q.rotate(v1)
 
</syntaxhighlight>
 
</syntaxhighlight>
 
}}
 
}}
Line 79: Line 82:
 
     |class=tdu.Quaternion
 
     |class=tdu.Quaternion
 
     |name=slerp
 
     |name=slerp
     |call=slerp(q2, slerpF)
+
     |call=slerp(q2, factor)
 
     |returns=quaternion
 
     |returns=quaternion
     |text=Returns a quaternion as the spherical interpolation of the current quaternion (q) and another quaternion (q2) using an interpolation factor (slerpF).
+
     |text=Returns the spherical interpolation of the quaternion with another quaternion and an interpolation factor.
 +
The quaternion argument can be anything from which a quaternion can be derived ie. (x,y,z,w), Matrix, etc.
 
<syntaxhighlight lang=python>
 
<syntaxhighlight lang=python>
l = q.slerp(q2, slerpF)
+
q3 = q.slerp(q2, factor)
 
</syntaxhighlight>
 
</syntaxhighlight>
 
}}
 
}}
Line 91: Line 95:
 
     |call=eulerAngles(order='xyz')
 
     |call=eulerAngles(order='xyz')
 
     |returns=tuple
 
     |returns=tuple
     |text=Returns euler angles in degrees as a tuple (i.e. pitch as x, yaw as y, roll as z) from current quaternion. The 'order' argument can be set to any valid rotation order which by default is set to 'xyz'.  
+
     |text=Returns euler angles in degrees as a tuple (i.e. pitch as x, yaw as y, roll as z) from current quaternion and a rotation order. The 'order' argument can be set to any valid rotation order which by default is set to 'xyz'.  
 
<syntaxhighlight lang=python>
 
<syntaxhighlight lang=python>
l = q.eulerAngles(order='xyz')
+
r = q.eulerAngles(order='xyz')
 
</syntaxhighlight>
 
</syntaxhighlight>
 
}}
 
}}
Line 101: Line 105:
 
     |call=axis()
 
     |call=axis()
 
     |returns=vector
 
     |returns=vector
     |text=Returns the rotation axis vector of the current.
+
     |text=Returns the rotation axis vector of the quaternion.
 
<syntaxhighlight lang=python>
 
<syntaxhighlight lang=python>
l = q.axis()
+
v = q.axis()
 
</syntaxhighlight>
 
</syntaxhighlight>
 
}}
 
}}
Line 109: Line 113:
 
     |class=tdu.Quaternion
 
     |class=tdu.Quaternion
 
     |name=dot
 
     |name=dot
     |call=dot(quat)
+
     |call=dot(q2)
 
     |returns=float
 
     |returns=float
 
     |text=Returns the dot product of the quaternion and the argument.
 
     |text=Returns the dot product of the quaternion and the argument.
The quaternion argument can be anything from which a quaternion can be derived (x,y,z,w), Matrix, etc).
+
The quaternion argument can be anything from which a quaternion can be derived ie. (x,y,z,w), Matrix, etc.
 
<syntaxhighlight lang=python>
 
<syntaxhighlight lang=python>
 
l = q.dot(q2)
 
l = q.dot(q2)
Line 122: Line 126:
 
     |call=exp()
 
     |call=exp()
 
     |returns=quaternion
 
     |returns=quaternion
     |text=Returns the exponential of the current as a new quaternion.
+
     |text=Returns the exponential of the quaternion as a new quaternion.
 
<syntaxhighlight lang=python>
 
<syntaxhighlight lang=python>
l = q.exp()
+
q2 = q.exp()
 
</syntaxhighlight>
 
</syntaxhighlight>
 
}}
 
}}
Line 139: Line 143:
 
     |call=log()
 
     |call=log()
 
     |returns=quaternion
 
     |returns=quaternion
     |text=Returns the natural logarithm of the current as a new quaternion.
+
     |text=Returns the natural logarithm of the current quaternion as a new quaternion.
 
<syntaxhighlight lang=python>
 
<syntaxhighlight lang=python>
 
l = q.log()
 
l = q.log()
Line 149: Line 153:
 
     |call=inverse()
 
     |call=inverse()
 
     |returns=None
 
     |returns=None
     |text=Invert the current quaternion.
+
     |text=Invert the quaternion in place.
 
<syntaxhighlight lang=python>
 
<syntaxhighlight lang=python>
 
q.inverse()
 
q.inverse()
Line 159: Line 163:
 
     |call=angle()
 
     |call=angle()
 
     |returns=float
 
     |returns=float
     |text=Returns the rotation angle (in degrees) of the current.
+
     |text=Returns the rotation angle (in degrees) of the quaternion.
 
<syntaxhighlight lang=python>
 
<syntaxhighlight lang=python>
l = q.angle()
+
a = q.angle()
 
</syntaxhighlight>
 
</syntaxhighlight>
 
}}}}
 
}}}}

Revision as of 06:57, 29 May 2018

Quaternion


Members

wfloat :

Get or set the w component of the quaternion.

xfloat :

Get or set the x component of the quaternion.

yfloat :

Get or set the y component of the quaternion.

zfloat :

Get or set the z component of the quaternion.

Methods

lerp(q2, factor)quaternion:

Returns the linear interpolation of the quaternion with another quaternion and an interpolation factor.

The quaternion argument can be anything from which a quaternion can be derived ie. (x,y,z,w), Matrix, etc. The interpolation factor must be between 0 and 1.

q3 = q.lerp(q2, factor)

length()float:

Returns the length of the quaternion.

l = q.length()

cross(q2)vector:

Returns the cross product of the quaternion and argument.

The quaternion argument can be anything from which a quaternion can be derived ie. (x,y,z,w), Matrix, etc.

l = q.cross(q2)

rotate(vec)vector:

Rotates a vector using the current quaternion. Returns a new vector.

v2 = q.rotate(v1)

slerp(q2, factor)quaternion:

Returns the spherical interpolation of the quaternion with another quaternion and an interpolation factor.

The quaternion argument can be anything from which a quaternion can be derived ie. (x,y,z,w), Matrix, etc.

q3 = q.slerp(q2, factor)

eulerAngles(order='xyz')tuple:

Returns euler angles in degrees as a tuple (i.e. pitch as x, yaw as y, roll as z) from current quaternion and a rotation order. The 'order' argument can be set to any valid rotation order which by default is set to 'xyz'.

r = q.eulerAngles(order='xyz')

axis()vector:

Returns the rotation axis vector of the quaternion.

v = q.axis()

dot(q2)float:

Returns the dot product of the quaternion and the argument.

The quaternion argument can be anything from which a quaternion can be derived ie. (x,y,z,w), Matrix, etc.

l = q.dot(q2)

exp()quaternion:

Returns the exponential of the quaternion as a new quaternion.

q2 = q.exp()

copy()quaternion:

Creates a copy of the quaternion with separate values.

log()quaternion:

Returns the natural logarithm of the current quaternion as a new quaternion.

l = q.log()

inverse()None:

Invert the quaternion in place.

q.inverse()

angle()float:

Returns the rotation angle (in degrees) of the quaternion.

a = q.angle()

TouchDesigner Build: