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