public class Quaternion
extends java.lang.Object
implements java.lang.Cloneable
angle = 2 * arccos(w) axis = [ x/sin(angle/2), y/sin(angle/2), z/sin(angle/2) ]
Constructor and Description |
---|
Quaternion()
Constructs a Quaternion with default values (1, [0 0 0]), which is the
Identity quaternion representing zero rotation.
|
Quaternion(double[] angleAxis)
Constructs a quaternion representing an orientation specified by an angle
of rotation and an axis of rotation represented with real values.
|
Quaternion(double scalarPart,
double[] vectorPart)
Constructs a quaternion with the specified scalar and vector parts.
|
Quaternion(double angle,
Vector3D axis)
Constructs a quaternion representing an orientation specified by an angle
of rotation and a
Vector3D giving the axis of rotation. |
Modifier and Type | Method and Description |
---|---|
Quaternion |
add(Quaternion other)
Returns a new quaternion which is the result of adding this quaternion to
the specified other quaternion.
|
java.lang.Object |
clone()
Returns a new
Quaternion which is a deep clone of this
Quaternion. |
Quaternion |
conjugate()
Returns a new
Quaternion which is the conjugate of this
Quaternion . |
double |
dot(Quaternion other)
Returns the dot-product of this quaternion with the specified quaternion.
|
double[] |
getAngleAxis()
Returns the angle and axis of rotation specified by this quaternion.
|
double[] |
getV()
Returns the vector part of this quaternion.
|
double |
getW()
Returns the scalar part of this quaternion.
|
double |
magnitude()
Returns the magnitude of this quaternion, where magnitude equals the
square root of the sum of the squares of the four constituent parts of
the quaternion (the scalar part and the three components of the axis
part).
|
Point3D |
mult(Point3D point)
Rotate the point about this quaternion.
|
Vector3D |
mult(Vector3D vec)
Multiply this Quaternion by a vec, and return the new Vector3D.
|
Quaternion |
multiplyBy(double scaleFactor)
Returns a new quaternion which is the result of multiplying (scaling)
this quaternion by the specified scale factor.
|
Quaternion |
multiplyBy(Quaternion q)
Returns a new quaternion which is the product of this quaternion
post-multiplied by the specified quaternion.
|
void |
normalize()
Normalizes this quaternion; that is, forces it to be of unit length.
|
Point3D |
pivot(Point3D point,
Point3D about)
Overload of pivot(Vector3D, Point3D).
|
Vector3D |
pivot(Vector3D vec,
Point3D about)
Pivot a vector about a point using the rotation defined by this quaternion.
|
Vector3D |
rotate(Vector3D v)
|
void |
setV(double[] v)
Specifies a new vector part for this quaternion.
|
void |
setW(double w)
Specifies a new value for the scalar part of this quaternion.
|
Quaternion |
slerp(Quaternion quat,
double amount)
Spherical interpolation between this quaternion and quat.
|
Matrix3D |
toMatrix3D()
Convert this Quaternion to a rotation matrix.
|
java.lang.String |
toString()
Returns a String representation of this quaternion.
|
public Quaternion()
public Quaternion(double scalarPart, double[] vectorPart)
scalarPart
- A double representing the scalar part of the quaternionvectorPart
- An array of doubles representing the [x,y,z] vector part of
the quaternionQuaternion(double[])
public Quaternion(double[] angleAxis)
Quaternion(double,double[])
, this constructor expects
as input the angle of rotation and axis of rotation in 3D space.angleAxis
- An array of doubles where [0] specifies an angle of rotation
in degrees and [1][2][3] specify the [x y z] components of an
axis of rotation.Quaternion(double, double[])
public Quaternion(double angle, Vector3D axis)
Vector3D
giving the axis of rotation. Note that
unlike the constructor Quaternion(double,double[])
,
this constructor expects as input the angle of rotation in degrees and
axis of rotation in 3D space.angle
- The angle of rotation in degrees represented by this
quaternionaxis
- The axis of rotation represented by this quaternionpublic double[] getAngleAxis()
public double magnitude()
public void normalize()
public Quaternion multiplyBy(Quaternion q)
The definition of the product of two quaternions is that of quaternion multiplication:
For quaternions q1 = (w1, v1[x1,y1,z1]) and q2 = (w2, v2[x2,y2,z2]), q1 * q2 = [ ( w1*w2 - (v1 dot v2) ), ( w1*v2 + w2*v1 + (v1 cross v2) ) ]where 'w' represents the scalar part of a quaternion and v represents the vector part of a quaternion.
q
- the quaternion to be post-multiplied with this quaternionpublic Quaternion multiplyBy(double scaleFactor)
scaleFactor
- The multiplier which is applied to this quaternion to produce
the new (returned) quaternion.public Quaternion conjugate()
Quaternion
which is the conjugate of this
Quaternion
. The conjugate q' of a quaternion q=(w, [x,y,z]) is
defined as q' = (w, [-x,-y,-z]). This method does not affect the current
quaternion.public Vector3D rotate(Vector3D v)
Vector3D
which is the result of applying the rotation
specified by this quaternion to the specified Vector3D
. The
resultant Vector3D
is generated by multiplying this quaternion by
the specified Vector3D
and then multiplying the result by the
conjugate of this quaternion. That is, the result is computed by applying
the quaternion rotation formula
newV = Q * V * Q' ,where Q is a quaternion, V is a vector, and Q' is the conjugate of Q.
public double getW()
Quaternion
class header comments for details on the relationship
of the parts of a quaternion to the orientation represented by the
quaternion.public void setW(double w)
Quaternion
class header comments for details
on the relationship of the parts of a quaternion to the orientation
represented by the quaternion.w
- The new value for the scalar part of the quaternion.public double[] getV()
Quaternion
class header comments for details on the relationship
of the parts of a quaternion to the orientation represented by the
quaternion. To obtain the axis of rotation represented by this
quaternion, use the axis portion of the values returned by
getAngleAxis()
.public void setV(double[] v)
Quaternion
class header comments for details on the relationship
of the parts of a quaternion to the orientation represented by the
quaternion.v
- An array of doubles representing the new vector part of the
quaternion.public java.lang.Object clone()
Quaternion
which is a deep clone of this
Quaternion.clone
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public double dot(Quaternion other)
other
- A quaternion whose components are multiplied with the
corresponding components of this quaternionpublic Quaternion add(Quaternion other)
other
- A quaternion to be added to this quaternionpublic Matrix3D toMatrix3D()
public Quaternion slerp(Quaternion quat, double amount)
quat
- The quaternion with which this quaternion should be interpolated.amount
- The amount to interpolate.public Vector3D pivot(Vector3D vec, Point3D about)
vec
- The vector to pivot.about
- The point to pivot about.public Point3D pivot(Point3D point, Point3D about)
point
- The point to pivot.about
- The point to pivot about.public Vector3D mult(Vector3D vec)
vec
- The Vector3D which should be rotated using this Quaternion.