Skip to content
Snippets Groups Projects
Commit bebb1abb authored by Magnus Eik's avatar Magnus Eik
Browse files

Create abstract class Transform2D and its subclasses AffineTransform2D and JuliaTransform

These classes perform the transformations needed to produce fractals.
parent eb7a19ab
No related branches found
No related tags found
1 merge request!1Merge master and main
<?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>
......
<?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>
......
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);
}
}
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();
}
}
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);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment