1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.language.d3;
11
12 /***
13 * A sphericalpoint as defined in <a
14 * href="http://mathworld.wolfram.com/SphericalCoordinates.html">http://mathworld.wolfram.com/SphericalCoordinates.html
15 * </a>.
16 * <p>
17 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
18 * University of Technology </a>, the Netherlands. <br>
19 * See for project information <a
20 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
21 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
22 * License (GPL) </a>, no warranty <br>
23 *
24 * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
25 * Jacobs </a>
26 * @version 1.2 Aug 4, 2004
27 * @since 1.4
28 */
29 public class SphericalPoint
30 {
31 /*** radius */
32 private double radius = 0.0;
33
34 /*** phi */
35 private double phi = 0.0;
36
37 /*** theta */
38 private double theta = 0.0;
39
40 /***
41 * constructs a new SphericalPoint.
42 *
43 * @param phi phi
44 * @param radius radius
45 * @param theta theta
46 */
47 public SphericalPoint(final double radius, final double phi,
48 final double theta)
49 {
50 super();
51 this.phi = phi;
52 this.radius = radius;
53 this.theta = theta;
54 }
55
56 /***
57 * @return phi
58 */
59 public double getPhi()
60 {
61 return this.phi;
62 }
63
64 /***
65 * @return radius
66 */
67 public double getRadius()
68 {
69 return this.radius;
70 }
71
72 /***
73 * @return theta
74 */
75 public double getTheta()
76 {
77 return this.theta;
78 }
79
80 /***
81 * converts a sphericalpoint to a cartesian point
82 *
83 * @return the cartesian point
84 */
85 public CartesianPoint toCartesianPoint()
86 {
87 return SphericalPoint.toCartesianPoint(this);
88 }
89
90 /***
91 * converts a sphericalpoint to a cartesian point
92 *
93 * @param point the sphericalpoint
94 * @return the cartesian point
95 */
96 public static CartesianPoint toCartesianPoint(final SphericalPoint point)
97 {
98 double x = point.radius * Math.sin(point.phi) * Math.cos(point.theta);
99 double y = point.radius * Math.sin(point.phi) * Math.sin(point.theta);
100 double z = point.radius * Math.cos(point.phi);
101 return new CartesianPoint(x, y, z);
102 }
103 }