-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge Dev into Master
- Loading branch information
Showing
53 changed files
with
2,210 additions
and
762 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ | |
out/ | ||
*.gif | ||
*.iml | ||
/target/ | ||
imgs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/com/tiggerbiggo/primaplay/calculation/ComplexNumber.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.tiggerbiggo.primaplay.calculation; | ||
|
||
public class ComplexNumber { | ||
|
||
//Stored complex number in the form real + bi | ||
double real, imaginary; | ||
|
||
public ComplexNumber(double real, double imaginary) { | ||
this.real = real; | ||
this.imaginary = imaginary; | ||
} | ||
|
||
public ComplexNumber(Vector2 in) { | ||
this(in.X(), in.Y()); | ||
} | ||
|
||
public ComplexNumber() { | ||
this(0, 0); | ||
} | ||
|
||
public Vector2 asVector() { | ||
return new Vector2(this); | ||
} | ||
|
||
public ComplexNumber add(ComplexNumber B) { | ||
return new ComplexNumber(real + B.real, imaginary + B.imaginary); | ||
} | ||
|
||
public ComplexNumber multiply(ComplexNumber B) { | ||
double a, b, c, d, r, i; | ||
|
||
a = real; | ||
b = imaginary; | ||
|
||
c = B.real; | ||
d = B.imaginary; | ||
|
||
r = (a * c) - (b * d); | ||
i = (a * d) + (b * c); | ||
|
||
return new ComplexNumber(r, i); | ||
} | ||
|
||
public ComplexNumber power(int powerOf) { | ||
ComplexNumber c = this.clone(); | ||
ComplexNumber c2 = this.clone(); | ||
for (int i = 0; i < powerOf; i++) { | ||
c2 = c.multiply(c2); | ||
} | ||
return this; | ||
} | ||
/* | ||
(real+bi)(c+di) | ||
ac + adi + bci + bdi^2 | ||
ac + adi + bci - bd | ||
simple = ac-bd | ||
complex = ad + bc | ||
* | ||
* */ | ||
|
||
public ComplexNumber clone() { | ||
return new ComplexNumber(real, imaginary); | ||
} | ||
} |
Oops, something went wrong.