Class Polar3D<Q extends javax.measure.quantity.Quantity>

  • Type Parameters:
    Q - The Quantity (unit type, such as Length or Volume) of this vector.
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<javax.measure.Measurable<Q>>, javax.measure.Measurable<Q>, javolution.lang.Immutable, javolution.lang.Realtime, javolution.lang.ValueType, javolution.xml.XMLSerializable, GroupAdditive<Vector<Parameter<Q>>>, Structure<Vector<Parameter<Q>>>, VectorSpace<Vector<Parameter<Q>>,​Parameter<Q>>, VectorSpaceNormed<Vector<Parameter<Q>>,​Parameter<Q>>

    public final class Polar3D<Q extends javax.measure.quantity.Quantity>
    extends Coordinate3D<Q>
    implements javolution.xml.XMLSerializable
    This class represents a 3 element vector of Parameter elements representing a geometrical polar coordinate with elements magnitude, azimuth angle and elevation angle where elevation is measured positive above the reference plane (similar to latitude).

    Modified by: Joseph A. Huwaldt

    Version:
    November 4, 2015
    Author:
    Joseph A. Huwaldt, Date: November 21, 2008
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int AZIMUTH
      Constant used to identify the azimuth angle of the vector.
      static int ELEVATION
      Constant used to identify the elevation angle of the vector.
      static int MAGNITUDE
      Constant used to identify the magnitude of in the vector.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Polar3D<Q> anglesTo​(javax.measure.unit.Unit<javax.measure.quantity.Angle> unit)
      Returns the equivalent to this vector but with the angles stated in the specified unit.
      <T extends javax.measure.quantity.Quantity>
      Polar3D<T>
      asType​(java.lang.Class<T> type)
      Casts this Polar3D to a parameterized unit of specified nature or throw a ClassCastException if the dimension of the specified quantity and this parameter's unit dimension do not match.
      Polar3D<Q> copy()
      Returns a copy of this vector allocated by the calling thread (possibly on the stack).
      Polar3D cross​(Vector that)
      Returns the cross product of two 3-dimensional vectors.
      Polar3D<?> divide​(Parameter<?> that)
      Returns the result of this vector divided by the specified divisor.
      boolean equals​(java.lang.Object obj)
      Compares this Polar3D against the specified object for strict equality (same values and same units).
      Polar3D<Q> fromVector3D​(Vector3D<Q> vector)
      Return the specified Vector3D object as a Polar3D instance.
      Parameter get​(int i)
      Returns the value of a Parameter from this vector.
      javax.measure.unit.Unit<javax.measure.quantity.Angle> getAnglesUnit()
      Returns the unit in which the angles in this vector are stated in.
      Parameter<javax.measure.quantity.Angle> getAzimuth()
      Returns the azimuth angle of this vector as a Parameter.
      Parameter<javax.measure.quantity.Angle> getElevation()
      Returns the elevation angle of this vector as a Parameter.
      Parameter<Q> getMagnitude()
      Returns the magnitude of this vector as a Parameter.
      double getMagnitudeValue()
      Returns the magnitude of this vector as a double, stated in this vector's unit.
      javax.measure.unit.Unit<Q> getUnit()
      Returns the unit in which the magnitude in this vector are stated in.
      int hashCode()
      Returns the hash code for this parameter.
      static void main​(java.lang.String[] args)
      Tests the methods in this class.
      Polar3D<Q> minus​(Parameter<Q> that)
      Subtracts the supplied Parameter from this vector's magnitude and returns the result.
      Polar3D<Q> minus​(Vector<Parameter<Q>> that)
      Returns the difference between this vector and the one specified.
      Parameter<Q> norm()
      Returns the Euclidian norm, magnitude, or length of this vector (square root of the dot product of this vector and itself).
      double normValue()
      Returns the norm, magnitude, or length value of this vector.
      Polar3D<Q> opposite()
      Returns the negation of this vector.
      Polar3D<Q> plus​(Parameter<Q> that)
      Returns the sum of this vector with the parameter specified.
      Polar3D<Q> plus​(Vector<Parameter<Q>> that)
      Returns the sum of this vector with the one specified.
      Polar3D<Q> times​(double k)
      Returns the product of this vector with the specified coefficient.
      Polar3D times​(Parameter k)
      Returns the product of this vector with the specified coefficient.
      Parameter times​(Vector that)
      Returns the dot product of this vector with the one specified.
      <R extends javax.measure.quantity.Quantity>
      Polar3D<R>
      to​(javax.measure.unit.Unit<R> unit)
      Returns the equivalent to this vector but with the magnitude stated in the specified unit.
      Polar3D<javax.measure.quantity.Dimensionless> toUnitVector()
      Returns this vector converted to a unit vector with a vector magnitude of 1.0.
      Vector3D<Q> toVector3D()
      Returns a Cartesian Vector3D representation of this vector.
      static <Q extends javax.measure.quantity.Quantity>
      Polar3D<Q>
      valueOf​(double magnitude, double azimuth, double elevation, javax.measure.unit.Unit<Q> magUnit, javax.measure.unit.Unit<javax.measure.quantity.Angle> angleUnit)
      Returns a Polar3D instance holding the specified double values stated in the specified units.
      static <Q extends javax.measure.quantity.Quantity>
      Polar3D<Q>
      valueOf​(Coordinate3D<Q> coordinate)
      Returns a Polar3D instance containing the polar coordinate representation of the specified coordinate.
      static <Q extends javax.measure.quantity.Quantity>
      Polar3D<Q>
      valueOf​(Coordinate3D<Q> coord, javax.measure.unit.Unit<javax.measure.quantity.Angle> angleUnit)
      Returns a Polar3D instance containing the polar coordinate representation of the specified coordinate.
      static <Q extends javax.measure.quantity.Quantity>
      Polar3D<Q>
      valueOf​(Parameter<Q> magnitude, Parameter<javax.measure.quantity.Angle> azimuth, Parameter<javax.measure.quantity.Angle> elevation)
      Returns a Polar3D instance holding the specified Parameter values.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface javolution.lang.Realtime

        toText
    • Method Detail

      • valueOf

        public static <Q extends javax.measure.quantity.Quantity> Polar3D<Q> valueOf​(double magnitude,
                                                                                     double azimuth,
                                                                                     double elevation,
                                                                                     javax.measure.unit.Unit<Q> magUnit,
                                                                                     javax.measure.unit.Unit<javax.measure.quantity.Angle> angleUnit)
        Returns a Polar3D instance holding the specified double values stated in the specified units.
        Type Parameters:
        Q - the Quantity (unit type, e.g. Length or Volume) of this vector.
        Parameters:
        magnitude - the magnitude (length) of the vector stated in the specified unit.
        azimuth - the vector azimuth angle stated in the specified angle unit.
        elevation - the vector elevation angle value stated in the specified angle unit.
        magUnit - the unit in which the magnitude is stated.
        angleUnit - the unit in which the azimuth and elevation angles are stated.
        Returns:
        the vector having the specified values.
      • valueOf

        public static <Q extends javax.measure.quantity.Quantity> Polar3D<Q> valueOf​(Parameter<Q> magnitude,
                                                                                     Parameter<javax.measure.quantity.Angle> azimuth,
                                                                                     Parameter<javax.measure.quantity.Angle> elevation)
        Returns a Polar3D instance holding the specified Parameter values. All the values are converted to the same units as the x value.
        Type Parameters:
        Q - the Quantity (unit type, e.g. Length or Volume) of this vector.
        Parameters:
        magnitude - the vector magnitude (length) value.
        azimuth - the vector azimuth angle value.
        elevation - the vector elevation angle value.
        Returns:
        the vector having the specified values in the units of magnitude.
      • valueOf

        public static <Q extends javax.measure.quantity.Quantity> Polar3D<Q> valueOf​(Coordinate3D<Q> coordinate)
        Returns a Polar3D instance containing the polar coordinate representation of the specified coordinate. The azimuth and elevation components of the resulting vector have units of radians.

        The polar representation of a Cartesian coordinate is given by:

                 magnitude = |V|
                 azimuth   = atan2(Y,X)
                 elevation = 90° - acos(Z/|V|) = latitude
         

        Type Parameters:
        Q - the Quantity (unit type, e.g. Length or Volume) of this vector.
        Parameters:
        coordinate - the input coordinate.
        Returns:
        the polar coordinate having the specified values.
      • valueOf

        public static <Q extends javax.measure.quantity.Quantity> Polar3D<Q> valueOf​(Coordinate3D<Q> coord,
                                                                                     javax.measure.unit.Unit<javax.measure.quantity.Angle> angleUnit)
        Returns a Polar3D instance containing the polar coordinate representation of the specified coordinate.

        The polar representation of a Cartesian coordinate is given by:

                 magnitude = |V|
                 azimuth   = atan2(Y,X)
                 elevation = atan2(-Z,sqrt(X^2+Y^2))
         

        Type Parameters:
        Q - the Quantity (unit type, e.g. Length or Volume) of this vector.
        Parameters:
        coord - the coordinate to convert.
        angleUnit - the unit to use for the azimuth and elevation components.
        Returns:
        the polar coordinate vector having the specified values.
      • fromVector3D

        public Polar3D<QfromVector3D​(Vector3D<Q> vector)
        Return the specified Vector3D object as a Polar3D instance.
        Specified by:
        fromVector3D in class AbstractParamVector<Q extends javax.measure.quantity.Quantity,​Coordinate3D<Q extends javax.measure.quantity.Quantity>>
        Parameters:
        vector - The Vector3D object to be converted to a Polar3D.
        Returns:
        A Polar3D instance that is equivalent to the supplied Vector3D object.
      • get

        public Parameter get​(int i)
        Returns the value of a Parameter from this vector. The dimensions are defined as: magnitude, azimuth angle, and elevation angle in that order.
        Specified by:
        get in class Vector<Parameter<Q extends javax.measure.quantity.Quantity>>
        Parameters:
        i - the dimension index (0=magnitude, 1=azimuth, 2=elevation).
        Returns:
        the value of the parameter at i.
        Throws:
        java.lang.IndexOutOfBoundsException - (i < 0) || (i > dimension()-1)
      • getMagnitudeValue

        public double getMagnitudeValue()
        Returns the magnitude of this vector as a double, stated in this vector's unit.
        Returns:
        the magnitude of this vector in this vector's units.
      • getAzimuth

        public Parameter<javax.measure.quantity.Angle> getAzimuth()
        Returns the azimuth angle of this vector as a Parameter.
        Returns:
        the azimuth angle of this vector.
      • getElevation

        public Parameter<javax.measure.quantity.Angle> getElevation()
        Returns the elevation angle of this vector as a Parameter.
        Returns:
        the elevation angle of this vector.
      • normValue

        public double normValue()
        Returns the norm, magnitude, or length value of this vector.
        Specified by:
        normValue in class AbstractParamVector<Q extends javax.measure.quantity.Quantity,​Coordinate3D<Q extends javax.measure.quantity.Quantity>>
        Returns:
        this.norm().getValue().
      • plus

        public Polar3D<Qplus​(Vector<Parameter<Q>> that)
        Returns the sum of this vector with the one specified. The unit of the output vector will be the units of this vector.
        Specified by:
        plus in interface GroupAdditive<Q extends javax.measure.quantity.Quantity>
        Specified by:
        plus in class Vector<Parameter<Q extends javax.measure.quantity.Quantity>>
        Parameters:
        that - the vector to be added.
        Returns:
        this + that.
        Throws:
        DimensionException - if vector dimensions are different.
      • plus

        public Polar3D<Qplus​(Parameter<Q> that)
        Returns the sum of this vector with the parameter specified. The input parameter is added to the magnitude of this vector; the direction is left unchanged. The unit of the output vector will be the units of this vector.
        Specified by:
        plus in class AbstractParamVector<Q extends javax.measure.quantity.Quantity,​Coordinate3D<Q extends javax.measure.quantity.Quantity>>
        Parameters:
        that - the parameter to be added to the magnitude of this vector.
        Returns:
        this + that.
      • minus

        public Polar3D<Qminus​(Vector<Parameter<Q>> that)
        Returns the difference between this vector and the one specified.
        Overrides:
        minus in class Vector<Parameter<Q extends javax.measure.quantity.Quantity>>
        Parameters:
        that - the vector to be subtracted.
        Returns:
        this - that.
      • minus

        public Polar3D<Qminus​(Parameter<Q> that)
        Subtracts the supplied Parameter from this vector's magnitude and returns the result. The direction of the vector is left unchanged. The unit of the output vector will be the units of this vector.
        Specified by:
        minus in class AbstractParamVector<Q extends javax.measure.quantity.Quantity,​Coordinate3D<Q extends javax.measure.quantity.Quantity>>
        Parameters:
        that - the Parameter to be subtracted from the magnitude of this vector.
        Returns:
        this - that.
      • times

        public Polar3D times​(Parameter k)
        Returns the product of this vector with the specified coefficient. The magnitude of this vector is scaled by the input coefficient and the direction is left unchanged.
        Specified by:
        times in interface VectorSpace<Vector<Parameter<Q extends javax.measure.quantity.Quantity>>,​Parameter<Q extends javax.measure.quantity.Quantity>>
        Specified by:
        times in class Vector<Parameter<Q extends javax.measure.quantity.Quantity>>
        Parameters:
        k - the coefficient multiplier.
        Returns:
        this · k
      • times

        public Polar3D<Qtimes​(double k)
        Returns the product of this vector with the specified coefficient. The magnitude of this vector is scaled by the input coefficient and the direction is left unchanged.
        Specified by:
        times in class AbstractParamVector<Q extends javax.measure.quantity.Quantity,​Coordinate3D<Q extends javax.measure.quantity.Quantity>>
        Parameters:
        k - the coefficient multiplier.
        Returns:
        this · k
      • divide

        public Polar3D<?> divide​(Parameter<?> that)
        Returns the result of this vector divided by the specified divisor. The magnitude of this vector is divided by the input coefficient and the direction is left unchanged.
        Parameters:
        that - the divisor.
        Returns:
        this / that.
      • toUnitVector

        public Polar3D<javax.measure.quantity.Dimensionless> toUnitVector()
        Returns this vector converted to a unit vector with a vector magnitude of 1.0.
        Specified by:
        toUnitVector in class Coordinate3D<Q extends javax.measure.quantity.Quantity>
        Returns:
        this vector converted to a unit vector
      • copy

        public Polar3D<Qcopy()
        Returns a copy of this vector allocated by the calling thread (possibly on the stack).
        Specified by:
        copy in interface javolution.lang.ValueType
        Specified by:
        copy in class Vector<Parameter<Q extends javax.measure.quantity.Quantity>>
        Returns:
        an identical and independent copy of this vector.
      • getUnit

        public javax.measure.unit.Unit<QgetUnit()
        Returns the unit in which the magnitude in this vector are stated in.
        Specified by:
        getUnit in class AbstractParamVector<Q extends javax.measure.quantity.Quantity,​Coordinate3D<Q extends javax.measure.quantity.Quantity>>
        Returns:
        the unit in which the magnitude in this vector are stated in
      • getAnglesUnit

        public javax.measure.unit.Unit<javax.measure.quantity.Angle> getAnglesUnit()
        Returns the unit in which the angles in this vector are stated in.
        Returns:
        the unit in which the angles in this vector are stated in
      • to

        public <R extends javax.measure.quantity.Quantity> Polar3D<R> to​(javax.measure.unit.Unit<R> unit)
                                                                  throws javax.measure.converter.ConversionException
        Returns the equivalent to this vector but with the magnitude stated in the specified unit.
        Specified by:
        to in class AbstractParamVector<Q extends javax.measure.quantity.Quantity,​Coordinate3D<Q extends javax.measure.quantity.Quantity>>
        Type Parameters:
        R - the Quantity (unit type, e.g. Length or Volume) of the returned vector.
        Parameters:
        unit - the unit of the magnitude of the vector to be returned.
        Returns:
        a vector equivalent to this vector but with the magnitude stated in the specified unit.
        Throws:
        javax.measure.converter.ConversionException - if the current model does not allows for conversion to the specified unit.
      • anglesTo

        public Polar3D<QanglesTo​(javax.measure.unit.Unit<javax.measure.quantity.Angle> unit)
        Returns the equivalent to this vector but with the angles stated in the specified unit.
        Parameters:
        unit - the angle unit of the angles of the vector to be returned.
        Returns:
        a coordinate equivalent to this vector but with the angles stated in the specified unit.
        Throws:
        javax.measure.converter.ConversionException - if the current model does not allows for conversion to the specified unit.
      • asType

        public <T extends javax.measure.quantity.Quantity> Polar3D<T> asType​(java.lang.Class<T> type)
                                                                      throws java.lang.ClassCastException
        Casts this Polar3D to a parameterized unit of specified nature or throw a ClassCastException if the dimension of the specified quantity and this parameter's unit dimension do not match.
        Specified by:
        asType in class Coordinate3D<Q extends javax.measure.quantity.Quantity>
        Type Parameters:
        T - the Quantity (unit type, e.g. Length or Volume) of the returned vector.
        Parameters:
        type - the quantity class identifying the nature of the unit.
        Returns:
        this Polar3D parameterized with the specified type.
        Throws:
        java.lang.ClassCastException - if the dimension of this parameter's unit is different from the specified quantity dimension.
        java.lang.UnsupportedOperationException - if the specified quantity class does not have a public static field named "UNIT" holding the standard unit for the quantity.
      • toVector3D

        public Vector3D<QtoVector3D()
        Returns a Cartesian Vector3D representation of this vector.

        The polar to Cartesian transformation is defined by:

            |x|             | cos(elevation)*cos(azimuth)  |
            |y| = magnitude*| cos(elevation)*sin(azimuth)  |
            |z|             |     -sin(elevation)          |
         

        Specified by:
        toVector3D in class AbstractParamVector<Q extends javax.measure.quantity.Quantity,​Coordinate3D<Q extends javax.measure.quantity.Quantity>>
        Returns:
        a Cartesian Vector3D representation of this vector
      • equals

        public boolean equals​(java.lang.Object obj)
        Compares this Polar3D against the specified object for strict equality (same values and same units).
        Overrides:
        equals in class Vector<Parameter<Q extends javax.measure.quantity.Quantity>>
        Parameters:
        obj - the object to compare with.
        Returns:
        true if this vector is identical to that vector; false otherwise.
      • main

        public static void main​(java.lang.String[] args)
        Tests the methods in this class.
        Parameters:
        args - Command line arguments (ignored)