-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComplexPolar.java
More file actions
38 lines (31 loc) · 903 Bytes
/
ComplexPolar.java
File metadata and controls
38 lines (31 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public class ComplexPolar {
private final double r;
private final double theta;
public ComplexPolar(double real, double imag) {
r = Math.sqrt(real*real + imag*imag);
theta = Math.atan2(imag, real);
}
public ComplexPolar plus(ComplexPolar b) {
double real = this.re() + b.re();
double imag = im() + b.im();
return new ComplexPolar(real, imag);
}
public ComplexPolar(double radius, double angle, boolean complex) {
r = radius;
theta = angle;
}
public ComplexPolar times(ComplexPolar b) {
double radius = r * b.r;
double angle = theta + b.theta;
return new ComplexPolar(radius, angle, true);
}
public double abs() {
return r;
}
public double re() {
return r * Math.cos(theta);
}
public double im() {
return r * Math.sin(theta);
}
}