Class Vector3D<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 Vector3D<Q extends javax.measure.quantity.Quantity>
    extends Coordinate3D<Q>
    implements javolution.xml.XMLSerializable
    This class represents a 3 element vector of Parameter elements sharing the same units. In geometrical terms, this vector represents a set of 3 Cartesian coordinates.

    Modified by: Joseph A. Huwaldt

    Version:
    October 30, 2015
    Author:
    Joseph A. Huwaldt, Date: November 15, 2008
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Vector3D<javax.measure.quantity.Dimensionless> UNIT_X
      A unit vector in the X axis direction.
      static Vector3D<javax.measure.quantity.Dimensionless> UNIT_Y
      A unit vector in the Y axis direction.
      static Vector3D<javax.measure.quantity.Dimensionless> UNIT_Z
      A unit vector in the Z axis direction.
      static int X
      Constant used to identify the X coordinate in the vector.
      static int Y
      Constant used to identify the Y coordinate in the vector.
      static int Z
      Constant used to identify the Z coordinate in the vector.
      static Vector3D<javax.measure.quantity.Dimensionless> ZERO
      A dimensionless vector with all the elements set to zero.
      static Vector3D<javax.measure.quantity.Acceleration> ZERO_ACCELERATION
      An acceleration vector with all the elements set to zero.
      static Vector3D<javax.measure.quantity.Angle> ZERO_ANGLE
      A angle vector with all the elements set to zero.
      static Vector3D<javax.measure.quantity.Force> ZERO_FORCE
      A force vector with all the elements set to zero.
      static Vector3D<javax.measure.quantity.Length> ZERO_POSITION
      A position or length vector with all the elements set to zero.
      static Vector3D<javax.measure.quantity.Velocity> ZERO_VELOCITY
      A velocity vector with all the elements set to zero.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T extends javax.measure.quantity.Quantity>
      Vector3D<T>
      asType​(java.lang.Class<T> type)
      Casts this Vector3D 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.
      Vector3D<Q> copy()
      Returns a copy of this vector allocated by the calling thread (possibly on the stack).
      Vector3D cross​(Vector that)
      Returns the cross product of two 3-dimensional vectors.
      Vector3D<Q> divide​(double divisor)
      Returns this vector with each element divided by the specified divisor (dimensionless).
      Vector3D<?> divide​(Parameter<?> that)
      Returns this vector with each element divided by the specified divisor.
      boolean equals​(java.lang.Object obj)
      Compares this Vector3D against the specified object for strict equality (same values and same units).
      Vector3D<Q> fromVector3D​(Vector3D<Q> vector)
      Return the specified Vector3D object as a Vector3D instance.
      Parameter<Q> get​(int i)
      Returns the value of a Parameter from this vector.
      javax.measure.unit.Unit<Q> getUnit()
      Returns the unit in which the values in this vector are stated in.
      double getValue​(int i)
      Returns the value of the Parameter in this vector as a double, stated in this vector's unit.
      int hashCode()
      Returns the hash code for this parameter.
      static void main​(java.lang.String[] args)
      Tests the methods in this class.
      static <R extends javax.measure.quantity.Quantity>
      Matrix3D<R>
      makeSkewSymmetric​(double a, double b, double c, javax.measure.unit.Unit<R> unit)
      Returns a 3x3 skew-symmetric matrix representation of the values in the input 3D vector stated in the specified units.
      Vector3D<Q> minus​(Parameter<Q> that)
      Subtracts the supplied Parameter from each element of this vector and returns the result.
      Vector3D<Q> minus​(Vector<Parameter<Q>> that)
      Returns the difference between this vector and the one specified.
      double normValue()
      Returns the AbstractParamVector.norm(), magnitude, or length value of this vector.
      Vector3D<Q> opposite()
      Returns the negation of this vector.
      Vector3D<Q> plus​(Parameter<Q> that)
      Returns the sum of this vector with the parameter specified.
      Vector3D<Q> plus​(Vector<Parameter<Q>> that)
      Returns the sum of this vector with the one specified.
      Vector3D<Q> times​(double k)
      Returns the product of this vector with the specified coefficient.
      Vector3D 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.
      Vector3D timesEBE​(Vector that)
      Returns the element-by-element product of this vector with the one specified.
      <R extends javax.measure.quantity.Quantity>
      Vector3D<R>
      to​(javax.measure.unit.Unit<R> unit)
      Returns the equivalent to this vector but stated in the specified unit.
      Float64Vector toFloat64Vector()
      Returns double the values stored in this vector, stated in this vector's unit, as a Float64Vector.
      Matrix3D<Q> toSkewSymmetric()
      Returns a 3x3 skew-symmetric matrix representation of the values in this vector stated in this vector's unit.
      Vector3D<javax.measure.quantity.Dimensionless> toUnitVector()
      Returns this vector converted to a unit vector by dividing all the vector's elements by the length (AbstractParamVector.norm()) of this vector.
      Vector3D<Q> toVector3D()
      Returns a Cartesian Vector3D representation of this vector.
      static <Q extends javax.measure.quantity.Quantity>
      Vector3D<Q>
      valueOf​(double x, double y, double z, javax.measure.unit.Unit<Q> unit)
      Returns a Vector3D instance holding the specified double values stated in the specified units.
      static <Q extends javax.measure.quantity.Quantity>
      Vector3D<Q>
      valueOf​(Parameter<Q> x, Parameter<Q> y, Parameter<Q> z)
      Returns a Vector3D instance holding the specified Parameter values.
      static <Q extends javax.measure.quantity.Quantity>
      Vector3D<Q>
      valueOf​(Vector<Parameter<Q>> vector)
      Returns a Vector3D instance containing the specified vector of Parameter values with compatible units.
      static <Q extends javax.measure.quantity.Quantity>
      Vector3D<Q>
      valueOf​(Vector<Float64> vector, javax.measure.unit.Unit<Q> unit)
      Returns a Vector3D instance containing the specified vector of Float64 values stated in the specified units.
      • Methods inherited from class java.lang.Object

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

        toText
    • Field Detail

      • X

        public static final int X
        Constant used to identify the X coordinate in the vector.
        See Also:
        Constant Field Values
      • Y

        public static final int Y
        Constant used to identify the Y coordinate in the vector.
        See Also:
        Constant Field Values
      • Z

        public static final int Z
        Constant used to identify the Z coordinate in the vector.
        See Also:
        Constant Field Values
      • ZERO

        public static final Vector3D<javax.measure.quantity.Dimensionless> ZERO
        A dimensionless vector with all the elements set to zero.
      • ZERO_POSITION

        public static final Vector3D<javax.measure.quantity.Length> ZERO_POSITION
        A position or length vector with all the elements set to zero.
      • ZERO_VELOCITY

        public static final Vector3D<javax.measure.quantity.Velocity> ZERO_VELOCITY
        A velocity vector with all the elements set to zero.
      • ZERO_ACCELERATION

        public static final Vector3D<javax.measure.quantity.Acceleration> ZERO_ACCELERATION
        An acceleration vector with all the elements set to zero.
      • ZERO_FORCE

        public static final Vector3D<javax.measure.quantity.Force> ZERO_FORCE
        A force vector with all the elements set to zero.
      • ZERO_ANGLE

        public static final Vector3D<javax.measure.quantity.Angle> ZERO_ANGLE
        A angle vector with all the elements set to zero.
      • UNIT_X

        public static final Vector3D<javax.measure.quantity.Dimensionless> UNIT_X
        A unit vector in the X axis direction.
      • UNIT_Y

        public static final Vector3D<javax.measure.quantity.Dimensionless> UNIT_Y
        A unit vector in the Y axis direction.
      • UNIT_Z

        public static final Vector3D<javax.measure.quantity.Dimensionless> UNIT_Z
        A unit vector in the Z axis direction.
    • Method Detail

      • valueOf

        public static <Q extends javax.measure.quantity.Quantity> Vector3D<Q> valueOf​(double x,
                                                                                      double y,
                                                                                      double z,
                                                                                      javax.measure.unit.Unit<Q> unit)
        Returns a Vector3D 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:
        x - the x value stated in the specified unit.
        y - the y value stated in the specified unit.
        z - the z value stated in the specified unit.
        unit - the unit in which the coordinates are stated.
        Returns:
        the vector having the specified values.
      • valueOf

        public static <Q extends javax.measure.quantity.Quantity> Vector3D<Q> valueOf​(Parameter<Q> x,
                                                                                      Parameter<Q> y,
                                                                                      Parameter<Q> z)
        Returns a Vector3D 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:
        x - the x value.
        y - the y value.
        z - the z value.
        Returns:
        the vector having the specified values in the units of x.
      • valueOf

        public static <Q extends javax.measure.quantity.Quantity> Vector3D<Q> valueOf​(Vector<Float64> vector,
                                                                                      javax.measure.unit.Unit<Q> unit)
        Returns a Vector3D instance containing the specified vector of Float64 values stated in the specified units. The vector must have only 3 elements.
        Type Parameters:
        Q - the Quantity (unit type, e.g. Length or Volume) of this vector.
        Parameters:
        vector - the vector of Float64 values stated in the specified unit (must have dimension of 3).
        unit - the unit in which the coordinates are stated.
        Returns:
        the vector having the specified values.
      • valueOf

        public static <Q extends javax.measure.quantity.Quantity> Vector3D<Q> valueOf​(Vector<Parameter<Q>> vector)
        Returns a Vector3D instance containing the specified vector of Parameter values with compatible units. The vector must have only 3 elements. All the values are converted to the same units as the 1st value.
        Type Parameters:
        Q - the Quantity (unit type, e.g. Length or Volume) of this vector.
        Parameters:
        vector - the vector of Parameter values (must have dimension of 3).
        Returns:
        the vector having the specified values.
      • get

        public Parameter<Qget​(int i)
        Returns the value of a Parameter from this vector.
        Specified by:
        get in class Vector<Parameter<Q extends javax.measure.quantity.Quantity>>
        Parameters:
        i - the dimension index.
        Returns:
        the value of the parameter at i.
        Throws:
        java.lang.IndexOutOfBoundsException - (i < 0) || (i > dimension()-1)
      • getValue

        public double getValue​(int i)
        Returns the value of the Parameter in this vector as a double, stated in this vector's unit.
        Overrides:
        getValue in class AbstractParamVector<Q extends javax.measure.quantity.Quantity,​Coordinate3D<Q extends javax.measure.quantity.Quantity>>
        Parameters:
        i - the dimension index.
        Returns:
        the value of the Parameter at i.
        Throws:
        java.lang.IndexOutOfBoundsException - (i < 0) || (i > dimension()-1)
      • plus

        public Vector3D<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 Vector3D<Qplus​(Parameter<Q> that)
        Returns the sum of this vector with the parameter specified. The input parameter is added to each component of this vector. 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 each element of this vector.
        Returns:
        this + that.
      • minus

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

        public Vector3D<Qminus​(Parameter<Q> that)
        Subtracts the supplied Parameter from each element of this vector and returns the result. 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 each element of this vector.
        Returns:
        this - that.
      • times

        public Vector3D times​(Parameter k)
        Returns the product of this vector with the specified coefficient.
        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 Vector3D<Qtimes​(double k)
        Returns the product of this vector with the specified coefficient.
        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
      • timesEBE

        public Vector3D timesEBE​(Vector that)
        Returns the element-by-element product of this vector with the one specified.
        Parameters:
        that - the vector multiplier.
        Returns:
        this .* that
        Throws:
        DimensionException - if this.dimension() != that.dimension()
      • divide

        public Vector3D<Qdivide​(double divisor)
        Returns this vector with each element divided by the specified divisor (dimensionless).
        Overrides:
        divide in class AbstractParamVector<Q extends javax.measure.quantity.Quantity,​Coordinate3D<Q extends javax.measure.quantity.Quantity>>
        Parameters:
        divisor - the divisor.
        Returns:
        this / divisor.
      • divide

        public Vector3D<?> divide​(Parameter<?> that)
        Returns this vector with each element divided by the specified divisor.
        Parameters:
        that - the divisor.
        Returns:
        this / that.
      • toUnitVector

        public Vector3D<javax.measure.quantity.Dimensionless> toUnitVector()
        Returns this vector converted to a unit vector by dividing all the vector's elements by the length (AbstractParamVector.norm()) of this vector.
        Specified by:
        toUnitVector in class Coordinate3D<Q extends javax.measure.quantity.Quantity>
        Returns:
        this vector converted to a unit vector
      • copy

        public Vector3D<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 values 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 values in this vector are stated
      • to

        public <R extends javax.measure.quantity.Quantity> Vector3D<R> to​(javax.measure.unit.Unit<R> unit)
                                                                   throws javax.measure.converter.ConversionException
        Returns the equivalent to this vector but 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 vector to be returned.
        Returns:
        a vector equivalent to this vector but 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> Vector3D<T> asType​(java.lang.Class<T> type)
                                                                       throws java.lang.ClassCastException
        Casts this Vector3D 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 Vector3D 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.
        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
      • toFloat64Vector

        public Float64Vector toFloat64Vector()
        Returns double the values stored in this vector, stated in this vector's unit, as a Float64Vector.
        Returns:
        the values stored in this vector as a Float64Vector
      • toSkewSymmetric

        public Matrix3D<QtoSkewSymmetric()
        Returns a 3x3 skew-symmetric matrix representation of the values in this vector stated in this vector's unit.

        A skew symmetric representation of a vector is defined by:

               | 0 -c  b|      |a|
               | c  0 -a| <--  |b|
               |-b  a  0|      |c|
         

        Returns:
        a 3x3 skew-symmetric matrix representation of the values in this vector
      • makeSkewSymmetric

        public static <R extends javax.measure.quantity.Quantity> Matrix3D<R> makeSkewSymmetric​(double a,
                                                                                                double b,
                                                                                                double c,
                                                                                                javax.measure.unit.Unit<R> unit)
        Returns a 3x3 skew-symmetric matrix representation of the values in the input 3D vector stated in the specified units.

        A skew symmetric representation of a vector is defined by:

               | 0 -c  b|      |a|
               | c  0 -a| <--  |b|
               |-b  a  0|      |c|
         

        This is a more efficient convenience method equivalent to: Vector3D.valueOf(a, b, c, Dimensionless.UNIT).toSkewSymmetric();

        Type Parameters:
        R - the Quantity (unit type, e.g. Length or Volume) of the returned matrix.
        Parameters:
        a - The 1st element of the 3D vector
        b - The 2nd element of the 3D vector
        c - The 3rd element of the 3D vector
        unit - The unit that the elements are stated in.
        Returns:
        a 3x3 skew-symmetric matrix representation of the values in the input 3D vector.
      • equals

        public boolean equals​(java.lang.Object obj)
        Compares this Vector3D 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).