Package geomss.geom

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

  • Type Parameters:
    Q - The Quantity (unit type) associated with this vector's coordinate values.
    All Implemented Interfaces:
    GeomElement<GeomVector>, Transformable<GeomVector>, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable, javolution.lang.Immutable, javolution.lang.Reusable, javolution.lang.ValueType, javolution.xml.XMLSerializable

    public final class Vector<Q extends javax.measure.quantity.Quantity>
    extends GeomVector<Q>
    implements javolution.lang.ValueType
    A container that holds the coordinates of an n-dimensional vector which indicates direction, but not position.

    Modified by: Joseph A. Huwaldt

    Version:
    September 10, 2016
    Author:
    Joseph A. Huwaldt, Date: June 13, 2009
    See Also:
    Serialized Form
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Vector[] allocateArray​(int size)
      Allocate a recyclable array that can contain Vector objects using factory methods.
      Vector<Q> copy()
      Returns a copy of this Vector instance allocated by the calling thread (possibly on the stack).
      Vector<Q> copyToReal()
      Return a copy of this object with any transformations or subranges removed (applied).
      Vector<? extends javax.measure.quantity.Quantity> cross​(GeomVector<?> that)
      Returns the cross product of two vectors.
      Vector<Q> divide​(double divisor)
      Returns this vector with each element divided by the specified divisor (dimensionless).
      Vector<? extends javax.measure.quantity.Quantity> divide​(Parameter<?> divisor)
      Returns this vector with each element divided by the specified divisor.
      boolean equals​(java.lang.Object obj)
      Compares this vector against the specified object for strict equality (same values and same units).
      Point getOrigin()
      Return the origin point for this vector.
      int getPhyDimension()
      Returns the number of physical dimensions of this vector.
      javax.measure.unit.Unit 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.
      double getValue​(int i, javax.measure.unit.Unit<Q> unit)
      Returns the value of the Parameter in this vector as a double, stated in the specified units.
      int hashCode()
      Returns the hash code for this parameter.
      Vector<Q> immutable()
      Return an immutable version of this vector.
      Vector<Q> minus​(GeomVector<Q> that)
      Returns the difference between this vector and the one specified.
      Vector<Q> minus​(Parameter<Q> that)
      Subtracts the supplied Parameter from each element of this vector and returns the result.
      static Vector<javax.measure.quantity.Dimensionless> newInstance​(int numDims)
      Returns a dimensionless Vector instance of the specified dimension with all the coordinate values set to zero.
      static <Q extends javax.measure.quantity.Quantity>
      Vector<Q>
      newInstance​(int numDims, javax.measure.unit.Unit<Q> unit)
      Returns a Vector instance of the specified dimension and units with all the coordinate values set to zero.
      double normValue()
      Returns the GeomVector.norm(), magnitude, or length value of this vector (square root of the dot product of this vector and itself).
      Vector<Q> opposite()
      Returns the negation of this vector.
      Vector<Q> plus​(GeomVector<Q> that)
      Returns the sum of this vector with the one specified.
      Vector<Q> plus​(Parameter<Q> that)
      Returns the sum of this vector with the parameter specified.
      static void recycle​(Vector instance)
      Recycles a Vector instance immediately (on the stack when executing in a StackContext).
      static void recycleArray​(Vector[] arr)
      Recycle an array of Vector objects that was created by Vector.allocateArray().
      void setOrigin​(Point origin)
      Set the origin point for this vector.
      Vector<Q> times​(double k)
      Returns the product of this vector with the specified coefficient (dimensionless).
      Parameter<? extends javax.measure.quantity.Quantity> times​(GeomVector<?> that)
      Returns the dot product (scalar product) of this vector with the one specified.
      Vector<? extends javax.measure.quantity.Quantity> times​(Parameter<?> k)
      Returns the product of this vector with the specified coefficient.
      Vector<? extends javax.measure.quantity.Quantity> timesEBE​(GeomVector<?> that)
      Returns the element-by-element product of this vector with the one specified.
      Vector to​(javax.measure.unit.Unit unit)
      Returns the equivalent to this vector but stated in the specified unit.
      Vector<Q> toDimension​(int newDim)
      Return a copy of this vector converted to the specified number of physical dimensions.
      Float64Vector toFloat64Vector()
      Returns a Float64Vector containing the elements of this vector stated in the current units.
      ParameterVector<Q> toParameterVector()
      Returns a ParameterVector representation of this vector.
      Vector<javax.measure.quantity.Dimensionless> toUnitVector()
      Returns this vector converted to a unit vector by dividing all the vector's elements by the length (GeomVector.norm()) of this vector.
      static Vector<javax.measure.quantity.Dimensionless> valueOf​(double... x)
      Returns a dimensionless Vector instance holding the specified double value or values.
      static Vector<javax.measure.quantity.Length> valueOf​(GeomPoint point)
      Returns a Vector instance holding the specified GeomPoint values.
      static <Q extends javax.measure.quantity.Quantity>
      Vector<Q>
      valueOf​(GeomVector<Q> vector)
      Returns a Vector instance containing the specified GeomVector values.
      static <Q extends javax.measure.quantity.Quantity>
      Vector<Q>
      valueOf​(Parameter<Q>... values)
      Returns a Vector instance holding the specified Parameter values.
      static <Q extends javax.measure.quantity.Quantity>
      Vector<Q>
      valueOf​(java.util.List<Parameter<Q>> values)
      Returns a Vector instance containing the specified list of Parameter values with compatible units.
      static <Q extends javax.measure.quantity.Quantity>
      Vector<Q>
      valueOf​(javax.measure.unit.Unit<Q> unit, double... x)
      Returns a Vector instance holding the specified double value or values stated in the specified units.
      static <Q extends javax.measure.quantity.Quantity>
      Vector<Q>
      valueOf​(Vector<Parameter<Q>> vector)
      Returns a Vector instance containing the specified vector of Parameter values with compatible units.
      static <Q extends javax.measure.quantity.Quantity>
      Vector<Q>
      valueOf​(Vector<Float64> vector, javax.measure.unit.Unit<Q> unit)
      Returns a Vector 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 java.lang.Comparable

        compareTo
    • Method Detail

      • newInstance

        public static Vector<javax.measure.quantity.Dimensionless> newInstance​(int numDims)
        Returns a dimensionless Vector instance of the specified dimension with all the coordinate values set to zero.
        Parameters:
        numDims - the physical dimension of the vector to create.
        Returns:
        the dimensionless vector having the specified dimension and zeros for values.
      • newInstance

        public static <Q extends javax.measure.quantity.Quantity> Vector<Q> newInstance​(int numDims,
                                                                                        javax.measure.unit.Unit<Q> unit)
        Returns a Vector instance of the specified dimension and units with all the coordinate values set to zero.
        Type Parameters:
        Q - The Quantity (unit type) associated with the new vector's coordinate values.
        Parameters:
        numDims - the physical dimension of the vector to create.
        unit - the unit in which the coordinates are stated. May not be null.
        Returns:
        the vector having the specified dimension and zero meters for values.
      • valueOf

        public static <Q extends javax.measure.quantity.Quantity> Vector<Q> valueOf​(GeomVector<Q> vector)
        Returns a Vector instance containing the specified GeomVector values.
        Type Parameters:
        Q - The Quantity (unit type) associated with the new vector's coordinate values.
        Parameters:
        vector - The GeomVector to be placed in a new Vector instance. May not be null.
        Returns:
        the vector having the specified values.
      • valueOf

        public static Vector<javax.measure.quantity.Dimensionless> valueOf​(double... x)
        Returns a dimensionless Vector instance holding the specified double value or values.
        Parameters:
        x - the dimensionless coordinate values. May not be null.
        Returns:
        the vector having the specified value and dimensionless units.
      • valueOf

        public static <Q extends javax.measure.quantity.Quantity> Vector<Q> valueOf​(javax.measure.unit.Unit<Q> unit,
                                                                                    double... x)
        Returns a Vector instance holding the specified double value or values stated in the specified units.
        Type Parameters:
        Q - The Quantity (unit type) associated with the new vector's coordinate values.
        Parameters:
        unit - the unit in which the coordinates are stated. May not be null.
        x - the coordinate values stated in the specified unit. May not be null.
        Returns:
        the vector having the specified value.
      • valueOf

        public static <Q extends javax.measure.quantity.Quantity> Vector<Q> valueOf​(Vector<Parameter<Q>> vector)
        Returns a Vector instance containing the specified vector of Parameter values with compatible units. All the values are converted to the same units as the 1st value.
        Type Parameters:
        Q - The Quantity (unit type) associated with the new vector's coordinate values.
        Parameters:
        vector - the vector of Parameter values stated in the specified unit. May not be null.
        Returns:
        the vector having the specified values.
      • valueOf

        public static <Q extends javax.measure.quantity.Quantity> Vector<Q> valueOf​(java.util.List<Parameter<Q>> values)
        Returns a Vector instance containing the specified list of Parameter values with compatible units. All the values are converted to the same units as the 1st value.
        Type Parameters:
        Q - The Quantity (unit type) associated with the new vector's coordinate values.
        Parameters:
        values - the list of Parameter values stated in the specified unit. May not be null.
        Returns:
        the vector having the specified values.
      • valueOf

        public static <Q extends javax.measure.quantity.Quantity> Vector<Q> valueOf​(Vector<Float64> vector,
                                                                                    javax.measure.unit.Unit<Q> unit)
        Returns a Vector instance containing the specified vector of Float64 values stated in the specified units.
        Type Parameters:
        Q - The Quantity (unit type) associated with the new vector's coordinate values.
        Parameters:
        vector - the vector of Float64 values stated in the specified unit. May not be null.
        unit - The unit in which the coordinates are stated. May not be null.
        Returns:
        the vector having the specified values.
      • valueOf

        public static <Q extends javax.measure.quantity.Quantity> Vector<Q> valueOf​(Parameter<Q>... values)
        Returns a Vector instance holding the specified Parameter values. All the values are converted to the same units as the first value.
        Type Parameters:
        Q - The Quantity (unit type) associated with the new vector's coordinate values.
        Parameters:
        values - A list of values to store in the vector. May not be null.
        Returns:
        the vector having the specified values in the units of x.
      • valueOf

        public static Vector<javax.measure.quantity.Length> valueOf​(GeomPoint point)
        Returns a Vector instance holding the specified GeomPoint values.
        Parameters:
        point - A point who's coordinates are to be stored in the vector (making it a position vector). May not be null.
        Returns:
        the vector having the specified point coordinate values in it.
      • getPhyDimension

        public int getPhyDimension()
        Returns the number of physical dimensions of this vector.
        Specified by:
        getPhyDimension in interface GeomElement<Q extends javax.measure.quantity.Quantity>
        Returns:
        The number of physical dimensions of this vector.
      • getValue

        public double getValue​(int i)
        Returns the value of the Parameter in this vector as a double, stated in this vector's unit.
        Specified by:
        getValue in class GeomVector<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 ≥ getPhyDimension())
      • getValue

        public double getValue​(int i,
                               javax.measure.unit.Unit<Q> unit)
        Returns the value of the Parameter in this vector as a double, stated in the specified units.
        Specified by:
        getValue in class GeomVector<Q extends javax.measure.quantity.Quantity>
        Parameters:
        i - the dimension index.
        unit - the unit to return the value in. May not be null.
        Returns:
        the value of the Parameter at i in the specified unit.
        Throws:
        java.lang.IndexOutOfBoundsException - (i < 0) || (i ≥ getPhyDimension())
      • setOrigin

        public void setOrigin​(Point origin)
        Set the origin point for this vector. The origin is used as a reference for drawing the vector and is not a part of the state of this vector and is not used in any calculations with this vector.
        Specified by:
        setOrigin in class GeomVector<Q extends javax.measure.quantity.Quantity>
        Parameters:
        origin - The point to use as the origin of this vector (may not be null).
      • getOrigin

        public Point getOrigin()
        Return the origin point for this vector. If no origin has been explicitly set, then the coordinate system origin in the default units is returned.
        Specified by:
        getOrigin in class GeomVector<Q extends javax.measure.quantity.Quantity>
        Returns:
        The origin point for this vector.
      • normValue

        public double normValue()
        Returns the GeomVector.norm(), magnitude, or length value of this vector (square root of the dot product of this vector and itself).
        Specified by:
        normValue in class GeomVector<Q extends javax.measure.quantity.Quantity>
        Returns:
        this.norm().doubleValue().
      • opposite

        public Vector<Qopposite()
        Returns the negation of this vector.
        Specified by:
        opposite in class GeomVector<Q extends javax.measure.quantity.Quantity>
        Returns:
        -this.
      • plus

        public Vector<Qplus​(GeomVector<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 class GeomVector<Q extends javax.measure.quantity.Quantity>
        Parameters:
        that - the vector to be added. May not be null.
        Returns:
        this + that.
        Throws:
        DimensionException - if vector dimensions are different.
      • plus

        public Vector<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 GeomVector<Q extends javax.measure.quantity.Quantity>
        Parameters:
        that - the parameter to be added to each element of this vector. May not be null.
        Returns:
        this + that.
      • minus

        public Vector<Qminus​(GeomVector<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.
        Specified by:
        minus in class GeomVector<Q extends javax.measure.quantity.Quantity>
        Parameters:
        that - the vector to be subtracted from this vector. May not be null.
        Returns:
        this - that.
        Throws:
        DimensionException - if vector dimensions are different.
      • minus

        public Vector<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 GeomVector<Q extends javax.measure.quantity.Quantity>
        Parameters:
        that - the Parameter to be subtracted from each element of this vector. May not be null.
        Returns:
        this - that.
      • times

        public Vector<Qtimes​(double k)
        Returns the product of this vector with the specified coefficient (dimensionless).
        Specified by:
        times in class GeomVector<Q extends javax.measure.quantity.Quantity>
        Parameters:
        k - the coefficient multiplier.
        Returns:
        this · k
      • times

        public Vector<? extends javax.measure.quantity.Quantity> times​(Parameter<?> k)
        Returns the product of this vector with the specified coefficient.
        Specified by:
        times in class GeomVector<Q extends javax.measure.quantity.Quantity>
        Parameters:
        k - the coefficient multiplier. May not be null.
        Returns:
        this · k
      • times

        public Parameter<? extends javax.measure.quantity.Quantity> times​(GeomVector<?> that)
        Returns the dot product (scalar product) of this vector with the one specified.
        Specified by:
        times in class GeomVector<Q extends javax.measure.quantity.Quantity>
        Parameters:
        that - the vector multiplier. May not be null.
        Returns:
        this · that
        Throws:
        DimensionException - if this.dimension() != that.dimension()
        See Also:
        Wikipedia: Dot Product
      • timesEBE

        public Vector<? extends javax.measure.quantity.Quantity> timesEBE​(GeomVector<?> that)
        Returns the element-by-element product of this vector with the one specified.
        Specified by:
        timesEBE in class GeomVector<Q extends javax.measure.quantity.Quantity>
        Parameters:
        that - the vector multiplier. May not be null.
        Returns:
        this .* that
        Throws:
        DimensionException - if this.dimension() != that.dimension()
      • cross

        public Vector<? extends javax.measure.quantity.Quantity> cross​(GeomVector<?> that)
        Returns the cross product of two vectors.
        Specified by:
        cross in class GeomVector<Q extends javax.measure.quantity.Quantity>
        Parameters:
        that - the vector multiplier. May not be null.
        Returns:
        this x that
        Throws:
        DimensionException - if (that.getDimension() != this.getDimension())
        See Also:
        Wikipedia: Cross Product
      • divide

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

        public Vector<? extends javax.measure.quantity.Quantity> divide​(Parameter<?> divisor)
        Returns this vector with each element divided by the specified divisor.
        Specified by:
        divide in class GeomVector<Q extends javax.measure.quantity.Quantity>
        Parameters:
        divisor - the divisor. May not be null.
        Returns:
        this / divisor.
      • immutable

        public Vector<Qimmutable()
        Return an immutable version of this vector.
        Specified by:
        immutable in class GeomVector<Q extends javax.measure.quantity.Quantity>
        Returns:
        An immutable version of this vector.
      • toUnitVector

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

        public javax.measure.unit.Unit getUnit()
        Returns the unit in which the values in this vector are stated in.
        Specified by:
        getUnit in interface GeomElement<Q extends javax.measure.quantity.Quantity>
        Returns:
        The units in which this vector is stated in.
      • to

        public Vector to​(javax.measure.unit.Unit unit)
        Returns the equivalent to this vector but stated in the specified unit.
        Specified by:
        to in interface GeomElement<Q extends javax.measure.quantity.Quantity>
        Parameters:
        unit - the unit of the vector to be returned. May not be null.
        Returns:
        an equivalent to this vector but stated in the specified unit.
        Throws:
        javax.measure.converter.ConversionException - if the the input unit is not compatible with this unit.
      • toDimension

        public Vector<QtoDimension​(int newDim)
        Return a copy of this vector converted to the specified number of physical dimensions. If the number of dimensions is greater than this element, then zeros are added to the additional dimensions. If the number of dimensions is less than this element, then the extra dimensions are simply dropped (truncated). If the new dimensions are the same as the dimension of this element, then this element is simply returned.
        Specified by:
        toDimension in interface GeomElement<Q extends javax.measure.quantity.Quantity>
        Specified by:
        toDimension in class GeomVector<Q extends javax.measure.quantity.Quantity>
        Parameters:
        newDim - The dimension of the vector to return.
        Returns:
        A copy of this vector converted to the new dimensions.
      • copy

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

        public Vector<QcopyToReal()
        Return a copy of this object with any transformations or subranges removed (applied).
        Specified by:
        copyToReal in interface GeomElement<Q extends javax.measure.quantity.Quantity>
        Returns:
        A copy of this object with any transformations or subranges removed.
      • toFloat64Vector

        public Float64Vector toFloat64Vector()
        Returns a Float64Vector containing the elements of this vector stated in the current units.
        Specified by:
        toFloat64Vector in class GeomVector<Q extends javax.measure.quantity.Quantity>
        Returns:
        A Float64Vector that contains the elements of this vector in the current units.
      • equals

        public boolean equals​(java.lang.Object obj)
        Compares this vector against the specified object for strict equality (same values and same units).
        Overrides:
        equals in class AbstractGeomElement<GeomVector>
        Parameters:
        obj - the object to compare with.
        Returns:
        true if this vector is identical to that vector; false otherwise.
      • recycle

        public static void recycle​(Vector instance)
        Recycles a Vector instance immediately (on the stack when executing in a StackContext).
        Parameters:
        instance - The instance to be recycled.
      • allocateArray

        public static Vector[] allocateArray​(int size)
        Allocate a recyclable array that can contain Vector objects using factory methods.

        WARNING: The array returned may not be zeroed. Any object references in the returned array must be assumed to be invalid. Also, the returned array may be larger than the requested size! The array returned by this method can be recycled by recycleArray().

        Parameters:
        size - The minimum number of elements for the returned array to contain.
        Returns:
        An array that can contain Vector objects allocated using factory methods.
        See Also:
        recycleArray(geomss.geom.Vector[])
      • recycleArray

        public static void recycleArray​(Vector[] arr)
        Recycle an array of Vector objects that was created by Vector.allocateArray().
        Parameters:
        arr - The array to be recycled. The array must have been created by this the allocateArray() method!
        See Also:
        allocateArray(int)