Package jahuwaldt.js.param
Class Polar3D<Q extends javax.measure.quantity.Quantity>
- java.lang.Object
-
- org.jscience.mathematics.vector.Vector<Parameter<Q>>
-
- jahuwaldt.js.param.AbstractParamVector<Q,Coordinate3D<Q>>
-
- jahuwaldt.js.param.Coordinate3D<Q>
-
- jahuwaldt.js.param.Polar3D<Q>
-
- 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 elementvector
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
-
-
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 aClassCastException
if the dimension of the specified quantity and this parameter's unit dimension do not match.Polar3D<Q>
copy()
Returns a copy of this vectorallocated
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 specifiedVector3D
object as aPolar3D
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 aParameter
.Parameter<javax.measure.quantity.Angle>
getElevation()
Returns the elevation angle of this vector as aParameter
.Parameter<Q>
getMagnitude()
Returns the magnitude of this vector as aParameter
.double
getMagnitudeValue()
Returns the magnitude of this vector as adouble
, stated in this vector'sunit
.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 thenorm
, 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 aPolar3D
instance holding the specifieddouble
values stated in the specified units.static <Q extends javax.measure.quantity.Quantity>
Polar3D<Q>valueOf(Coordinate3D<Q> coordinate)
Returns aPolar3D
instance containing the polar coordinate representation of the specifiedcoordinate
.static <Q extends javax.measure.quantity.Quantity>
Polar3D<Q>valueOf(Coordinate3D<Q> coord, javax.measure.unit.Unit<javax.measure.quantity.Angle> angleUnit)
Returns aPolar3D
instance containing the polar coordinate representation of the specifiedcoordinate
.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 aPolar3D
instance holding the specifiedParameter
values.-
Methods inherited from class jahuwaldt.js.param.Coordinate3D
getDimension, isApproxEqual, isApproxZero
-
-
-
-
Field Detail
-
MAGNITUDE
public static final int MAGNITUDE
Constant used to identify the magnitude of in the vector.- See Also:
- Constant Field Values
-
AZIMUTH
public static final int AZIMUTH
Constant used to identify the azimuth angle of the vector.- See Also:
- Constant Field Values
-
ELEVATION
public static final int ELEVATION
Constant used to identify the elevation angle of the vector.- See Also:
- Constant Field Values
-
-
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 aPolar3D
instance holding the specifieddouble
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 aPolar3D
instance holding the specifiedParameter
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 aPolar3D
instance containing the polar coordinate representation of the specifiedcoordinate
. 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 aPolar3D
instance containing the polar coordinate representation of the specifiedcoordinate
.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<Q> fromVector3D(Vector3D<Q> vector)
Return the specifiedVector3D
object as aPolar3D
instance.- Specified by:
fromVector3D
in classAbstractParamVector<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.
-
getMagnitudeValue
public double getMagnitudeValue()
Returns the magnitude of this vector as adouble
, stated in this vector'sunit
.- Returns:
- the magnitude of this vector in this vector's units.
-
getMagnitude
public Parameter<Q> getMagnitude()
Returns the magnitude of this vector as aParameter
.- Returns:
- the magnitude of this vector.
-
getAzimuth
public Parameter<javax.measure.quantity.Angle> getAzimuth()
Returns the azimuth angle of this vector as aParameter
.- Returns:
- the azimuth angle of this vector.
-
getElevation
public Parameter<javax.measure.quantity.Angle> getElevation()
Returns the elevation angle of this vector as aParameter
.- Returns:
- the elevation angle of this vector.
-
norm
public Parameter<Q> norm()
Returns the Euclidian norm, magnitude, or length of this vector (square root of the dot product of this vector and itself).- Specified by:
norm
in interfaceVectorSpaceNormed<Vector<Parameter<Q extends javax.measure.quantity.Quantity>>,Parameter<Q extends javax.measure.quantity.Quantity>>
- Overrides:
norm
in classAbstractParamVector<Q extends javax.measure.quantity.Quantity,Coordinate3D<Q extends javax.measure.quantity.Quantity>>
- Returns:
sqrt(this · this)
.- See Also:
- Wikipedia: Vector Norm
-
normValue
public double normValue()
Returns thenorm
, magnitude, or length value of this vector.- Specified by:
normValue
in classAbstractParamVector<Q extends javax.measure.quantity.Quantity,Coordinate3D<Q extends javax.measure.quantity.Quantity>>
- Returns:
this.norm().getValue()
.
-
plus
public Polar3D<Q> plus(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 interfaceGroupAdditive<Q extends javax.measure.quantity.Quantity>
- Specified by:
plus
in classVector<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<Q> plus(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 classAbstractParamVector<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<Q> minus(Vector<Parameter<Q>> that)
Returns the difference between this vector and the one specified.
-
minus
public Polar3D<Q> minus(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 classAbstractParamVector<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 interfaceVectorSpace<Vector<Parameter<Q extends javax.measure.quantity.Quantity>>,Parameter<Q extends javax.measure.quantity.Quantity>>
- Specified by:
times
in classVector<Parameter<Q extends javax.measure.quantity.Quantity>>
- Parameters:
k
- the coefficient multiplier.- Returns:
this · k
-
times
public Polar3D<Q> times(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 classAbstractParamVector<Q extends javax.measure.quantity.Quantity,Coordinate3D<Q extends javax.measure.quantity.Quantity>>
- Parameters:
k
- the coefficient multiplier.- Returns:
this · k
-
times
public Parameter times(Vector that)
Returns the dot product of this vector with the one specified.- Specified by:
times
in classVector<Parameter<Q extends javax.measure.quantity.Quantity>>
- Parameters:
that
- the vector multiplier.- Returns:
this · that
- Throws:
DimensionException
- ifthis.dimension() != that.dimension()
- See Also:
- Wikipedia: Dot Product
-
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
.
-
cross
public Polar3D cross(Vector that)
Returns the cross product of two 3-dimensional vectors.- Overrides:
cross
in classVector<Parameter<Q extends javax.measure.quantity.Quantity>>
- Parameters:
that
- the vector multiplier.- Returns:
this x that
- Throws:
DimensionException
- if(that.getDimension() != 3)
- See Also:
- Wikipedia: Cross Product
-
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 classCoordinate3D<Q extends javax.measure.quantity.Quantity>
- Returns:
- this vector converted to a unit vector
-
copy
public Polar3D<Q> copy()
Returns a copy of this vectorallocated
by the calling thread (possibly on the stack).
-
getUnit
public javax.measure.unit.Unit<Q> getUnit()
Returns the unit in which the magnitude in this vector are stated in.- Specified by:
getUnit
in classAbstractParamVector<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 classAbstractParamVector<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<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.- 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 aClassCastException
if the dimension of the specified quantity and this parameter's unit dimension do not match.- Specified by:
asType
in classCoordinate3D<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<Q> toVector3D()
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 classAbstractParamVector<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).
-
hashCode
public int hashCode()
Returns the hash code for this parameter.- Overrides:
hashCode
in classVector<Parameter<Q extends javax.measure.quantity.Quantity>>
- Returns:
- the hash code value.
- See Also:
Vector.equals(org.jscience.mathematics.vector.Vector<F>, java.util.Comparator<F>)
-
main
public static void main(java.lang.String[] args)
Tests the methods in this class.- Parameters:
args
- Command line arguments (ignored)
-
-