package nl.tudelft.simulation.language.d3; /** * A sphericalpoint as defined in * http://mathworld.wolfram.com/SphericalCoordinates.html . *
* Copyright (c) 2002-2018 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights * reserved. See for project information * https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can * be found at * https://simulation.tudelft.nl/dsol/3.0/license.html. *
* @author Peter Jacobs */ public class SphericalPoint { /** radius. */ private double radius = 0.0; /** phi. */ private double phi = 0.0; /** theta. */ private double theta = 0.0; /** * constructs a new SphericalPoint. * @param phi double; phi * @param radius double; radius * @param theta double; theta */ public SphericalPoint(final double radius, final double phi, final double theta) { super(); this.phi = phi; this.radius = radius; this.theta = theta; } /** * @return phi */ public final double getPhi() { return this.phi; } /** * @return radius */ public final double getRadius() { return this.radius; } /** * @return theta */ public final double getTheta() { return this.theta; } /** * converts a sphericalpoint to a cartesian point. * @return the cartesian point */ public final CartesianPoint toCartesianPoint() { return SphericalPoint.toCartesianPoint(this); } /** * converts a sphericalpoint to a cartesian point. * @param point SphericalPoint; the sphericalpoint * @return the cartesian point */ public static CartesianPoint toCartesianPoint(final SphericalPoint point) { double x = point.radius * Math.sin(point.phi) * Math.cos(point.theta); double y = point.radius * Math.sin(point.phi) * Math.sin(point.theta); double z = point.radius * Math.cos(point.phi); return new CartesianPoint(x, y, z); } /** {@inheritDoc} */ @Override @SuppressWarnings("checkstyle:designforextension") public int hashCode() { final int prime = 31; int result = 1; long temp; temp = Double.doubleToLongBits(this.phi); result = prime * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.radius); result = prime * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.theta); result = prime * result + (int) (temp ^ (temp >>> 32)); return result; } /** {@inheritDoc} */ @Override @SuppressWarnings({"checkstyle:designforextension", "checkstyle:needbraces"}) public boolean equals(final Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; SphericalPoint other = (SphericalPoint) obj; if (Double.doubleToLongBits(this.phi) != Double.doubleToLongBits(other.phi)) return false; if (Double.doubleToLongBits(this.radius) != Double.doubleToLongBits(other.radius)) return false; if (Double.doubleToLongBits(this.theta) != Double.doubleToLongBits(other.theta)) return false; return true; } /** {@inheritDoc} */ @Override @SuppressWarnings("checkstyle:designforextension") public String toString() { return "SphericalPoint [radius=" + this.radius + ", phi=" + this.phi + ", theta=" + this.theta + "]"; } }