Creating Quaternion class

This commit is contained in:
F. Y. H. 2023-05-19 00:57:23 +02:00
parent 5669350291
commit 7c934dc49e
Signed by: Alnotz
GPG key ID: B808CA1113935C00
5 changed files with 122 additions and 4 deletions

View file

@ -3,5 +3,6 @@ package fr.alnotz;
public class Application { public class Application {
public static void main(String[] args){ public static void main(String[] args){
System.out.println("Hi."); System.out.println("Hi.");
} }
} }

View file

@ -3,6 +3,10 @@ package fr.alnotz;
public class Dual implements IsDual{ public class Dual implements IsDual{
private double r; private double r;
private double d; private double d;
public Dual(){
this.r = 0;
this.d = 0;
}
public Dual(double r, double d){ public Dual(double r, double d){
this.r = r; this.r = r;
this.d = d; this.d = d;
@ -10,6 +14,15 @@ public class Dual implements IsDual{
public static Dual plus(IsDual dual0, IsDual dual1){ public static Dual plus(IsDual dual0, IsDual dual1){
return new Dual(dual0.getR() + dual1.getR(), dual0.getD() + dual1.getD()); return new Dual(dual0.getR() + dual1.getR(), dual0.getD() + dual1.getD());
} }
public static Dual times(IsDual dual0, IsDual dual1){
return new Dual(dual0.getR() * dual1.getR(), dual0.getR() * dual1.getD() + dual1.getR() * dual0.getD());
}
public static Dual conjugate(IsDual dual){
return new Dual(dual.getR(), -1 * dual.getD());
}
public static boolean equals(IsDual dual0, IsDual dual1){
return dual0.getR() == dual1.getR() && dual0.getD() == dual1.getD();
}
@Override @Override
public double getR() { public double getR() {
return this.r; return this.r;
@ -35,15 +48,21 @@ public class Dual implements IsDual{
this.r += dual.getR(); this.r += dual.getR();
this.d += dual.getD(); this.d += dual.getD();
} }
@Override @Override
public void times(IsDual dual) { public void times(IsDual dual) {
this.r *= dual.getR(); this.r *= dual.getR();
this.d = 2 * this.r * dual.getD(); this.d = this.r * dual.getD() + this.d * dual.getR();
}
@Override
public void conjugate(){
this.d *= -1;
} }
@Override @Override
public boolean equals(IsDual dual) { public boolean equals(IsDual dual) {
return this.r == dual.getR() && this.d == dual.getR(); return this.r == dual.getR() && this.d == dual.getD();
}
@Override
public String toString(){
return String.format("%+f %+fε\n", this.r, this.d);
} }
} }

View file

@ -7,5 +7,7 @@ public interface IsDual {
void setD(double d); void setD(double d);
void plus(IsDual dual); void plus(IsDual dual);
void times(IsDual dual); void times(IsDual dual);
void conjugate();
boolean equals(IsDual dual); boolean equals(IsDual dual);
String toString();
} }

View file

@ -0,0 +1,17 @@
package fr.alnotz;
public interface IsQuaternion {
double getS();
double getI();
double getJ();
double getK();
void setS();
void setI();
void setJ();
void setK();
void plus(IsQuaternion quaternion);
void times(IsQuaternion quaternion);
void conjugate();
boolean equals(IsQuaternion quaternion);
String toString();
}

79
fr/alnotz/Quaternion.java Normal file
View file

@ -0,0 +1,79 @@
package fr.alnotz;
public class Quaternion implements IsQuaternion{
private double s;
private double i;
private double j;
private double k;
public Quaternion(){
this.s = 0;
this.i = 0;
this.j = 0;
this.k = 0;
}
public Quaternion(double s, double i, double j, double k){
this.s = s;
this.i = i;
this.j = j;
this.k = k;
}
@Override
public double getS() {
return 0;
}
@Override
public double getI() {
return 0;
}
@Override
public double getJ() {
return 0;
}
@Override
public double getK() {
return 0;
}
@Override
public void setS() {
}
@Override
public void setI() {
}
@Override
public void setJ() {
}
@Override
public void setK() {
}
@Override
public void plus(IsQuaternion quaternion) {
}
@Override
public void times(IsQuaternion quaternion) {
}
@Override
public void conjugate() {
}
@Override
public boolean equals(IsQuaternion quaternion) {
return false;
}
}