From eb7a19ab431886498dc9cf11a15ec0af59e79a38 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?H=C3=A5vard=20Daleng?=
 <142524365+MrMarHVD@users.noreply.github.com>
Date: Wed, 14 Feb 2024 11:42:13 +0100
Subject: [PATCH] Created Complex-class which inherits from Vector2D.

---
 .../ntnu/stud/chaosgame/model/Complex.java    | 26 +++++++++++++++++++
 .../ntnu/stud/chaosgame/model/Vector2D.java   |  7 ++++-
 2 files changed, 32 insertions(+), 1 deletion(-)
 create mode 100644 src/main/java/edu/ntnu/stud/chaosgame/model/Complex.java

diff --git a/src/main/java/edu/ntnu/stud/chaosgame/model/Complex.java b/src/main/java/edu/ntnu/stud/chaosgame/model/Complex.java
new file mode 100644
index 0000000..fd9e506
--- /dev/null
+++ b/src/main/java/edu/ntnu/stud/chaosgame/model/Complex.java
@@ -0,0 +1,26 @@
+package edu.ntnu.stud.chaosgame.model;
+
+/**
+ * Class representing a complex number.
+ */
+public class Complex extends Vector2D{
+
+  /**
+   * Create a new complex number.
+   */
+  public Complex(double real, double imag) {
+    super(real, imag);
+  }
+
+  /**
+   * Get the square root of the complex number.
+   * 
+   * @return The square root of the complex number.
+   */
+  public Complex sqrt() {
+    double r = Math.sqrt(Math.sqrt(getX0() * getX0() + getX1() * getX1()));
+    double theta = Math.atan2(getX1(), getX0()) / 2;
+    return new Complex(r * Math.cos(theta), r * Math.sin(theta));
+  }
+
+}
diff --git a/src/main/java/edu/ntnu/stud/chaosgame/model/Vector2D.java b/src/main/java/edu/ntnu/stud/chaosgame/model/Vector2D.java
index 16e863c..2c0ad6c 100644
--- a/src/main/java/edu/ntnu/stud/chaosgame/model/Vector2D.java
+++ b/src/main/java/edu/ntnu/stud/chaosgame/model/Vector2D.java
@@ -16,7 +16,12 @@ public class Vector2D {
   private double x1;
 
   /**
-   * Create a new 2D vector.
+   * Create a new 2D vector; default constructor.
+   */
+  public Vector2D() {}
+
+  /**
+   * Create a new 2D vector; parameterized.
    *
    * @param x0 The x0 component of the vector.
    * @param x1 The x1 component of the vector.
-- 
GitLab