Package geomss.geom
Class MutableVector<Q extends javax.measure.quantity.Quantity>
- java.lang.Object
-
- geomss.geom.AbstractGeomElement<GeomVector>
-
- geomss.geom.GeomVector<Q>
-
- geomss.geom.MutableVector<Q>
-
- 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
-
-
Field Summary
-
Fields inherited from class geomss.geom.GeomVector
X, Y, Z
-
Fields inherited from class geomss.geom.AbstractGeomElement
RESOURCES
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MutableVector<Q>
copy()
Returns a copy of this Vector instanceallocated
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 thevalues
in this vector are stated in.double
getValue(int i)
Returns the value of the Parameter in this vector as adouble
, stated in this vector'sunit
.double
getValue(int i, javax.measure.unit.Unit<Q> unit)
Returns the value of the Parameter in this vector as adouble
, 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 MutableVector<javax.measure.quantity.Dimensionless>
newInstance(int dim)
Returns a dimensionlessMutableVector
instance of the specified dimension with all the coordinate values set to zero.static <Q extends javax.measure.quantity.Quantity>
MutableVector<Q>newInstance(int dim, javax.measure.unit.Unit<Q> unit)
Returns aMutableVector
instance of the specified dimension and units with all the coordinate values set to zero.double
normValue()
Returns theGeomVector.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(MutableVector instance)
Recycles aMutableVector
instance immediately (on the stack when executing in aStackContext
).void
set(int i, Parameter<Q> value)
Set the value of a vector dimension to the specified Parameter.void
set(GeomVector<Q> v)
Set the value of elements of this vector to the elements of the specified vector.void
setOrigin(Point origin)
Set the origin point for this vector.void
setValue(int i, double value)
Set the value of a vector dimension to the specified double in the current vector units.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.MutableVector
to(javax.measure.unit.Unit unit)
Returns the equivalent to this vector but stated in the specified unit.MutableVector<Q>
toDimension(int newDim)
Return a copy of this vector converted to the specified number of physical dimensions.Float64Vector
toFloat64Vector()
Returns aFloat64Vector
containing the elements of this vector stated in the current units.ParameterVector<Q>
toParameterVector()
Returns aParameterVector
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 MutableVector<javax.measure.quantity.Dimensionless>
valueOf(double... x)
Returns a dimensionlessMutableVector
instance holding the specifieddouble
value or values.static MutableVector<javax.measure.quantity.Length>
valueOf(GeomPoint point)
Returns aMutableVector
instance holding the specifiedGeomPoint
values.static <Q extends javax.measure.quantity.Quantity>
MutableVector<Q>valueOf(GeomVector<Q> vector)
Returns aVector
instance containing the specified GeomVector values.static <Q extends javax.measure.quantity.Quantity>
MutableVector<Q>valueOf(Parameter<Q>... values)
Returns aMutableVector
instance holding the specifiedParameter
values.static <Q extends javax.measure.quantity.Quantity>
MutableVector<Q>valueOf(java.util.List<Parameter<Q>> values)
Returns aMutableVector
instance containing the specified list of Parameter values with compatible units.static <Q extends javax.measure.quantity.Quantity>
MutableVector<Q>valueOf(javax.measure.unit.Unit<Q> unit, double... x)
Returns aMutableVector
instance holding the specifieddouble
value or values stated in the specified units.static <Q extends javax.measure.quantity.Quantity>
MutableVector<Q>valueOf(Vector<Parameter<Q>> vector)
Returns aMutableVector
instance containing the specified vector of Parameter values with compatible units.static <Q extends javax.measure.quantity.Quantity>
MutableVector<Q>valueOf(Vector<Float64> vector, javax.measure.unit.Unit<Q> unit)
Returns aMutableVector
instance containing the specified vector of Float64 values stated in the specified units.-
Methods inherited from class geomss.geom.GeomVector
angle, dot, get, getBoundsMax, getBoundsMin, getLimitPoint, getParDimension, getTransformed, isApproxEqual, isApproxEqual, isValid, mag, magValue, norm, size, toArray, toArray, toText
-
Methods inherited from class geomss.geom.AbstractGeomElement
addChangeListener, clone, compareTo, getAllUserData, getID, getName, getUserData, putAllUserData, putUserData, removeChangeListener, removeUserData, reset, setName, toString
-
Methods inherited from interface geomss.geom.GeomElement
addChangeListener, getAllUserData, getID, getName, getUserData, putAllUserData, putUserData, removeChangeListener, removeUserData, setName
-
-
-
-
Method Detail
-
newInstance
public static MutableVector<javax.measure.quantity.Dimensionless> newInstance(int dim)
Returns a dimensionlessMutableVector
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 aMutableVector
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 aVector
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 dimensionlessMutableVector
instance holding the specifieddouble
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 aMutableVector
instance holding the specifieddouble
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 aMutableVector
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 aMutableVector
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 aMutableVector
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 aMutableVector
instance holding the specifiedParameter
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 aMutableVector
instance holding the specifiedGeomPoint
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 ati
. 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 ati
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 adouble
, stated in this vector'sunit
.- Specified by:
getValue
in classGeomVector<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 adouble
, stated in the specified units.- Specified by:
getValue
in classGeomVector<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 classGeomVector<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 classGeomVector<Q extends javax.measure.quantity.Quantity>
- Returns:
- The origin point for this vector.
-
normValue
public double normValue()
Returns theGeomVector.norm()
, magnitude, or length value of this vector (square root of the dot product of this vector and itself).- Specified by:
normValue
in classGeomVector<Q extends javax.measure.quantity.Quantity>
- Returns:
this.norm().getValue()
.
-
opposite
public Vector<Q> opposite()
Returns the negation of this vector.- Specified by:
opposite
in classGeomVector<Q extends javax.measure.quantity.Quantity>
- Returns:
-this
.
-
plus
public Vector<Q> plus(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 classGeomVector<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<Q> plus(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 classGeomVector<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<Q> minus(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 classGeomVector<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<Q> minus(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 classGeomVector<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<Q> times(double k)
Returns the product of this vector with the specified coefficient (dimensionless).- Specified by:
times
in classGeomVector<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 classGeomVector<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 classGeomVector<Q extends javax.measure.quantity.Quantity>
- Parameters:
that
- the vector multiplier. May not be null.- Returns:
this · that
- Throws:
DimensionException
- ifthis.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 classGeomVector<Q extends javax.measure.quantity.Quantity>
- Parameters:
that
- the vector multiplier. May not be null.- Returns:
this .* that
- Throws:
DimensionException
- ifthis.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 classGeomVector<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<Q> divide(double divisor)
Returns this vector with each element divided by the specified divisor (dimensionless).- Specified by:
divide
in classGeomVector<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 classGeomVector<Q extends javax.measure.quantity.Quantity>
- Parameters:
divisor
- the divisor. May not be null.- Returns:
this / divisor
.
-
immutable
public Vector<Q> immutable()
Return an immutable version of this vector.- Specified by:
immutable
in classGeomVector<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 classGeomVector<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 thevalues
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<Q> toDimension(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 interfaceGeomElement<Q extends javax.measure.quantity.Quantity>
- Specified by:
toDimension
in classGeomVector<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<Q> copy()
Returns a copy of this Vector instanceallocated
by the calling thread (possibly on the stack).- Specified by:
copy
in interfaceGeomElement<Q extends javax.measure.quantity.Quantity>
- Specified by:
copy
in classGeomVector<Q extends javax.measure.quantity.Quantity>
- Returns:
- an identical and independent copy of this vector.
-
copyToReal
public Vector<Q> copyToReal()
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.
-
toParameterVector
public ParameterVector<Q> toParameterVector()
Returns aParameterVector
representation of this vector.- Specified by:
toParameterVector
in classGeomVector<Q extends javax.measure.quantity.Quantity>
- Returns:
- A ParameterVector that is equivalent to this vector.
-
toFloat64Vector
public Float64Vector toFloat64Vector()
Returns aFloat64Vector
containing the elements of this vector stated in the current units.- Specified by:
toFloat64Vector
in classGeomVector<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 classAbstractGeomElement<GeomVector>
- Parameters:
obj
- the object to compare with.- Returns:
true
if this vector is identical to that vector;false
otherwise.
-
hashCode
public int hashCode()
Returns the hash code for this parameter.- Overrides:
hashCode
in classAbstractGeomElement<GeomVector>
- Returns:
- the hash code value.
-
recycle
public static void recycle(MutableVector instance)
Recycles aMutableVector
instance immediately (on the stack when executing in aStackContext
).- Parameters:
instance
- The instance to be recycled.
-
-