From e5f944298a4126e34317a869c2796018bf21542a Mon Sep 17 00:00:00 2001 From: emilruud <emilruud@ntnu.no> Date: Mon, 26 Feb 2024 13:11:13 +0100 Subject: [PATCH] Made JuliaTransform class --- .../edu/ntnu/idatt2003/JuliaTransform.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/main/java/edu/ntnu/idatt2003/JuliaTransform.java diff --git a/src/main/java/edu/ntnu/idatt2003/JuliaTransform.java b/src/main/java/edu/ntnu/idatt2003/JuliaTransform.java new file mode 100644 index 0000000..1491efb --- /dev/null +++ b/src/main/java/edu/ntnu/idatt2003/JuliaTransform.java @@ -0,0 +1,41 @@ +package edu.ntnu.idatt2003; + +import java.util.Objects; +import java.util.concurrent.CompletionException; + +public class JuliaTransform implements Transform2D { + private final Complex point; + private final int sign; + + /** + * Constructs a JuliaTransform object with the specified complex constant 'point' + * and the chosen sign represented by the integer 'sign'. + * + * @param point The complex constant representing 'c' in the transformation formula. + * @param sign The sign of the transformation, should be +1 or -1. + * @throws IllegalArgumentException If the sign is neither +1 nor -1. + */ + public JuliaTransform(Complex point, int sign) { + this.point = point; + + if (sign != 1 && sign != -1) { + throw new IllegalArgumentException("Sign must be 1 or -1"); + } + this.sign = sign; + } + + /** + * Transforms a complex vector 'z' according to the Julia transformation formula. + * Computes ±sqrt(z - c) based on the chosen sign. + * + * @param z The complex vector to be transformed. + * @return The transformed complex vector. + */ + @Override + public Vector2D transform(Vector2D z) { + Vector2D result = (z.subtract(point)); + Complex complexResult = new Complex(result.getX0(), result.getX1()); + complexResult = complexResult.sqrt(); + return new Vector2D(complexResult.getX0()*sign, complexResult.getX1()*sign); + } +} -- GitLab