Package jahuwaldt.js.param
Class Vector3D<Q extends javax.measure.quantity.Quantity>
- java.lang.Object
-
- org.jscience.mathematics.vector.Vector<Parameter<Q>>
-
- jahuwaldt.js.param.AbstractParamVector<Q,Coordinate3D<Q>>
-
- jahuwaldt.js.param.Coordinate3D<Q>
-
- jahuwaldt.js.param.Vector3D<Q>
-
- Type Parameters:
Q
- The Quantity (unit type, such as Length or Volume) of this vector.
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<javax.measure.Measurable<Q>>
,javax.measure.Measurable<Q>
,javolution.lang.Immutable
,javolution.lang.Realtime
,javolution.lang.ValueType
,javolution.xml.XMLSerializable
,GroupAdditive<Vector<Parameter<Q>>>
,Structure<Vector<Parameter<Q>>>
,VectorSpace<Vector<Parameter<Q>>,Parameter<Q>>
,VectorSpaceNormed<Vector<Parameter<Q>>,Parameter<Q>>
public final class Vector3D<Q extends javax.measure.quantity.Quantity> extends Coordinate3D<Q> implements javolution.xml.XMLSerializable
This class represents a 3 elementvector
of Parameter elements sharing the same units. In geometrical terms, this vector represents a set of 3 Cartesian coordinates.Modified by: Joseph A. Huwaldt
- Version:
- October 30, 2015
- Author:
- Joseph A. Huwaldt, Date: November 15, 2008
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static Vector3D<javax.measure.quantity.Dimensionless>
UNIT_X
A unit vector in the X axis direction.static Vector3D<javax.measure.quantity.Dimensionless>
UNIT_Y
A unit vector in the Y axis direction.static Vector3D<javax.measure.quantity.Dimensionless>
UNIT_Z
A unit vector in the Z axis direction.static int
X
Constant used to identify the X coordinate in the vector.static int
Y
Constant used to identify the Y coordinate in the vector.static int
Z
Constant used to identify the Z coordinate in the vector.static Vector3D<javax.measure.quantity.Dimensionless>
ZERO
A dimensionless vector with all the elements set to zero.static Vector3D<javax.measure.quantity.Acceleration>
ZERO_ACCELERATION
An acceleration vector with all the elements set to zero.static Vector3D<javax.measure.quantity.Angle>
ZERO_ANGLE
A angle vector with all the elements set to zero.static Vector3D<javax.measure.quantity.Force>
ZERO_FORCE
A force vector with all the elements set to zero.static Vector3D<javax.measure.quantity.Length>
ZERO_POSITION
A position or length vector with all the elements set to zero.static Vector3D<javax.measure.quantity.Velocity>
ZERO_VELOCITY
A velocity vector with all the elements set to zero.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends javax.measure.quantity.Quantity>
Vector3D<T>asType(java.lang.Class<T> type)
Casts this Vector3D to a parameterized unit of specified nature or throw aClassCastException
if the dimension of the specified quantity and this parameter's unit dimension do not match.Vector3D<Q>
copy()
Returns a copy of this vectorallocated
by the calling thread (possibly on the stack).Vector3D
cross(Vector that)
Returns the cross product of two 3-dimensional vectors.Vector3D<Q>
divide(double divisor)
Returns this vector with each element divided by the specified divisor (dimensionless).Vector3D<?>
divide(Parameter<?> that)
Returns this vector with each element divided by the specified divisor.boolean
equals(java.lang.Object obj)
Compares this Vector3D against the specified object for strict equality (same values and same units).Vector3D<Q>
fromVector3D(Vector3D<Q> vector)
Return the specifiedVector3D
object as aVector3D
instance.Parameter<Q>
get(int i)
Returns the value of a Parameter from this vector.javax.measure.unit.Unit<Q>
getUnit()
Returns the unit in which 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
.int
hashCode()
Returns the hash code for this parameter.static void
main(java.lang.String[] args)
Tests the methods in this class.static <R extends javax.measure.quantity.Quantity>
Matrix3D<R>makeSkewSymmetric(double a, double b, double c, javax.measure.unit.Unit<R> unit)
Returns a 3x3 skew-symmetric matrix representation of the values in the input 3D vector stated in the specified units.Vector3D<Q>
minus(Parameter<Q> that)
Subtracts the supplied Parameter from each element of this vector and returns the result.Vector3D<Q>
minus(Vector<Parameter<Q>> that)
Returns the difference between this vector and the one specified.double
normValue()
Returns theAbstractParamVector.norm()
, magnitude, or length value of this vector.Vector3D<Q>
opposite()
Returns the negation of this vector.Vector3D<Q>
plus(Parameter<Q> that)
Returns the sum of this vector with the parameter specified.Vector3D<Q>
plus(Vector<Parameter<Q>> that)
Returns the sum of this vector with the one specified.Vector3D<Q>
times(double k)
Returns the product of this vector with the specified coefficient.Vector3D
times(Parameter k)
Returns the product of this vector with the specified coefficient.Parameter
times(Vector that)
Returns the dot product of this vector with the one specified.Vector3D
timesEBE(Vector that)
Returns the element-by-element product of this vector with the one specified.<R extends javax.measure.quantity.Quantity>
Vector3D<R>to(javax.measure.unit.Unit<R> unit)
Returns the equivalent to this vector but stated in the specified unit.Float64Vector
toFloat64Vector()
Returns double the values stored in this vector, stated in this vector'sunit
, as a Float64Vector.Matrix3D<Q>
toSkewSymmetric()
Returns a 3x3 skew-symmetric matrix representation of the values in this vector stated in this vector'sunit
.Vector3D<javax.measure.quantity.Dimensionless>
toUnitVector()
Returns this vector converted to a unit vector by dividing all the vector's elements by the length (AbstractParamVector.norm()
) of this vector.Vector3D<Q>
toVector3D()
Returns a Cartesian Vector3D representation of this vector.static <Q extends javax.measure.quantity.Quantity>
Vector3D<Q>valueOf(double x, double y, double z, javax.measure.unit.Unit<Q> unit)
Returns aVector3D
instance holding the specifieddouble
values stated in the specified units.static <Q extends javax.measure.quantity.Quantity>
Vector3D<Q>valueOf(Parameter<Q> x, Parameter<Q> y, Parameter<Q> z)
Returns aVector3D
instance holding the specifiedParameter
values.static <Q extends javax.measure.quantity.Quantity>
Vector3D<Q>valueOf(Vector<Parameter<Q>> vector)
Returns aVector3D
instance containing the specified vector of Parameter values with compatible units.static <Q extends javax.measure.quantity.Quantity>
Vector3D<Q>valueOf(Vector<Float64> vector, javax.measure.unit.Unit<Q> unit)
Returns aVector3D
instance containing the specified vector of Float64 values stated in the specified units.-
Methods inherited from class jahuwaldt.js.param.Coordinate3D
getDimension, isApproxEqual, isApproxZero
-
-
-
-
Field Detail
-
X
public static final int X
Constant used to identify the X coordinate in the vector.- See Also:
- Constant Field Values
-
Y
public static final int Y
Constant used to identify the Y coordinate in the vector.- See Also:
- Constant Field Values
-
Z
public static final int Z
Constant used to identify the Z coordinate in the vector.- See Also:
- Constant Field Values
-
ZERO
public static final Vector3D<javax.measure.quantity.Dimensionless> ZERO
A dimensionless vector with all the elements set to zero.
-
ZERO_POSITION
public static final Vector3D<javax.measure.quantity.Length> ZERO_POSITION
A position or length vector with all the elements set to zero.
-
ZERO_VELOCITY
public static final Vector3D<javax.measure.quantity.Velocity> ZERO_VELOCITY
A velocity vector with all the elements set to zero.
-
ZERO_ACCELERATION
public static final Vector3D<javax.measure.quantity.Acceleration> ZERO_ACCELERATION
An acceleration vector with all the elements set to zero.
-
ZERO_FORCE
public static final Vector3D<javax.measure.quantity.Force> ZERO_FORCE
A force vector with all the elements set to zero.
-
ZERO_ANGLE
public static final Vector3D<javax.measure.quantity.Angle> ZERO_ANGLE
A angle vector with all the elements set to zero.
-
UNIT_X
public static final Vector3D<javax.measure.quantity.Dimensionless> UNIT_X
A unit vector in the X axis direction.
-
UNIT_Y
public static final Vector3D<javax.measure.quantity.Dimensionless> UNIT_Y
A unit vector in the Y axis direction.
-
-
Method Detail
-
valueOf
public static <Q extends javax.measure.quantity.Quantity> Vector3D<Q> valueOf(double x, double y, double z, javax.measure.unit.Unit<Q> unit)
Returns aVector3D
instance holding the specifieddouble
values stated in the specified units.- Type Parameters:
Q
- the Quantity (unit type, e.g. Length or Volume) of this vector.- Parameters:
x
- the x value stated in the specified unit.y
- the y value stated in the specified unit.z
- the z value stated in the specified unit.unit
- the unit in which the coordinates are stated.- Returns:
- the vector having the specified values.
-
valueOf
public static <Q extends javax.measure.quantity.Quantity> Vector3D<Q> valueOf(Parameter<Q> x, Parameter<Q> y, Parameter<Q> z)
Returns aVector3D
instance holding the specifiedParameter
values. All the values are converted to the same units as the x value.- Type Parameters:
Q
- the Quantity (unit type, e.g. Length or Volume) of this vector.- Parameters:
x
- the x value.y
- the y value.z
- the z value.- Returns:
- the vector having the specified values in the units of x.
-
valueOf
public static <Q extends javax.measure.quantity.Quantity> Vector3D<Q> valueOf(Vector<Float64> vector, javax.measure.unit.Unit<Q> unit)
Returns aVector3D
instance containing the specified vector of Float64 values stated in the specified units. The vector must have only 3 elements.- Type Parameters:
Q
- the Quantity (unit type, e.g. Length or Volume) of this vector.- Parameters:
vector
- the vector of Float64 values stated in the specified unit (must have dimension of 3).unit
- the unit in which the coordinates are stated.- Returns:
- the vector having the specified values.
-
valueOf
public static <Q extends javax.measure.quantity.Quantity> Vector3D<Q> valueOf(Vector<Parameter<Q>> vector)
Returns aVector3D
instance containing the specified vector of Parameter values with compatible units. The vector must have only 3 elements. All the values are converted to the same units as the 1st value.- Type Parameters:
Q
- the Quantity (unit type, e.g. Length or Volume) of this vector.- Parameters:
vector
- the vector of Parameter values (must have dimension of 3).- Returns:
- the vector having the specified values.
-
fromVector3D
public Vector3D<Q> fromVector3D(Vector3D<Q> vector)
Return the specifiedVector3D
object as aVector3D
instance.- Specified by:
fromVector3D
in classAbstractParamVector<Q extends javax.measure.quantity.Quantity,Coordinate3D<Q extends javax.measure.quantity.Quantity>>
- Parameters:
vector
- TheVector3D
object to be converted to aVector3D
.- Returns:
- The input object is simply returned.
-
getValue
public double getValue(int i)
Returns the value of the Parameter in this vector as adouble
, stated in this vector'sunit
.- Overrides:
getValue
in classAbstractParamVector<Q extends javax.measure.quantity.Quantity,Coordinate3D<Q extends javax.measure.quantity.Quantity>>
- Parameters:
i
- the dimension index.- Returns:
- the value of the Parameter at
i
. - Throws:
java.lang.IndexOutOfBoundsException
-(i < 0) || (i > dimension()-1)
-
normValue
public double normValue()
Returns theAbstractParamVector.norm()
, magnitude, or length value of this vector.- Specified by:
normValue
in classAbstractParamVector<Q extends javax.measure.quantity.Quantity,Coordinate3D<Q extends javax.measure.quantity.Quantity>>
- Returns:
this.norm().doubleValue()
.
-
plus
public Vector3D<Q> plus(Vector<Parameter<Q>> that)
Returns the sum of this vector with the one specified. The unit of the output vector will be the units of this vector.- Specified by:
plus
in interfaceGroupAdditive<Q extends javax.measure.quantity.Quantity>
- Specified by:
plus
in classVector<Parameter<Q extends javax.measure.quantity.Quantity>>
- Parameters:
that
- the vector to be added.- Returns:
this + that
.- Throws:
DimensionException
- if vector dimensions are different.
-
plus
public Vector3D<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 classAbstractParamVector<Q extends javax.measure.quantity.Quantity,Coordinate3D<Q extends javax.measure.quantity.Quantity>>
- Parameters:
that
- the parameter to be added to each element of this vector.- Returns:
this + that
.
-
minus
public Vector3D<Q> minus(Vector<Parameter<Q>> that)
Returns the difference between this vector and the one specified. The unit of the output vector will be the units of this vector.
-
minus
public Vector3D<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 classAbstractParamVector<Q extends javax.measure.quantity.Quantity,Coordinate3D<Q extends javax.measure.quantity.Quantity>>
- Parameters:
that
- the Parameter to be subtracted from each element of this vector.- Returns:
this - that
.
-
times
public Vector3D times(Parameter k)
Returns the product of this vector with the specified coefficient.- Specified by:
times
in interfaceVectorSpace<Vector<Parameter<Q extends javax.measure.quantity.Quantity>>,Parameter<Q extends javax.measure.quantity.Quantity>>
- Specified by:
times
in classVector<Parameter<Q extends javax.measure.quantity.Quantity>>
- Parameters:
k
- the coefficient multiplier.- Returns:
this · k
-
times
public Vector3D<Q> times(double k)
Returns the product of this vector with the specified coefficient.- Specified by:
times
in classAbstractParamVector<Q extends javax.measure.quantity.Quantity,Coordinate3D<Q extends javax.measure.quantity.Quantity>>
- Parameters:
k
- the coefficient multiplier.- Returns:
this · k
-
times
public Parameter times(Vector that)
Returns the dot product of this vector with the one specified.- Specified by:
times
in classVector<Parameter<Q extends javax.measure.quantity.Quantity>>
- Parameters:
that
- the vector multiplier.- Returns:
this · that
- Throws:
DimensionException
- ifthis.dimension() != that.dimension()
- See Also:
- Wikipedia: Dot Product
-
timesEBE
public Vector3D timesEBE(Vector that)
Returns the element-by-element product of this vector with the one specified.- Parameters:
that
- the vector multiplier.- Returns:
this .* that
- Throws:
DimensionException
- ifthis.dimension() != that.dimension()
-
divide
public Vector3D<Q> divide(double divisor)
Returns this vector with each element divided by the specified divisor (dimensionless).- Overrides:
divide
in classAbstractParamVector<Q extends javax.measure.quantity.Quantity,Coordinate3D<Q extends javax.measure.quantity.Quantity>>
- Parameters:
divisor
- the divisor.- Returns:
this / divisor
.
-
cross
public Vector3D cross(Vector that)
Returns the cross product of two 3-dimensional vectors.- Overrides:
cross
in classVector<Parameter<Q extends javax.measure.quantity.Quantity>>
- Parameters:
that
- the vector multiplier.- Returns:
this x that
- Throws:
DimensionException
- if(that.getDimension() != 3)
- See Also:
- Wikipedia: Cross Product
-
divide
public Vector3D<?> divide(Parameter<?> that)
Returns this vector with each element divided by the specified divisor.- Parameters:
that
- the divisor.- Returns:
this / that
.
-
toUnitVector
public Vector3D<javax.measure.quantity.Dimensionless> toUnitVector()
Returns this vector converted to a unit vector by dividing all the vector's elements by the length (AbstractParamVector.norm()
) of this vector.- Specified by:
toUnitVector
in classCoordinate3D<Q extends javax.measure.quantity.Quantity>
- Returns:
- this vector converted to a unit vector
-
copy
public Vector3D<Q> copy()
Returns a copy of this vectorallocated
by the calling thread (possibly on the stack).
-
getUnit
public javax.measure.unit.Unit<Q> getUnit()
Returns the unit in which thevalues
in this vector are stated in.- Specified by:
getUnit
in classAbstractParamVector<Q extends javax.measure.quantity.Quantity,Coordinate3D<Q extends javax.measure.quantity.Quantity>>
- Returns:
- the unit in which the values in this vector are stated
-
to
public <R extends javax.measure.quantity.Quantity> Vector3D<R> to(javax.measure.unit.Unit<R> unit) throws javax.measure.converter.ConversionException
Returns the equivalent to this vector but stated in the specified unit.- Specified by:
to
in classAbstractParamVector<Q extends javax.measure.quantity.Quantity,Coordinate3D<Q extends javax.measure.quantity.Quantity>>
- Type Parameters:
R
- the Quantity (unit type, e.g. Length or Volume) of the returned vector.- Parameters:
unit
- the unit of the vector to be returned.- Returns:
- a vector equivalent to this vector but stated in the specified unit.
- Throws:
javax.measure.converter.ConversionException
- if the current model does not allows for conversion to the specified unit.
-
asType
public <T extends javax.measure.quantity.Quantity> Vector3D<T> asType(java.lang.Class<T> type) throws java.lang.ClassCastException
Casts this Vector3D to a parameterized unit of specified nature or throw aClassCastException
if the dimension of the specified quantity and this parameter's unit dimension do not match.- Specified by:
asType
in classCoordinate3D<Q extends javax.measure.quantity.Quantity>
- Type Parameters:
T
- the Quantity (unit type, e.g. Length or Volume) of the returned vector.- Parameters:
type
- the quantity class identifying the nature of the unit.- Returns:
- this Vector3D parameterized with the specified type.
- Throws:
java.lang.ClassCastException
- if the dimension of this parameter's unit is different from the specified quantity dimension.java.lang.UnsupportedOperationException
- if the specified quantity class does not have a public static field named "UNIT" holding the standard unit for the quantity.
-
toVector3D
public Vector3D<Q> toVector3D()
Returns a Cartesian Vector3D representation of this vector.- Specified by:
toVector3D
in classAbstractParamVector<Q extends javax.measure.quantity.Quantity,Coordinate3D<Q extends javax.measure.quantity.Quantity>>
- Returns:
- a Cartesian Vector3D representation of this vector
-
toFloat64Vector
public Float64Vector toFloat64Vector()
Returns double the values stored in this vector, stated in this vector'sunit
, as a Float64Vector.- Returns:
- the values stored in this vector as a Float64Vector
-
toSkewSymmetric
public Matrix3D<Q> toSkewSymmetric()
Returns a 3x3 skew-symmetric matrix representation of the values in this vector stated in this vector'sunit
.A skew symmetric representation of a vector is defined by:
| 0 -c b| |a| | c 0 -a| <-- |b| |-b a 0| |c|
- Returns:
- a 3x3 skew-symmetric matrix representation of the values in this vector
-
makeSkewSymmetric
public static <R extends javax.measure.quantity.Quantity> Matrix3D<R> makeSkewSymmetric(double a, double b, double c, javax.measure.unit.Unit<R> unit)
Returns a 3x3 skew-symmetric matrix representation of the values in the input 3D vector stated in the specified units.A skew symmetric representation of a vector is defined by:
| 0 -c b| |a| | c 0 -a| <-- |b| |-b a 0| |c|
This is a more efficient convenience method equivalent to:
Vector3D.valueOf(a, b, c, Dimensionless.UNIT).toSkewSymmetric();
- Type Parameters:
R
- the Quantity (unit type, e.g. Length or Volume) of the returned matrix.- Parameters:
a
- The 1st element of the 3D vectorb
- The 2nd element of the 3D vectorc
- The 3rd element of the 3D vectorunit
- The unit that the elements are stated in.- Returns:
- a 3x3 skew-symmetric matrix representation of the values in the input 3D vector.
-
equals
public boolean equals(java.lang.Object obj)
Compares this Vector3D against the specified object for strict equality (same values and same units).
-
hashCode
public int hashCode()
Returns the hash code for this parameter.- Overrides:
hashCode
in classVector<Parameter<Q extends javax.measure.quantity.Quantity>>
- Returns:
- the hash code value.
- See Also:
Vector.equals(org.jscience.mathematics.vector.Vector<F>, java.util.Comparator<F>)
-
main
public static void main(java.lang.String[] args)
Tests the methods in this class.- Parameters:
args
- Command line arguments (ignored).
-
-