Skip to content
Snippets Groups Projects
Commit 31c3e357 authored by Edvard Granheim Harbo's avatar Edvard Granheim Harbo
Browse files

Fixed the JuliaTransformation bug

parent 5286011a
Branches
No related tags found
2 merge requests!54Final release,!18Julia transformation
...@@ -48,11 +48,18 @@ public class Complex extends Vector2D { ...@@ -48,11 +48,18 @@ public class Complex extends Vector2D {
*/ */
public Complex sqrt() { public Complex sqrt() {
double r = Math.sqrt(Math.pow(getX0(), 2) + Math.pow(getX1(), 2)); double r = Math.sqrt(Math.pow(getX0(), 2) + Math.pow(getX1(), 2));
double theta = Math.atan2(getX1(), getX0()); double theta = Math.atan2(getX1(), getX0()) / 2.0;
return new Complex(Math.sqrt(r) * Math.cos(theta / 2), Math.sqrt(r) * Math.sin(theta / 2)); double sqrtMag = Math.sqrt(r);
double realPart = sqrtMag * Math.cos(theta);
double imaginaryPart = sqrtMag * Math.sin(theta);
return new Complex(realPart, imaginaryPart);
} }
public double magnitudeSquared() { public double magnitudeSquared() {
return getX0() * getX0() + getX1() * getX1(); return getX0() * getX0() + getX1() * getX1();
} }
public String toString() {
return "(" + getX0() + " + " + getX1() + "i)";
}
} }
\ No newline at end of file
...@@ -53,7 +53,6 @@ public class JuliaTransform implements Transform2D { ...@@ -53,7 +53,6 @@ public class JuliaTransform implements Transform2D {
if (sign == -1) { if (sign == -1) {
subtracted = new Complex(-subtracted.getX0(), -subtracted.getX1()); subtracted = new Complex(-subtracted.getX0(), -subtracted.getX1());
} }
return subtracted; return subtracted;
} }
} }
......
...@@ -80,8 +80,12 @@ public class ChaosCanvas{ ...@@ -80,8 +80,12 @@ public class ChaosCanvas{
int x = (int) indices.getX0(); int x = (int) indices.getX0();
int y = (int) indices.getX1(); int y = (int) indices.getX1();
if (x >= 0 && x < width && y >= 0 && y < height) { if (x >= 0 && x < width && y >= 0 && y < height) {
if (canvas[x][y] != 1) { // Check if the pixel is not already set
canvas[x][y] = 1; canvas[x][y] = 1;
} }
} else {
System.out.println("Indices out of bounds");
}
} }
/** /**
* Gets the canvas array. * Gets the canvas array.
......
...@@ -55,13 +55,4 @@ public class ChaosGame { ...@@ -55,13 +55,4 @@ public class ChaosGame {
ChaosGameDescription description = new ChaosGameDescription(transforms, new Vector2D(0, 0), new Vector2D(1, 1)); ChaosGameDescription description = new ChaosGameDescription(transforms, new Vector2D(0, 0), new Vector2D(1, 1));
return description; return description;
} }
public static ChaosGameDescription createJuliaChaosGameDescription() {
List<Transform2D> transforms = new ArrayList<>();
Complex julaPoint = new Complex(-0.74543, 0.11301);
int sign = -1;
transforms.add(new JuliaTransform(julaPoint, sign));
ChaosGameDescription description = new ChaosGameDescription(transforms, new Vector2D(-1.6, -1), new Vector2D(1.6, 1));
return description;
}
} }
\ No newline at end of file
...@@ -32,7 +32,9 @@ public class ChaosGameFileHandler { ...@@ -32,7 +32,9 @@ public class ChaosGameFileHandler {
if (transformType.equals("Affine2D")) { if (transformType.equals("Affine2D")) {
transforms.add(parseAffineTransform2D(line)); transforms.add(parseAffineTransform2D(line));
} else if (transformType.equals("Julia")) { } else if (transformType.equals("Julia")) {
transforms.add(parseJuliaTransform(line)); JuliaTransform transformation = parseJuliaTransform(line);
transforms.add(transformation);
transforms.add(new JuliaTransform(transformation.getPoint(), -transformation.getSign()));
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment