Don't know how to create my hybrid DualQuaternion

This commit is contained in:
F. Y. H. 2023-05-19 02:55:12 +02:00
parent 4dcfa47e31
commit 877dad46c6
Signed by: Alnotz
GPG key ID: B808CA1113935C00
2 changed files with 43 additions and 0 deletions

View file

@ -0,0 +1,5 @@
package fr.alnotz;
public interface IsDualQuaternion {
/*…*/
}

View file

@ -17,6 +17,44 @@ public class Quaternion implements IsQuaternion{
this.j = j; this.j = j;
this.k = k; this.k = k;
} }
public static Quaternion plus(IsQuaternion quaternion0, IsQuaternion quaternion1){
return new Quaternion(quaternion0.getS() + quaternion1.getS(),
quaternion0.getI() + quaternion1.getI(),
quaternion0.getJ() + quaternion1.getJ(),
quaternion0.getK() + quaternion1.getK());
}
public static Quaternion times(IsQuaternion quaternion0, IsQuaternion quaternion1){
/*
* (a0 + b0i + c0j + d0k)(a1 + b1i + c1j + d1k)
* (a0a1 - b0b1 - c0c1 - d0d1) +
* (a0b1 + b0a1 + c0d1 - d0c1)i +
* (a0c1 - b0d1 + c0a1 + d0b1)j +
* (a0d1 + b0c1 - c0b1 + d0a1)k
*/
double newS = quaternion0.getS() * quaternion1.getS() -
quaternion1.getI() * quaternion1.getI() -
quaternion0.getJ() * quaternion1.getJ() -
quaternion0.getK() * quaternion1.getK();
double newI = quaternion0.getS() * quaternion1.getI() +
quaternion0.getI() * quaternion1.getK() +
quaternion0.getJ() * quaternion1.getS() -
quaternion0.getK() * quaternion1.getJ();
double newJ = quaternion0.getS() * quaternion1.getJ() -
quaternion0.getI() * quaternion1.getK() +
quaternion0.getJ() * quaternion1.getS() +
quaternion0.getK() * quaternion1.getI();
double newK = quaternion0.getS() * quaternion1.getK() +
quaternion0.getI() * quaternion1.getJ() -
quaternion0.getJ() * quaternion1.getI() +
quaternion0.getK() * quaternion1.getS();
return new Quaternion(newS, newI, newJ, newK);
}
public static Quaternion conjugate(IsQuaternion quaternion) {
return new Quaternion(quaternion.getS(),
-1 * quaternion.getI(),
-1 * quaternion.getJ(),
-1 * quaternion.getK());
}
@Override @Override
public double getS() { public double getS() {
return this.s; return this.s;