|
Simple module providing a quaternion class for manipulating rotations easily.
NOTE: unittest in quaternion_test.py
NOTE: a lot of this code is taken from various places, including OpenglContext.
Note: all angles are assumed to be specified in radians.
Note: this is an entirely separate implementation from the PyOpenGL
quaternion class. This implementation assumes that Numeric python
will be available, and provides only those methods and helpers
commonly needed for manipulating rotations.
TODO:
Make all functions use an array instead of a quat class.
Make a quat class which uses the functions.
Make a c version of for the python functions.
- based off amd lib, gamasutra article, and CS quats.
|
Imported modules
|
|
import Matrix
import Numeric
import math
|
|
Functions
|
|
|
|
|
|
angle_to_radians
|
angle_to_radians ( angle )
|
|
|
euler_to_quats
|
euler_to_quats ( rotations )
Returns a sequence of quats.
It is an array where each quat is four floats.
w,x,y,z is the order.
rotations- an array of rotations.
where each rotation is three floats.
|
|
|
fromAXYZ
|
fromAXYZ (
a,
x,
y,
z,
)
|
|
|
fromEuler
|
fromEuler (
x=0,
y=0,
z=0,
)
Create a new quaternion from a 3-element euler-angle
rotation about x, then y, then z
|
|
|
fromEuler_angle
|
fromEuler_angle (
x=0,
y=0,
z=0,
)
From x,y,z angles in degrees create a quat.
|
|
|
fromMatrix
|
fromMatrix ( matrix )
from a 4x4 matrix return a quaternion.
These are the orders of the matrix:
[00,01,02,03]
[10,11,12,13]
[20,21,22,23]
[30,31,32,33] [0 , 1, 2, 3]
[4 , 5, 6, 7]
[8 , 9,10,11]
[12,13,14,15]
Which is the opengl order.
|
|
|
fromXYZR
|
fromXYZR (
x,
y,
z,
r,
)
Create a new quaternion from a VRML-style rotation
x,y,z are the axis of rotation
r is the rotation in radians.
|
|
|
from_euler_list
|
from_euler_list ( l )
|
|
|
get_angles_from_two_points
|
get_angles_from_two_points ( a, b )
returns the angles along the x,y,z axis. this is direction of the
two points.
|
Exceptions
|
|
ValueError("shouldn't get here x:%s: y :%s: " %( x, y ) )
|
|
|
|
length_quat
|
length_quat ( quat )
|
|
|
magnitude_vectors
|
magnitude_vectors ( vectors )
Calculate the magnitudes of the given vectors
- vectors
- sequence object with 1 or more
3-item vector values.
returns a double array with x elements,
where x is the number of 3-element vectors
|
|
|
normalise_vector
|
normalise_vector ( vector )
Given a 3 or 4-item vector, return a 3-item unit vector
|
|
|
normalise_vectors
|
normalise_vectors ( vectors )
Get normalised versions of the vectors.
- vectors
- sequence object with 1 or more
3-item vector values.
returns a double array with x 3-element vectors,
where x is the number of 3-element vectors in "vectors"
Will raise ZeroDivisionError if there are 0-magnitude
vectors in the set.
|
|
|
radians_to_angle
|
radians_to_angle ( radians )
|
|
|
slerp_quat
|
slerp_quat (
quat_a,
quat_b,
slerp,
)
Returns a quaternion spherically interpolated between quat_a, quat_b.
quat_a, quat_b - quaternions to interpolate between.
slerp - interp factor (0.0 = quat_a, 1.0 = quat_b)
|
|
Classes
|
|
Quaternion |
Quaternion object implementing those methods required
|
|
|