View Javadoc
1   package nl.tudelft.simulation.language.d3;
2   
3   /**
4    * A spherical point as defined in <a href="https://mathworld.wolfram.com/SphericalCoordinates.html">
5    * https://mathworld.wolfram.com/SphericalCoordinates.html </a>. Also according to ISO 31-11
6    * <p>
7    * Copyright (c) 2002-2025 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
8    * for project information <a href="https://simulation.tudelft.nl/dsol/manual/" target="_blank">DSOL Manual</a>. The DSOL
9    * project is distributed under a three-clause BSD-style license, which can be found at
10   * <a href="https://simulation.tudelft.nl/dsol/docs/latest/license.html" target="_blank">DSOL License</a>.
11   * </p>
12   * @author <a href="https://www.linkedin.com/in/peterhmjacobs">Peter Jacobs </a>
13   */
14  public class SphericalPoint
15  {
16      /** radius. */
17      private double radius = 0.0;
18  
19      /** theta. */
20      private double theta = 0.0;
21  
22      /** phi. */
23      private double phi = 0.0;
24  
25      /**
26       * constructs a new SphericalPoint.
27       * @param radius radius
28       * @param theta theta
29       * @param phi phi
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       * @return phi
41       */
42      public double getPhi()
43      {
44          return this.phi;
45      }
46  
47      /**
48       * @return radius
49       */
50      public double getRadius()
51      {
52          return this.radius;
53      }
54  
55      /**
56       * @return theta
57       */
58      public double getTheta()
59      {
60          return this.theta;
61      }
62  
63      /**
64       * converts a spherical point to a Cartesian point.
65       * @return the Cartesian point
66       */
67      public CartesianPoint toCartesianPoint()
68      {
69          return SphericalPoint.toCartesianPoint(this);
70      }
71  
72      /**
73       * converts a spherical point to a Cartesian point.
74       * @param point the spherical point
75       * @return the Cartesian point
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 }