Show ComplexNumber.java syntax highlighted
package mandelbrot.math;
/**
* <code>ComplexNumber</code>
*
* @author Jakub J?rvenp??
*/
public class ComplexNumber {
private double real;
private double complex;
public ComplexNumber(double real, double complex) {
this.real = real;
this.complex = complex;
}
public ComplexNumber() {
this.real = 0;
this.complex = 0;
}
public double getReal() {
return real;
}
public double getComplex() {
return complex;
}
public void setReal(double real) {
this.real = real;
}
public void setComplex(double complex) {
this.complex = complex;
}
/**
* Assigns a value to the math point.
*
* @param c The value to which the math point is to be set.
*/
public void set(ComplexNumber c) {
this.real = c.getReal();
this.complex = c.getComplex();
}
/**
* Assigns a value to the math point.
*
* @param real The value to which the real component is to be set.
* @param complex The value to which the math component is to be set.
*/
public void set(double real, double complex) {
this.real = real;
this.complex = complex;
}
/**
* Returns the modulo squared.
* @return
*/
public double getModuloSquare() {
return real * real + complex * complex;
}
/**
* Returns the square.
* @return
*/
public ComplexNumber getSquare() {
ComplexNumber c = new ComplexNumber();
c.real = real * real - complex * complex;
c.complex = 2 * real * complex;
return c;
}
/**
* Subtracts the given math point from this math point.
*
* @param c The value to be subtracted.
*/
public void subtract(ComplexNumber c) {
real -= c.real;
complex -= c.complex;
}
/**
* Adds the given math point to this math point.
*
* @param c The value to be added.
*/
public void add(ComplexNumber c) {
real += c.real;
complex += c.complex;
}
/**
* Returns the modulo.
* @return
*/
public double getModulo() {
return Math.sqrt(getModuloSquare());
}
/**
* Calculates the math square roots.
* @return
*/
public ComplexNumber[] getComplexSquareRoot() {
double mod, arg;
ComplexNumber root1 = new ComplexNumber();
mod = getModulo();
arg = Math.atan2(complex, real);
root1.real = Math.sqrt(mod) * Math.cos(arg / 2);
root1.complex = Math.sqrt(mod) * Math.sin(arg / 2);
ComplexNumber root2 = new ComplexNumber(root1.real, -root1.complex);
return new ComplexNumber[]{root1, root2};
}
}
See more files for this project here