Skip to content

Commit 46ad654

Browse files
committed
Merge branch 'quaternions'
2 parents c282d59 + 55a0cab commit 46ad654

File tree

28 files changed

+2992
-1225
lines changed

28 files changed

+2992
-1225
lines changed

.editorconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[*.scala]
2+
indent_style = space
3+
indent_size = 2
4+
5+
[*.java]
6+
indent_style = space
7+
indent_size = 4
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
package io.github.hexagonnico.vecmatlib.quaternion
2+
3+
import io.github.hexagonnico.vecmatlib.vector.VecAbstract
4+
5+
/**
6+
* Abstract class with quaternion operations.
7+
*
8+
* @tparam Q The quaternion class extending this one
9+
*/
10+
abstract class Quaternion[Q <: Quaternion[Q, V], V <: VecAbstract[V]] {
11+
12+
/**
13+
* Returns the sum between this quaternion and the given one.
14+
*
15+
* @param q The quaternion to add
16+
* @return The sum of this quaternion and the given one
17+
*/
18+
def +(q: Q): Q
19+
20+
/**
21+
* Returns the sum between this quaternion and the given one.
22+
*
23+
* This method can be used in place of the '+' operator for better interoperability with Java.
24+
*
25+
* @param q The quaternion to add
26+
* @return The sum of this quaternion and the given one
27+
*/
28+
def plus(q: Q): Q = this + q
29+
30+
/**
31+
* Returns the additive inverse of this quaternion.
32+
*
33+
* @return The additive inverse of this quaternion
34+
*/
35+
def unary_-(): Q
36+
37+
/**
38+
* Returns the additive inverse of this quaternion.
39+
*
40+
* This method can be used in place of the unary '-' operator for better interoperability with Java.
41+
*
42+
* @return The additive inverse of this quaternion
43+
*/
44+
def negated: Q = -this
45+
46+
/**
47+
* Returns the subtraction between the given quaternion and this one.
48+
*
49+
* @param q The quaternion to subtract
50+
* @return The subtraction of the given quaternion from this one
51+
*/
52+
def -(q: Q): Q = this + (-q)
53+
54+
/**
55+
* Returns the subtraction between the given quaternion and this one.
56+
*
57+
* This method can be used in place of the '-' operator for better interoperability with Java.
58+
*
59+
* @param q The quaternion to subtract
60+
* @return The subtraction of the given quaternion from this one
61+
*/
62+
def minus(q: Q): Q = this - q
63+
64+
/**
65+
* Returns the product between this quaternion and the given one as defined by the Hamilton product.
66+
*
67+
* @param q The second operand of the multiplication
68+
* @return The product between this quaternion and the given one
69+
*/
70+
def *(q: Q): Q
71+
72+
/**
73+
* Returns the product between this quaternion and the given one as defined by the Hamilton product.
74+
*
75+
* This method can be used in place of the '*' operator for better interoperability with Java.
76+
*
77+
* @param q The second operand of the multiplication
78+
* @return The product between this quaternion and the given one
79+
*/
80+
def multiply(q: Q): Q = this * q
81+
82+
/**
83+
* Returns the conjugate of this quaternion.
84+
* The conjugate of a quaternion `w + xi + yj + zk` is the quaternion `w - xi - yj - zk`.
85+
*
86+
* @return The conjugate of this quaternion
87+
*/
88+
def conjugate: Q
89+
90+
/**
91+
* Returns the length (or norm) of this quaternion.
92+
*
93+
* @return The norm of this quaternion
94+
*/
95+
def length: Double
96+
97+
/**
98+
* Returns this quaternion as a unit quaternion.
99+
* That is, this quaternion divided by its norm or [[length]].
100+
*
101+
* @return This quaternion as a unit quaternion
102+
*/
103+
def normalized: Q
104+
105+
/**
106+
* Returns the multiplicative inverse of this quaternion.
107+
*
108+
* The same quaternion can be obtained with `1.0 / q`.
109+
*
110+
* @return The inverse of this quaternion
111+
*/
112+
def inverse: Q
113+
114+
/**
115+
* Returns the product of this quaternion by the [[inverse]] of the given one.
116+
*
117+
* @param q The second operand of the division
118+
* @return The product of this quaternion by the inverse of the given one
119+
*/
120+
def /(q: Q): Q = this * q.inverse
121+
122+
/**
123+
* Returns the product of this quaternion by the [[inverse]] of the given one.
124+
*
125+
* This method can be used in place of the '/' operator for better interoperability with Java.
126+
*
127+
* @param q The second operand of the division
128+
* @return The product of this quaternion by the inverse of the given one
129+
*/
130+
def divide(q: Q): Q = this / q
131+
132+
/**
133+
* Returns the exponential of this quaternion.
134+
*
135+
* @return The exponential of this quaternion
136+
*/
137+
def exp: Q
138+
139+
/**
140+
* Returns the logarithm of this quaternion.
141+
*
142+
* @return The logarithm of this quaternion
143+
*/
144+
def log: Q
145+
146+
/**
147+
* Returns this quaternion's rotation in the form of euler angles.
148+
*
149+
* The result is undefined if this quaternion is not [[normalized]].
150+
*
151+
* @return This quaternion's rotation in the form of euler angles
152+
*/
153+
def euler: V
154+
155+
/**
156+
* Returns the angle of the rotation represented by this unit quaternion.
157+
*
158+
* The result is undefined if this quaternion is not [[normalized]].
159+
*
160+
* @return The angle of the rotation represented by this unit quaternion
161+
*/
162+
def angle: Double
163+
164+
/**
165+
* Returns the vector part of this quaternion.
166+
* The vector part of a quaternion `w + xi + yj + zk` is the vector `(x, y, z)`.
167+
*
168+
* Normalize this vector to get the rotation axis of the quaternion.
169+
*
170+
* @return
171+
*/
172+
def vector: V
173+
174+
/**
175+
* Returns that is, this quaternion divided by its norm or [[length]].
176+
*
177+
* @return A unit quaternion
178+
*/
179+
def slerp(to: Q, weight: Double): Q
180+
}

0 commit comments

Comments
 (0)