public class Quaternion extends Number
x = x0 + x1 i + x2 j + x3 k,
where x0, x1, x2, x3 are real numbers and the numbers i, j, k are defined to satisfy the Hamilton relationsi2 = j2 = k2 = ijk = -1, ij = -ji = k,
cf. Ebbinghaus et al.: Numbers. Springer-Verlag, New York Berlin Heidelberg 1991, §7.1.1. This shows that the multiplication of quaternions is in general not commutative. In particular, among some other consequences, the binomial formula is no longer valid for quaternions.Modifier and Type | Field and Description |
---|---|
static double |
ACCURACY
Accuracy up to which equality of double values are computed in
methods of this class.
|
static Quaternion |
I
Constant i ∈ ℍ.
|
static Quaternion |
J
Constant j ∈ ℍ.
|
static Quaternion |
K
Constant k ∈ ℍ.
|
static Quaternion |
ONE
Constant 1 ∈ ℍ.
|
static Quaternion |
ZERO
Constant 0 ∈ ℍ.
|
Constructor and Description |
---|
Quaternion(Complex z)
Creates a quaternion
x
= Re z + (Im z)∙i + 0∙j + 0∙k
from a complex number x0 + x1 i.
|
Quaternion(double x0)
Creates a quaternion
x
= x0 + 0∙i + 0∙j + 0∙k,
from a real number x0.
|
Quaternion(double x0,
double x1,
double x2,
double x3)
Creates a quaternion
x
= x0
+ x1 i + x2 j + x3 k
|
Modifier and Type | Method and Description |
---|---|
double |
abs()
Returns the absolute value
|x| of x ∈ ℍ
of this quaternion x.
|
Quaternion |
add(Quaternion y)
Returns the sum of this number and the quaternion z.
|
byte |
byteValue()
Returns the byte value of the real part of this quaternion (by casting to type byte).
|
Quaternion |
conjugate()
Returns the conjugate of this number.
|
Quaternion |
divide(double y)
Divides this quaternion by a real number y.
|
Quaternion |
divideFromLeft(Quaternion y)
Divides this quaternion by a quaternion y from the left.
|
Quaternion |
divideFromRight(Quaternion y)
Divides this quaternion by a quaternion y from the right.
|
double |
doubleValue()
Returns the value of the real part of this quaternion.
|
boolean |
equals(Object obj)
Compares this object against the specified object.
|
static boolean |
equals(Quaternion a,
Quaternion b,
double accuracy)
Compares the two quaternions up to the specified accuracy.
|
float |
floatValue()
Returns the float value of the real part of this quaternion (by casting to type float).
|
int |
hashCode()
Returns the hash code for this
Quaternion number. |
int |
intValue()
Returns the integer value of the real part of this quaternion (by casting to type int).
|
Quaternion |
inverse()
Returns the multiplicative inverse, or reciprocal, of this number.
|
long |
longValue()
Returns the long value of the real part of this quaternion (by casting to type long).
|
Quaternion |
minus(Quaternion y)
Subtracts y from this quaternion.
|
Quaternion |
multiply(double y)
The product of a real number y with this quaternion.
|
Quaternion |
multiply(Quaternion y)
Returns the product of this quaternion and the quaternion y.
|
Quaternion |
plus(Quaternion y)
Returns the sum of this number and the quaternion y.
|
Quaternion |
reciprocal()
Returns the reciprocal of this number.
|
short |
shortValue()
Returns the short value of the real part of this quaternion (by casting to type short).
|
Quaternion |
subtract(Quaternion y)
Subtracts y from this quaternion.
|
String |
toString()
Returns a string representation of this quaternion in a "readable" standard format.
|
String |
toString(DecimalFormat digit)
Returns a string representation of this quaternion in the specified
"readable" decimal format.
|
public static final double ACCURACY
toString()
.public static final Quaternion ZERO
public static final Quaternion ONE
public static final Quaternion I
public static final Quaternion J
public static final Quaternion K
public Quaternion(double x0, double x1, double x2, double x3)
x0
- the real part of the quaternionx1
- the i-part of the quaternionx2
- the j-part of the quaternionx3
- the k-part of the quaternionpublic Quaternion(Complex z)
z
- the complex number from which the quaternion is createdpublic Quaternion(double x0)
x0
- the real number from which the quaternion is createdpublic double abs()
this
|public Quaternion add(Quaternion y)
x + y = (x0 + y0) + (x1 + y1) i + (x2 + y2) j + (x3 + y3) k
y
- the addendthis
+ yplus(Quaternion)
public Quaternion conjugate()
x* = x0 - x1 i - x2 j - x3 k
this
*public Quaternion divide(double y)
x/y = x0/y + (x1/y) i + (x2/y) j + (x3/y) k.
If |y| = 0, y-1 =Double.NaN
.y
- divisorthis
/ypublic Quaternion divideFromLeft(Quaternion y)
y-1x = y*x / |y|2,
where y* denotes the conjugate of y, and |y| its absolute value. If |y| = 0, y-1 =Double.NaN
.y
- divisorthis
/ydivide(double)
,
divideFromRight(Quaternion)
,
abs()
,
inverse()
public Quaternion divideFromRight(Quaternion y)
xy-1 = xy* / |y|2,
where y* denotes the conjugate of y, and |y| its absolute value. If |y| = 0, y-1 =Double.NaN
.y
- divisorthis
/ydivide(double)
,
divideFromLeft(Quaternion)
,
abs()
,
inverse()
public Quaternion inverse()
x-1 = x* / |x|2,
where x* denotes the conjugate of x, and |x| its absolute value. If |this
| = 0, this
-1 =
Double.NaN
.this
-1reciprocal()
,
abs()
,
conjugate()
public Quaternion minus(Quaternion y)
x - y = (x0 - y0) + (x1 - y1) i + (x2 - y2) j + (x3 - y3) k
y
- a quaternionthis
- ysubtract(Quaternion)
public Quaternion multiply(double y)
xy = yx = yx0 + yx1 i + yx2 j + yx3 k
For a real factor, the quaternion multiplication therefore is commutative.y
- a real numberthis
∙y = y∙this
multiply(Quaternion)
public Quaternion multiply(Quaternion y)
x∙y = (x0y0 - x1y1 - x2y2 - x3y3) + (x0y1 + x1y0 + x2y3 - x3y2) i + (x0y2 - x1y3 + x2y0 + x3y1) j + (x0y3 + x1y2 - x2y1 + x3y0) k
Note that multiplication of quaternions is not commutative, i.e. that in general xy ≠ yx.y
- a quaternionthis
∙ymultiply(double)
public Quaternion plus(Quaternion y)
x + y = (x0 + y0) + (x1 + y1) i + (x2 + y2) j + (x3 + y3) k
y
- the addendthis
+ yadd(Quaternion)
public Quaternion reciprocal()
this
-1inverse()
public Quaternion subtract(Quaternion y)
x - y = (x0 - y0) + (x1 - y1) i + (x2 - y2) j + (x3 - y3) k
y
- a quaternionthis
- zminus(Quaternion)
public String toString()
toString
in class Object
toString(java.text.DecimalFormat)
public String toString(DecimalFormat digit)
digit
- the decimal format in which z is to be displayedtoString()
public int intValue()
public long longValue()
public float floatValue()
floatValue
in class Number
public double doubleValue()
doubleValue
in class Number
public byte byteValue()
public short shortValue()
shortValue
in class Number
public boolean equals(Object obj)
true
if and only if the argument is not
null
and is a
Quaternion
object whose real and imaginary parts are
double
s which have the same values as the
real and imaginary parts of this object, according to
Double.equals(Object)
.equals
in class Object
obj
- the object to compare withtrue
if the objects are the same; false
otherwiseDouble.equals(Object)
public static boolean equals(Quaternion a, Quaternion b, double accuracy)
true
if and only the absolute values of the
differences between the two real parts and the two imaginary parts, respectively,
are less than then the specified accuracy.a
- the first quaternion to compare withb
- the second quaternion to compare withaccuracy
- the accuracy of the comparisontrue
if the real and imaginary parts, respectively,
of the two numbers differ from each other by
at most accuracy
; false
otherwiseequals(Object)