Package org.djunits.vecmat.d2
Class Vector2<Q extends Quantity<Q,U>,U extends UnitInterface<U,Q>,V extends Vector2<Q,U,V,SI,H>,SI extends Vector2<SIQuantity,SIUnit,SI,?,?>,H extends Vector2<?,?,?,?,?>>
java.lang.Object
org.djunits.vecmat.def.VectorMatrix<Q,U,M,SI,H>
org.djunits.vecmat.def.Matrix<Q,U,V,SI,H>
org.djunits.vecmat.def.Vector<Q,U,V,SI,H>
org.djunits.vecmat.d2.Vector2<Q,U,V,SI,H>
- Type Parameters:
Q- the quantity typeU- the unit typeV- the vector type (Row or Col)SI- the vector type with generics <SIQuantity, SIUnit<H- the generic vector type with generics <?, ?< for Hadamard operations
- All Implemented Interfaces:
Serializable,Iterable<Q>,Additive<V>,Scalable<V>,Value<U,,V> Hadamard<H,,SI> Normed<Q,U>
- Direct Known Subclasses:
Vector2.Col,Vector2.Row
public abstract class Vector2<Q extends Quantity<Q,U>,U extends UnitInterface<U,Q>,V extends Vector2<Q,U,V,SI,H>,SI extends Vector2<SIQuantity,SIUnit,SI,?,?>,H extends Vector2<?,?,?,?,?>>
extends Vector<Q,U,V,SI,H>
Vector2 implements a vector with two real-valued entries. The vector is immutable, except for the display unit, which can be
changed. Many of the method that have been defined already for a generic vector have been re-implemented for efficiency.
Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djunits.org. The DJUNITS project is distributed under a three-clause BSD-style license.
- Author:
- Alexander Verbraeck
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classVector2.Col<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>> Vector2.Col implements a column vector with two real-valued entries.static classVector2.Row<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>> Vector2.Row implements a row vector with two real-valued entries. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabs()Make the SI-values of this element absolute.Return the a vector or matrix with entries that contain the sum of the element and the increment.Add an element to this element, based on the SI-values.booleanQ[]Return the vector as an array of scalars.inthashCode()instantiateSi(double[] siNew) Return a new vector or matrix with the given SI or BASE values.protected abstract VinstantiateSi(double xSiNew, double ySiNew) Return a column or row vector with x and y values in SI or BASE units.abstract booleanReturn whether this vector is a column vector.booleanIndicate whether this is a Relative Value.iterator()Create and return an iterator over the scalars in this vector in proper sequence.max()Return the maximum value of the elements of the vector or matrix.mean()Return the mean value of the elements of the vector or matrix.median()Return the median value of the elements of the vector or matrix.min()Return the minimum value of the elements of the vector or matrix.mode()Return the largest value of the elements of the vector or matrix.negate()Negate this element, based on the SI-values.normL1()Return the L1-norm of this element, expressed as a quantity.normL2()Return the L2-norm of this element, expressed as a quantity.normLinf()Return the L∞-norm of this element, expressed as a quantity.normLp(int p) Return the Lp-norm of this element, expressed as a quantity.scaleBy(double factor) Scale the element by a dimensionless factor, based on the SI-values.double[]si()Return the contents of the vector as an array.doublesi(int index) Retrieve an si-value from the vector.intsize()Retrieve the size of the vector.Return the a vector or matrix with entries that contain the value minus the decrement.Subtract an element from this element, based on the SI-values.sum()Return the sum of the values of the elements of the vector or matrix.toString()Return a concise description of this value.Return a concise description of this value with the values expressed in the specified unit.x()Return the x-value of the vector as a quantity with the correct unit.doublexSi()Return the x-value of the vector in SI or BASE units.y()Return the y-value of the vector as a quantity with the correct unit.doubleySi()Return the y-value of the vector in SI or BASE units.Methods inherited from class org.djunits.vecmat.def.Matrix
checkMultiply, checkMultiply, multiplyMethods inherited from class org.djunits.vecmat.def.VectorMatrix
asMatrixNxM, asQuantityTable, checkCol, checkRow, cols, divideElements, divideElements, get, getColumnScalars, getColumnSi, getColumnVector, getDisplayUnit, getRowScalars, getRowSi, getRowVector, getScalarGrid, instantiateSi, invertElements, mcheckCol, mcheckRow, mget, mgetColumnScalars, mgetColumnSi, mgetColumnVector, mgetRowScalars, mgetRowSi, mgetRowVector, msi, multiplyElements, multiplyElements, multiplyElements, rows, setDisplayUnit, siMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djunits.vecmat.operations.Hadamard
divideElementsMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface org.djunits.value.Value
isAbsolute, setDisplayUnit
-
Constructor Details
-
Vector2
Create a new Vector2 with a unit.- Parameters:
xInUnit- the x-value expressed in the given unityInUnit- the y-value expressed in the given unitdisplayUnit- the display unit to use
-
-
Method Details
-
instantiateSi
Return a column or row vector with x and y values in SI or BASE units.- Parameters:
xSiNew- the x value in SI or BASE unitsySiNew- the y value in SI or BASE units- Returns:
- a new column or row vector with adapted x and y values
-
size
public int size()Description copied from class:VectorRetrieve the size of the vector. -
si
Description copied from class:VectorRetrieve an si-value from the vector.- Specified by:
siin classVector<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, V extends Vector2<Q, U, V, SI, H>, SI extends Vector2<SIQuantity, SIUnit, SI, ?, ?>, H extends Vector2<?, ?, ?, ?, ?>> - Parameters:
index- the index (0-based) to retrieve the value from- Returns:
- the value as a Scalar
- Throws:
IndexOutOfBoundsException- in case index is out of bounds
-
iterator
Description copied from class:VectorCreate and return an iterator over the scalars in this vector in proper sequence.- Specified by:
iteratorin interfaceIterable<Q extends Quantity<Q,U>> - Specified by:
iteratorin classVector<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, V extends Vector2<Q, U, V, SI, H>, SI extends Vector2<SIQuantity, SIUnit, SI, ?, ?>, H extends Vector2<?, ?, ?, ?, ?>> - Returns:
- an iterator over the scalars in this vector in proper sequence
-
getScalarArray
Description copied from class:VectorReturn the vector as an array of scalars. -
instantiateSi
Description copied from class:VectorMatrixReturn a new vector or matrix with the given SI or BASE values.- Specified by:
instantiateSiin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, V extends Vector2<Q, U, V, SI, H>, SI extends Vector2<SIQuantity, SIUnit, SI, ?, ?>, H extends Vector2<?, ?, ?, ?, ?>> - Parameters:
siNew- the values for the new vector or matrix in row-major format- Returns:
- a new matrix with the provided SI or BASE values
-
xSi
public double xSi()Return the x-value of the vector in SI or BASE units.- Returns:
- the x-value of the vector in SI or BASE units
-
ySi
public double ySi()Return the y-value of the vector in SI or BASE units.- Returns:
- the y-value of the vector in SI or BASE units
-
si
public double[] si()Return the contents of the vector as an array. -
x
Return the x-value of the vector as a quantity with the correct unit.- Returns:
- the x-value of the vector as a quantity with the correct unit
-
y
Return the y-value of the vector as a quantity with the correct unit.- Returns:
- the y-value of the vector as a quantity with the correct unit
-
scaleBy
Description copied from interface:ScalableScale the element by a dimensionless factor, based on the SI-values. Note that this can lead to unwanted effects for elements with Offset scales. 2 * 10 °C = 293.15 °C and not 20 °C.- Specified by:
scaleByin interfaceScalable<Q extends Quantity<Q,U>> - Overrides:
scaleByin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, V extends Vector2<Q, U, V, SI, H>, SI extends Vector2<SIQuantity, SIUnit, SI, ?, ?>, H extends Vector2<?, ?, ?, ?, ?>> - Parameters:
factor- the dimensionless scale factor- Returns:
- a new element with all of its SI-values scaled by the dimensionless factor
-
add
Description copied from interface:AdditiveAdd an element to this element, based on the SI-values. Note that this can lead to unwanted effects for elements with Offset scales: 10 °C + 5 °C = 288.15 °C and not 15 °C.- Specified by:
addin interfaceAdditive<Q extends Quantity<Q,U>> - Overrides:
addin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, V extends Vector2<Q, U, V, SI, H>, SI extends Vector2<SIQuantity, SIUnit, SI, ?, ?>, H extends Vector2<?, ?, ?, ?, ?>> - Parameters:
other- the element to add to this element- Returns:
- the sum of the SI-values of this element and the SI-values of the other element
-
subtract
Description copied from interface:AdditiveSubtract an element from this element, based on the SI-values.- Specified by:
subtractin interfaceAdditive<Q extends Quantity<Q,U>> - Overrides:
subtractin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, V extends Vector2<Q, U, V, SI, H>, SI extends Vector2<SIQuantity, SIUnit, SI, ?, ?>, H extends Vector2<?, ?, ?, ?, ?>> - Parameters:
other- the element to subtract from this element- Returns:
- a new element with the SI-values of this element minus the SI-values of the other element
-
negate
Description copied from interface:AdditiveNegate this element, based on the SI-values. Note that this can lead to unwanted effects for elements with Offset scales. A temperature in Celsius that is negated, will have its Kelvin temperatures negated.- Specified by:
negatein interfaceAdditive<Q extends Quantity<Q,U>> - Overrides:
negatein classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, V extends Vector2<Q, U, V, SI, H>, SI extends Vector2<SIQuantity, SIUnit, SI, ?, ?>, H extends Vector2<?, ?, ?, ?, ?>> - Returns:
- a new element with all of its SI-values negated
-
abs
Description copied from interface:AdditiveMake the SI-values of this element absolute. A new element wil be returned. Note that this can lead to unwanted effects for elements with Offset scales. A temperature of -10 degrees Celsius will have its Kelvin temperatures negated.- Specified by:
absin interfaceAdditive<Q extends Quantity<Q,U>> - Overrides:
absin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, V extends Vector2<Q, U, V, SI, H>, SI extends Vector2<SIQuantity, SIUnit, SI, ?, ?>, H extends Vector2<?, ?, ?, ?, ?>> - Returns:
- a new element with the absolute value for all of its SI-values
-
normL1
Description copied from interface:NormedReturn the L1-norm of this element, expressed as a quantity. The L1-norm is |x1| + |x2| + ... + |xn|.- Returns:
- the L1-norm of this element, expressed as a quantity
-
normL2
Description copied from interface:NormedReturn the L2-norm of this element, expressed as a quantity. The L2-norm is sqrt(x1^2 + x2^2 + ... + xn^2).- Returns:
- the L2-norm of this element, expressed as a quantity
-
normLp
Description copied from interface:NormedReturn the Lp-norm of this element, expressed as a quantity. The Ln-norm is (x1^p + x2^p + ... + xn^p)^(1/p).- Parameters:
p- the rank of the norm- Returns:
- the Lp-norm of this element, expressed as a quantity
-
normLinf
Description copied from interface:NormedReturn the L∞-norm of this element, expressed as a quantity. The L∞-norm is max(|x1|, |x2|, ..., |xn|).- Returns:
- the L∞-norm of this element, expressed as a quantity
-
mean
Description copied from class:VectorMatrixReturn the mean value of the elements of the vector or matrix. -
min
Description copied from class:VectorMatrixReturn the minimum value of the elements of the vector or matrix. -
max
Description copied from class:VectorMatrixReturn the maximum value of the elements of the vector or matrix. -
mode
Description copied from class:VectorMatrixReturn the largest value of the elements of the vector or matrix. -
median
Description copied from class:VectorMatrixReturn the median value of the elements of the vector or matrix. -
sum
Description copied from class:VectorMatrixReturn the sum of the values of the elements of the vector or matrix. -
add
Description copied from class:VectorMatrixReturn the a vector or matrix with entries that contain the sum of the element and the increment.- Overrides:
addin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, V extends Vector2<Q, U, V, SI, H>, SI extends Vector2<SIQuantity, SIUnit, SI, ?, ?>, H extends Vector2<?, ?, ?, ?, ?>> - Parameters:
increment- the quantity by which to increase the values of the vector or matrix- Returns:
- a vector or matrix with elements that are incremented by the given quantity
-
subtract
Description copied from class:VectorMatrixReturn the a vector or matrix with entries that contain the value minus the decrement.- Overrides:
subtractin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, V extends Vector2<Q, U, V, SI, H>, SI extends Vector2<SIQuantity, SIUnit, SI, ?, ?>, H extends Vector2<?, ?, ?, ?, ?>> - Parameters:
decrement- the quantity by which to decrease the values of the vector or matrix- Returns:
- a vector or matrix with elements that are decremented by the given quantity
-
isRelative
public boolean isRelative()Description copied from interface:ValueIndicate whether this is a Relative Value.- Specified by:
isRelativein interfaceValue<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>> - Overrides:
isRelativein classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, V extends Vector2<Q, U, V, SI, H>, SI extends Vector2<SIQuantity, SIUnit, SI, ?, ?>, H extends Vector2<?, ?, ?, ?, ?>> - Returns:
- whether this is a Relative Value
-
isColumnVector
public abstract boolean isColumnVector()Return whether this vector is a column vector. -
hashCode
public int hashCode() -
equals
-
toString
Description copied from interface:ValueReturn a concise description of this value with the values expressed in the specified unit.- Specified by:
toStringin interfaceValue<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>> - Overrides:
toStringin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, V extends Vector2<Q, U, V, SI, H>, SI extends Vector2<SIQuantity, SIUnit, SI, ?, ?>, H extends Vector2<?, ?, ?, ?, ?>> - Parameters:
withUnit- the unit into which the values are converted for display- Returns:
- a String with the value contents expressed in the specified unit
-
toString
Description copied from interface:ValueReturn a concise description of this value.- Specified by:
toStringin interfaceValue<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>> - Overrides:
toStringin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, V extends Vector2<Q, U, V, SI, H>, SI extends Vector2<SIQuantity, SIUnit, SI, ?, ?>, H extends Vector2<?, ?, ?, ?, ?>> - Returns:
- a String with the value contents, without the type, with the unit attached.
-