Creating Quaternion class
This commit is contained in:
parent
5669350291
commit
7c934dc49e
5 changed files with 122 additions and 4 deletions
|
@ -3,5 +3,6 @@ package fr.alnotz;
|
|||
public class Application {
|
||||
public static void main(String[] args){
|
||||
System.out.println("Hi.");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,10 @@ 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;
|
||||
|
@ -10,6 +14,15 @@ public class Dual implements IsDual{
|
|||
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;
|
||||
|
@ -35,15 +48,21 @@ public class Dual implements IsDual{
|
|||
this.r += dual.getR();
|
||||
this.d += dual.getD();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void times(IsDual dual) {
|
||||
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
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,5 +7,7 @@ public interface IsDual {
|
|||
void setD(double d);
|
||||
void plus(IsDual dual);
|
||||
void times(IsDual dual);
|
||||
void conjugate();
|
||||
boolean equals(IsDual dual);
|
||||
String toString();
|
||||
}
|
||||
|
|
17
fr/alnotz/IsQuaternion.java
Normal file
17
fr/alnotz/IsQuaternion.java
Normal 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
79
fr/alnotz/Quaternion.java
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue