Package geomss.geom
Class Vector<Q extends javax.measure.quantity.Quantity>
- java.lang.Object
-
- geomss.geom.AbstractGeomElement<GeomVector>
-
- geomss.geom.GeomVector<Q>
-
- geomss.geom.Vector<Q>
-
- 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
-
-
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 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 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 Vector<javax.measure.quantity.Dimensionless>
newInstance(int numDims)
Returns a dimensionlessVector
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 aVector
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(Vector instance)
Recycles aVector
instance immediately (on the stack when executing in aStackContext
).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 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 Vector<javax.measure.quantity.Dimensionless>
valueOf(double... x)
Returns a dimensionlessVector
instance holding the specifieddouble
value or values.static Vector<javax.measure.quantity.Length>
valueOf(GeomPoint point)
Returns aVector
instance holding the specifiedGeomPoint
values.static <Q extends javax.measure.quantity.Quantity>
Vector<Q>valueOf(GeomVector<Q> vector)
Returns aVector
instance containing the specified GeomVector values.static <Q extends javax.measure.quantity.Quantity>
Vector<Q>valueOf(Parameter<Q>... values)
Returns aVector
instance holding the specifiedParameter
values.static <Q extends javax.measure.quantity.Quantity>
Vector<Q>valueOf(java.util.List<Parameter<Q>> values)
Returns aVector
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 aVector
instance holding the specifieddouble
value or values stated in the specified units.static <Q extends javax.measure.quantity.Quantity>
Vector<Q>valueOf(Vector<Parameter<Q>> vector)
Returns aVector
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 aVector
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 Vector<javax.measure.quantity.Dimensionless> newInstance(int numDims)
Returns a dimensionlessVector
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 aVector
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 aVector
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 dimensionlessVector
instance holding the specifieddouble
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 aVector
instance holding the specifieddouble
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 aVector
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 aVector
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 aVector
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 aVector
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) 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 aVector
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.- Specified by:
getPhyDimension
in interfaceGeomElement<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 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 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 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().doubleValue()
.
-
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 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 thevalues
in this vector are stated in.- Specified by:
getUnit
in interfaceGeomElement<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 interfaceGeomElement<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<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 Vector<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 interfacejavolution.lang.ValueType
- 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).- Specified by:
copyToReal
in interfaceGeomElement<Q extends javax.measure.quantity.Quantity>
- 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(Vector instance)
Recycles aVector
instance immediately (on the stack when executing in aStackContext
).- 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)
-
-