@@ -12,7 +12,7 @@ import io.github.hexagonnico.vecmatlib.vector.{Vec3d, Vec3f}
1212 * @param y The second component of the vector part (imaginary 'j' axis)
1313 * @param z The third component of the vector part (imaginary 'k' axis)
1414 */
15- case class QuaternionF (w : Float , x : Float , y : Float , z : Float ) extends Quaternion [QuaternionF ] with Float4 {
15+ case class QuaternionF (w : Float , x : Float , y : Float , z : Float ) extends Quaternion [QuaternionF , Vec3f ] with Float4 {
1616
1717 /**
1818 * Constructs a quaternion from the given scalar part and the given vector part
@@ -208,35 +208,35 @@ case class QuaternionF(w: Float, x: Float, y: Float, z: Float) extends Quaternio
208208 override def normalized : QuaternionF = this / this .length.toFloat
209209
210210 /**
211- * Returns the multiplicative inverse (or the reciprocal) of this quaternion.
211+ * Returns the multiplicative inverse of this quaternion.
212212 *
213213 * The same quaternion can be obtained with `1.0 / q`.
214214 *
215- * @return The reciprocal of this quaternion
215+ * @return The inverse of this quaternion
216216 */
217- override def reciprocal : QuaternionF = this .conjugate / this .lengthSquared
217+ override def inverse : QuaternionF = this .conjugate / this .lengthSquared
218218
219219 /**
220- * Returns the product of this quaternion by the [[reciprocal ]] of the quaternion `w + xi + yj + zk`.
220+ * Returns the product of this quaternion by the [[inverse ]] of the quaternion `w + xi + yj + zk`.
221221 *
222222 * @param w The real/scalar part of the second operand of the division
223223 * @param x The first component of the vector part of the second operand of the division
224224 * @param y The second component of the vector part of the second operand of the division
225225 * @param z The third component of the vector part of the second operand of the division
226- * @return The product of this quaternion by the reciprocal of the quaternion `w + xi + yj + zk`
226+ * @return The product of this quaternion by the inverse of the quaternion `w + xi + yj + zk`
227227 */
228228 def / (w : Float , x : Float , y : Float , z : Float ): QuaternionF = this / QuaternionF (w, x, y, z)
229229
230230 /**
231- * Returns the product of this quaternion by the [[reciprocal ]] of the quaternion `w + xi + yj + zk`.
231+ * Returns the product of this quaternion by the [[inverse ]] of the quaternion `w + xi + yj + zk`.
232232 *
233233 * This method can be used in place of the '/' operator for better interoperability with Java.
234234 *
235235 * @param w The real/scalar part of the second operand of the division
236236 * @param x The first component of the vector part of the second operand of the division
237237 * @param y The second component of the vector part of the second operand of the division
238238 * @param z The third component of the vector part of the second operand of the division
239- * @return The product of this quaternion by the reciprocal of the quaternion `w + xi + yj + zk`
239+ * @return The product of this quaternion by the inverse of the quaternion `w + xi + yj + zk`
240240 */
241241 def divide (w : Float , x : Float , y : Float , z : Float ): QuaternionF = this / (w, x, y, z)
242242
@@ -245,22 +245,14 @@ case class QuaternionF(w: Float, x: Float, y: Float, z: Float) extends Quaternio
245245 *
246246 * @return The exponential of this quaternion
247247 */
248- override def exp : QuaternionF = {
249- val v = Vec3d (this .x, this .y, this .z)
250- val length = v.length
251- (QuaternionD (math.cos(length), v / v.length * math.sin(length)) * math.exp(this .w)).toFloat
252- }
248+ override def exp : QuaternionF = this .toDouble.exp.toFloat
253249
254250 /**
255251 * Returns the logarithm of this quaternion.
256252 *
257253 * @return The logarithm of this quaternion
258254 */
259- override def log : QuaternionF = {
260- val v = Vec3d (this .x, this .y, this .z)
261- val length = this .length
262- QuaternionD (math.log(length), v.normalized * math.acos(this .w / length)).toFloat
263- }
255+ override def log : QuaternionF = this .toDouble.log.toFloat
264256
265257 /**
266258 * Returns this quaternion's rotation in the form of euler angles.
@@ -269,11 +261,7 @@ case class QuaternionF(w: Float, x: Float, y: Float, z: Float) extends Quaternio
269261 *
270262 * @return This quaternion's rotation in the form of euler angles
271263 */
272- override def euler : Vec3d = Vec3d (
273- math.atan2(2.0 * (w * x + y * z), 1.0 - 2.0 * (x * x + y * y)),
274- 2.0 * math.atan2(1.0 + 2.0 * (w * y - x * z), 1.0 - 2.0 * (w * y - x * z)) - math.Pi / 2.0 ,
275- math.atan2(2.0 * (w * z + x * y), 1.0 - 2.0 * (y * y + z * z))
276- )
264+ override def euler : Vec3f = this .toDouble.euler.toFloat
277265
278266 /**
279267 * Returns the angle of the rotation represented by this unit quaternion.
@@ -285,25 +273,21 @@ case class QuaternionF(w: Float, x: Float, y: Float, z: Float) extends Quaternio
285273 override def angle : Double = 2.0 * math.acos(this .w)
286274
287275 /**
288- * Returns the axis this quaternion is rotating around.
276+ * Returns the vector part of this quaternion.
277+ * The vector part of a quaternion `w + xi + yj + zk` is the vector `(x, y, z)`.
289278 *
290- * @return The axis this quaternion is rotating around
279+ * Normalize this vector to get the rotation axis of the quaternion.
280+ *
281+ * @return
291282 */
292- override def axis : Vec3d = {
293- val r = 1.0f / math.sqrt(1.0 - w * w)
294- Vec3d (x * r, y * r, z * r)
295- }
283+ override def vector : Vec3f = Vec3f (this .x, this .y, this .z)
296284
297285 /**
298286 * Returns that is, this quaternion divided by its norm or [[length ]].
299287 *
300288 * @return A unit quaternion
301289 */
302- override def slerp (to : QuaternionF , weight : Double ): QuaternionF = {
303- val omega = math.acos(this dot to)
304- val sinOmega = math.sin(omega)
305- (this .toDouble * (math.sin((1.0 - weight) * omega) / sinOmega) + to.toDouble * (math.sin(weight * omega) / sinOmega)).toFloat
306- }
290+ override def slerp (to : QuaternionF , weight : Double ): QuaternionF = this .toDouble.slerp(to.toDouble, weight).toFloat
307291
308292 /**
309293 * Converts this quaternion to a double quaternion.
@@ -475,11 +459,11 @@ object QuaternionF {
475459 def * (q : QuaternionF ): QuaternionF = q * l
476460
477461 /**
478- * Returns the product between this scalar and the [[Quaternion.reciprocal ]] of the given quaternion.
462+ * Returns the product between this scalar and the [[Quaternion.inverse ]] of the given quaternion.
479463 *
480464 * @param q The second operand of the division
481- * @return The product of this scalar by the reciprocal of the given quaternion
465+ * @return The product of this scalar by the inverse of the given quaternion
482466 */
483- def / (q : QuaternionF ): QuaternionF = l * q.reciprocal
467+ def / (q : QuaternionF ): QuaternionF = l * q.inverse
484468 }
485469}
0 commit comments