quaternion-java/fr/alnotz/Dual.java

68 lines
1.7 KiB
Java

package fr.alnotz;
public class Dual implements IsDual{
private double r;
private double d;
public Dual(){
this.r = 0;
this.d = 0;
}
public Dual(double r, double d){
this.r = r;
this.d = d;
}
public static Dual plus(IsDual dual0, IsDual dual1){
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
public double getR() {
return this.r;
}
@Override
public double getD() {
return this.d;
}
@Override
public void setR(double r) {
this.r = r;
}
@Override
public void setD(double d) {
this.d = d;
}
@Override
public Dual plus(IsDual dual) {
return new Dual(this.r + dual.getR(),
this.d + dual.getD());
}
@Override
public Dual times(IsDual dual) {
return new Dual(this.r * dual.getR(),
this.r * dual.getD() + this.d * dual.getR());
}
@Override
public Dual conjugate(){
return new Dual(this.r, this.d * -1);
}
@Override
public boolean equals(IsDual dual) {
return this.r == dual.getR() && this.d == dual.getD();
}
@Override
public String toString(){
return String.format("%+f %+fε\n", this.r, this.d);
}
}