1 package nl.tudelft.simulation.language.d3;
2
3
4
5
6
7
8
9
10
11
12
13
14 public class SphericalPoint
15 {
16
17 private double radius = 0.0;
18
19
20 private double theta = 0.0;
21
22
23 private double phi = 0.0;
24
25
26
27
28
29
30
31 public SphericalPoint(final double radius, final double theta, final double phi)
32 {
33 super();
34 this.phi = phi;
35 this.radius = radius;
36 this.theta = theta;
37 }
38
39
40
41
42 public double getPhi()
43 {
44 return this.phi;
45 }
46
47
48
49
50 public double getRadius()
51 {
52 return this.radius;
53 }
54
55
56
57
58 public double getTheta()
59 {
60 return this.theta;
61 }
62
63
64
65
66
67 public CartesianPoint toCartesianPoint()
68 {
69 return SphericalPoint.toCartesianPoint(this);
70 }
71
72
73
74
75
76
77 public static CartesianPoint toCartesianPoint(final SphericalPoint point)
78 {
79 double x = point.radius * Math.sin(point.phi) * Math.cos(point.theta);
80 double y = point.radius * Math.sin(point.phi) * Math.sin(point.theta);
81 double z = point.radius * Math.cos(point.phi);
82 return new CartesianPoint(x, y, z);
83 }
84
85 @Override
86 public int hashCode()
87 {
88 final int prime = 31;
89 int result = 1;
90 long temp;
91 temp = Double.doubleToLongBits(this.phi);
92 result = prime * result + (int) (temp ^ (temp >>> 32));
93 temp = Double.doubleToLongBits(this.radius);
94 result = prime * result + (int) (temp ^ (temp >>> 32));
95 temp = Double.doubleToLongBits(this.theta);
96 result = prime * result + (int) (temp ^ (temp >>> 32));
97 return result;
98 }
99
100 @Override
101 @SuppressWarnings({"checkstyle:designforextension", "checkstyle:needbraces"})
102 public boolean equals(final Object obj)
103 {
104 if (this == obj)
105 return true;
106 if (obj == null)
107 return false;
108 if (getClass() != obj.getClass())
109 return false;
110 SphericalPoint other = (SphericalPoint) obj;
111 if (Double.doubleToLongBits(this.phi) != Double.doubleToLongBits(other.phi))
112 return false;
113 if (Double.doubleToLongBits(this.radius) != Double.doubleToLongBits(other.radius))
114 return false;
115 if (Double.doubleToLongBits(this.theta) != Double.doubleToLongBits(other.theta))
116 return false;
117 return true;
118 }
119
120 @Override
121 public String toString()
122 {
123 return "SphericalPoint [radius=" + this.radius + ", phi=" + this.phi + ", theta=" + this.theta + "]";
124 }
125
126 }