Skip to content
Snippets Groups Projects
Commit eb7a19ab authored by Håvard Daleng's avatar Håvard Daleng
Browse files

Created Complex-class which inherits from Vector2D.

parent 63bb60b2
No related branches found
No related tags found
1 merge request!1Merge master and main
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));
}
}
...@@ -16,7 +16,12 @@ public class Vector2D { ...@@ -16,7 +16,12 @@ public class Vector2D {
private double x1; 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 x0 The x0 component of the vector.
* @param x1 The x1 component of the vector. * @param x1 The x1 component of the vector.
......
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