From bebb1abb2f22b88a84a3c76b6258a24932715680 Mon Sep 17 00:00:00 2001 From: Magnus Eik <“mageik@stud.ntnu.noâ€> Date: Thu, 22 Feb 2024 15:23:02 +0100 Subject: [PATCH] Create abstract class Transform2D and its subclasses AffineTransform2D and JuliaTransform These classes perform the transformations needed to produce fractals. --- .idea/vcs.xml | 6 +++ pom.xml | 11 +++-- .../transformations/AffineTransform2D.java | 41 ++++++++++++++++ .../transformations/JuliaTransform.java | 47 +++++++++++++++++++ .../transformations/Transform2D.java | 15 ++++++ 5 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 src/main/java/edu/ntnu/stud/chaosgame/transformations/AffineTransform2D.java create mode 100644 src/main/java/edu/ntnu/stud/chaosgame/transformations/JuliaTransform.java create mode 100644 src/main/java/edu/ntnu/stud/chaosgame/transformations/Transform2D.java diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 35eb1dd..7ddfc9e 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,5 +1,11 @@ <?xml version="1.0" encoding="UTF-8"?> <project version="4"> + <component name="CommitMessageInspectionProfile"> + <profile version="1.0"> + <inspection_tool class="CommitFormat" enabled="true" level="WARNING" enabled_by_default="true" /> + <inspection_tool class="CommitNamingConvention" enabled="true" level="WARNING" enabled_by_default="true" /> + </profile> + </component> <component name="VcsDirectoryMappings"> <mapping directory="" vcs="Git" /> </component> diff --git a/pom.xml b/pom.xml index 0e7075c..e056f0e 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.example</groupId> @@ -26,7 +26,7 @@ <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-controls</artifactId> - <version> 21.0.1</version> + <version> 21.0.1</version> <scope>main</scope> </dependency> </dependencies> @@ -47,9 +47,12 @@ </plugin> <plugin> - <groupId>org.apache.maven.plugins</groupId> + <groupId>org.openjfx</groupId> <artifactId>javafx-maven-plugin</artifactId> <version>0.0.8</version> + <configuration> + <mainClass>edu.ntnu.stud.chaosgame.Main</mainClass> + </configuration> </plugin> <plugin> diff --git a/src/main/java/edu/ntnu/stud/chaosgame/transformations/AffineTransform2D.java b/src/main/java/edu/ntnu/stud/chaosgame/transformations/AffineTransform2D.java new file mode 100644 index 0000000..2c07e71 --- /dev/null +++ b/src/main/java/edu/ntnu/stud/chaosgame/transformations/AffineTransform2D.java @@ -0,0 +1,41 @@ +package edu.ntnu.stud.chaosgame.transformations; + +import edu.ntnu.stud.chaosgame.model.Matrix2x2; +import edu.ntnu.stud.chaosgame.model.Vector2D; + +/** + * Represents affine transformations in a 2D-plane by extending the abstract + * class Transform2D {@link Transform2D}. + */ +public class AffineTransform2D extends Transform2D { + + + /** + * The matrix{@link Matrix2x2} which performs the matrix-multiplication part of the affine transformation. + */ + Matrix2x2 matrix; + /** + * The vector{@link Vector2D} which is added as part of the affine transformation. + */ + Vector2D vector; + + /** + * Create a type of affine transformation. + * @param inputMatrix A matrix {@link Matrix2x2} which defines the matrix-multiplication part of the affine transformation. + * @param inputVector A vector {@link Vector2D} which defines the vector-addition part of the affine transformation. + */ + public AffineTransform2D(Matrix2x2 inputMatrix, Vector2D inputVector){ + this.matrix = inputMatrix; + this.vector = inputVector; + } + + /** + * Multiplies the matrix {@link Matrix2x2} matrix by the vector {@link Vector2D} vector and adds the vector {@link Vector2D} point. + * @param point The vector {@link Vector2D} which transformations are performed on. + * @return A new vector {@link Vector2D} which represents a point on a plane. The point represents a new step in the creation of fractal. + */ + public Vector2D transform(Vector2D point){ + + return matrix.multiply(point).add(vector); + } +} diff --git a/src/main/java/edu/ntnu/stud/chaosgame/transformations/JuliaTransform.java b/src/main/java/edu/ntnu/stud/chaosgame/transformations/JuliaTransform.java new file mode 100644 index 0000000..9b0e1f4 --- /dev/null +++ b/src/main/java/edu/ntnu/stud/chaosgame/transformations/JuliaTransform.java @@ -0,0 +1,47 @@ +package edu.ntnu.stud.chaosgame.transformations; + +import edu.ntnu.stud.chaosgame.model.Complex; +import edu.ntnu.stud.chaosgame.model.Vector2D; + +public class JuliaTransform extends Transform2D { + + /** + * The complex number represented through Complex {@link Complex} which + * is added or subtracted in the Julia transformations. + */ + private Complex c1; + /** + * The sign used to determine if the Julia transformations adds or subtracts {@link Complex} c1. + */ + int sign; + + /** + * Constructs a JuliaTransform object defined by the input. + * @param point The complex number {@link Complex} which is added or subtracted in the transformation. + * @param sign An integer which determines if c1 is added or subtracted in the transformation. + */ + public JuliaTransform(Complex point,int sign) { + this.c1 = point; + this.sign = sign; + } + + + /** + * Performs a Julia-transformation on a point defined by the vector point. + * The transformation will add or subtract c1 relative to point. + * This depends on the sign of the integer sign. + * Then the method performs the sqrt method from Complex {@link Complex}. + * @param point The vector {@link Vector2D} which transformations are performed on. + * @return The transformed point, represented by a vector {@link Vector2D} + */ + public Vector2D transform(Vector2D point){ + Vector2D temp1 = new Vector2D(); + if (sign > 0){ + temp1 = point.add(c1);} + else if (sign < 0){ + temp1 = point.subtract(c1); + } + return new Complex(temp1.getX0(), temp1.getX1()).sqrt(); + } + +} diff --git a/src/main/java/edu/ntnu/stud/chaosgame/transformations/Transform2D.java b/src/main/java/edu/ntnu/stud/chaosgame/transformations/Transform2D.java new file mode 100644 index 0000000..3a0537a --- /dev/null +++ b/src/main/java/edu/ntnu/stud/chaosgame/transformations/Transform2D.java @@ -0,0 +1,15 @@ +package edu.ntnu.stud.chaosgame.transformations; + +import edu.ntnu.stud.chaosgame.model.Vector2D; + +/** + * Abstract class representing transformations in a 2D-plane. + */ +public abstract class Transform2D { + /** + * Abstract method defining transformation in a 2D-plane. + * @param point The vector {@link Vector2D} which transformations are performed on. + * @return + */ + public abstract Vector2D transform(Vector2D point); +} -- GitLab