Package geomss.geom

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

  • Type Parameters:
    Q - The Quantity (unit type) of the elements of this vector.
    All Implemented Interfaces:
    GeomElement<GeomVector>, Transformable<GeomVector>, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable, javolution.lang.Reusable, javolution.xml.XMLSerializable

    public final class MutableVector<Q extends javax.measure.quantity.Quantity>
    extends GeomVector<Q>
    A container that holds changeable coordinates of an n-dimensional vector which indicates direction, but not position.

    Modified by: Joseph A. Huwaldt

    Version:
    November 27, 2015
    Author:
    Joseph A. Huwaldt, Date: June 13, 2009
    See Also:
    Serialized Form
    • Method Detail

      • newInstance

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

        public static <Q extends javax.measure.quantity.Quantity> MutableVector<Q> newInstance​(int dim,
                                                                                               javax.measure.unit.Unit<Q> unit)
        Returns a MutableVector instance of the specified dimension and units with all the coordinate values set to zero.
        Type Parameters:
        Q - The Quantity (unit type) of the returned vector.
        Parameters:
        dim - 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> MutableVector<Q> valueOf​(GeomVector<Q> vector)
        Returns a Vector instance containing the specified GeomVector values.
        Type Parameters:
        Q - The Quantity (unit type) of the returned vector.
        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 MutableVector<javax.measure.quantity.Dimensionless> valueOf​(double... x)
        Returns a dimensionless MutableVector 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.
      • valueOf

        public static <Q extends javax.measure.quantity.Quantity> MutableVector<Q> valueOf​(javax.measure.unit.Unit<Q> unit,
                                                                                           double... x)
        Returns a MutableVector instance holding the specified double value or values stated in the specified units.
        Type Parameters:
        Q - The Quantity (unit type) of the returned vector.
        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> MutableVector<Q> valueOf​(Vector<Parameter<Q>> vector)
        Returns a MutableVector 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) of the returned vector.
        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> MutableVector<Q> valueOf​(java.util.List<Parameter<Q>> values)
        Returns a MutableVector 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) of the returned vector.
        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> MutableVector<Q> valueOf​(Vector<Float64> vector,
                                                                                           javax.measure.unit.Unit<Q> unit)
        Returns a MutableVector instance containing the specified vector of Float64 values stated in the specified units.
        Type Parameters:
        Q - The Quantity (unit type) of the returned vector.
        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> MutableVector<Q> valueOf​(Parameter<Q>... values)
        Returns a MutableVector 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) of the returned vector.
        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 MutableVector<javax.measure.quantity.Length> valueOf​(GeomPoint point)
        Returns a MutableVector 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.
        Returns:
        The number of physical dimensions of this vector.
      • set

        public void set​(int i,
                        Parameter<Q> value)
        Set the value of a vector dimension to the specified Parameter.
        Parameters:
        i - the dimension index.
        value - The new value of the parameter to set at i. May not be null.
        Throws:
        java.lang.IndexOutOfBoundsException - (i < 0) || (i ≥ getPhyDimension())
      • set

        public void set​(GeomVector<Q> v)
        Set the value of elements of this vector to the elements of the specified vector.
        Parameters:
        v - The new vector to make this vector equal to. May not be null.
        Throws:
        DimensionException - (v.getPhyDimension() != getPhyDimension())
      • setValue

        public void setValue​(int i,
                             double value)
        Set the value of a vector dimension to the specified double in the current vector units.
        Parameters:
        i - the dimension index.
        value - The new value of the parameter to set at i in the current units of this vector.
        Throws:
        java.lang.IndexOutOfBoundsException - (i < 0) || (i ≥ getPhyDimension())
      • 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 set as the origin of this vector. May not be null.
      • getOrigin

        public Point getOrigin()
        Return the origin point for this vector.
        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().getValue().
      • 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.
      • getUnit

        public javax.measure.unit.Unit getUnit()
        Returns the unit in which the values in this vector are stated in.
        Returns:
        The unit in which the values in this vector are stated.
      • to

        public MutableVector to​(javax.measure.unit.Unit unit)
                         throws javax.measure.converter.ConversionException
        Returns the equivalent to this vector but stated in the specified unit.
        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 MutableVector<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 MutableVector<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 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).
        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​(MutableVector instance)
        Recycles a MutableVector instance immediately (on the stack when executing in a StackContext).
        Parameters:
        instance - The instance to be recycled.