Class Vector3<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>

java.lang.Object
org.djunits.vecmat.def.VectorMatrix<Q,V,SI,H,VT>
org.djunits.vecmat.def.Vector<Q,V,SI,H,VT>
org.djunits.vecmat.d3.Vector3<Q,V,SI,H,VT>
Type Parameters:
Q - the quantity type
V - the vector type (Col or Row)
SI - the vector type with generics <SIQuantity, SIUnit<
H - the generic vector type with generics <?, ?< for Hadamard operations
VT - the type of the transposed version of the vector
All Implemented Interfaces:
Serializable, Iterable<Q>, Additive<V>, Scalable<V>, Value<V,Q>, Hadamard<H,SI>, Normed<Q>
Direct Known Subclasses:
Vector3.Col, Vector3.Row

public abstract class Vector3<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>> extends Vector<Q,V,SI,H,VT>
Vector3 implements a vector with three 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 Classes
    Modifier and Type
    Class
    Description
    static class 
    Vector3.Col implements a column vector with three real-valued entries.
    static class 
    Vector3.Row implements a row vector with three real-valued entries.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Vector3(double xSi, double ySi, double zSi, Unit<?,Q> displayUnit)
    Create a new Vector3 with a display unit.
  • Method Summary

    Modifier and Type
    Method
    Description
    abs()
    Make the SI-values of this element absolute.
    add(Q increment)
    Return the a vector or matrix with entries that contain the sum of the element and the increment.
    add(V other)
    Add an element to this element, based on the SI-values.
    boolean
     
    Q[]
    Return the vector as an array of scalars.
    double[]
    Return a row-major array of SI-values for this matrix or vector.
    int
     
    instantiateSi(double[] siNew)
    Return a new vector or matrix with the given SI or BASE values.
    protected abstract V
    instantiateSi(double xSiNew, double ySiNew, double zSiNew)
    Return a new column or row vector with adapted x, y and z values.
    abstract boolean
    Return whether this vector is a column vector.
    boolean
    Indicate whether this is a Relative Value.
    Create and return an iterator over the scalars in this vector in proper sequence.
    max()
    Return the maximum value of the entries of the vector or matrix.
    Return the mean value of the entries of the vector or matrix.
    Return the median value of the entries of the vector or matrix.
    min()
    Return the minimum value of the entries of the vector or matrix.
    Negate this element, based on the SI-values.
    int
    Return the number of non-zero entries in the vector, matrix or table.
    Return the L1-norm of this element, expressed as a quantity.
    Return the L2-norm of this element, expressed as a quantity.
    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(int index)
    Retrieve an si-value from the vector.
    int
    Retrieve the size of the vector.
    subtract(Q decrement)
    Return the a vector or matrix with entries that contain the value minus the decrement.
    subtract(V other)
    Subtract an element from this element, based on the SI-values.
    sum()
    Return the sum of the values of the entries of the vector or matrix.
    double[]
    Return a row-major possibly UNSAFE array of SI-values for this matrix or vector.
    x()
    Return the x-value of the vector as a quantity with the correct unit.
    double
    xSi()
    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.
    double
    ySi()
    Return the y-value of the vector in SI or BASE units.
    z()
    Return the z-value of the vector as a quantity with the correct unit.
    double
    zSi()
    Return the z-value of the vector in SI or BASE units.

    Methods inherited from class org.djunits.vecmat.def.Vector

    get, isRowVector, mget, msi

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.djunits.vecmat.operations.Hadamard

    divideEntries

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator

    Methods inherited from interface org.djunits.vecmat.operations.Normed

    norm

    Methods inherited from interface org.djunits.value.Scalable

    divideBy

    Methods inherited from interface org.djunits.value.Value

    format, format, isAbsolute, setDisplayUnit
  • Constructor Details

    • Vector3

      protected Vector3(double xSi, double ySi, double zSi, Unit<?,Q> displayUnit)
      Create a new Vector3 with a display unit.
      Parameters:
      xSi - the x-value expressed in the SI unit
      ySi - the y-value expressed in the SI unit
      zSi - the z-value expressed in the SI unit
      displayUnit - the display unit to use
  • Method Details

    • instantiateSi

      protected abstract V instantiateSi(double xSiNew, double ySiNew, double zSiNew)
      Return a new column or row vector with adapted x, y and z values.
      Parameters:
      xSiNew - the x value to use
      ySiNew - the y value to use
      zSiNew - the z value to use
      Returns:
      a new column or row vector with adapted x, y and z values
    • instantiateSi

      public V instantiateSi(double[] siNew)
      Description copied from class: VectorMatrix
      Return a new vector or matrix with the given SI or BASE values.
      Specified by:
      instantiateSi in class VectorMatrix<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>
      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
    • size

      public int size()
      Description copied from class: Vector
      Retrieve the size of the vector.
      Specified by:
      size in class Vector<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>
      Returns:
      the size of the vector
    • si

      public double si(int index) throws IndexOutOfBoundsException
      Description copied from class: Vector
      Retrieve an si-value from the vector.
      Specified by:
      si in class Vector<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>
      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

      public Iterator<Q> iterator()
      Description copied from class: Vector
      Create and return an iterator over the scalars in this vector in proper sequence.
      Specified by:
      iterator in interface Iterable<Q extends Quantity<Q>>
      Specified by:
      iterator in class Vector<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>
      Returns:
      an iterator over the scalars in this vector in proper sequence
    • getScalarArray

      public Q[] getScalarArray()
      Description copied from class: Vector
      Return the vector as an array of scalars.
      Specified by:
      getScalarArray in class Vector<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>
      Returns:
      the vector as an array of scalars
    • 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
    • zSi

      public double zSi()
      Return the z-value of the vector in SI or BASE units.
      Returns:
      the z-value of the vector in SI or BASE units
    • unsafeSiArray

      public double[] unsafeSiArray()
      Description copied from class: VectorMatrix
      Return a row-major possibly UNSAFE array of SI-values for this matrix or vector. The method might give access to the underlying data structure, so treat the data carefully.
      Specified by:
      unsafeSiArray in class VectorMatrix<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>
      Returns:
      the row-major array of SI-values (safe copy)
    • getSiArray

      public double[] getSiArray()
      Description copied from class: VectorMatrix
      Return a row-major array of SI-values for this matrix or vector. This is guaranteed to be a safe copy.
      Specified by:
      getSiArray in class VectorMatrix<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>
      Returns:
      the row-major array of SI-values (safe copy)
    • x

      public Q 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

      public Q 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
    • z

      public Q z()
      Return the z-value of the vector as a quantity with the correct unit.
      Returns:
      the z-value of the vector as a quantity with the correct unit
    • nonZeroCount

      public int nonZeroCount()
      Description copied from class: VectorMatrix
      Return the number of non-zero entries in the vector, matrix or table. Note that NaN and Infinity count as a non-zero element. The value -0.0 counts as 0.0.
      Specified by:
      nonZeroCount in class VectorMatrix<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>
      Returns:
      the number of non-zero entries in the vector, matrix or table
    • scaleBy

      public V scaleBy(double factor)
      Description copied from interface: Scalable
      Scale 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:
      scaleBy in interface Scalable<Q extends Quantity<Q>>
      Overrides:
      scaleBy in class VectorMatrix<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>
      Parameters:
      factor - the dimensionless scale factor
      Returns:
      a new element with all of its SI-values scaled by the dimensionless factor
    • add

      public V add(V other)
      Description copied from interface: Additive
      Add 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:
      add in interface Additive<Q extends Quantity<Q>>
      Overrides:
      add in class VectorMatrix<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>
      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

      public V subtract(V other)
      Description copied from interface: Additive
      Subtract an element from this element, based on the SI-values.
      Specified by:
      subtract in interface Additive<Q extends Quantity<Q>>
      Overrides:
      subtract in class VectorMatrix<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>
      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

      public V negate()
      Description copied from interface: Additive
      Negate 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:
      negate in interface Additive<Q extends Quantity<Q>>
      Overrides:
      negate in class VectorMatrix<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>
      Returns:
      a new element with all of its SI-values negated
    • abs

      public V abs()
      Description copied from interface: Additive
      Make 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:
      abs in interface Additive<Q extends Quantity<Q>>
      Overrides:
      abs in class VectorMatrix<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>
      Returns:
      a new element with the absolute value for all of its SI-values
    • normL1

      public Q normL1()
      Description copied from interface: Normed
      Return 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

      public Q normL2()
      Description copied from interface: Normed
      Return 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

      public Q normLp(int p)
      Description copied from interface: Normed
      Return 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

      public Q normLinf()
      Description copied from interface: Normed
      Return 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

      public Q mean()
      Description copied from class: VectorMatrix
      Return the mean value of the entries of the vector or matrix.
      Overrides:
      mean in class VectorMatrix<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>
      Returns:
      the mean value of the entries of the vector or matrix
    • min

      public Q min()
      Description copied from class: VectorMatrix
      Return the minimum value of the entries of the vector or matrix.
      Overrides:
      min in class VectorMatrix<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>
      Returns:
      the minimum value of the entries of the vector or matrix
    • max

      public Q max()
      Description copied from class: VectorMatrix
      Return the maximum value of the entries of the vector or matrix.
      Overrides:
      max in class VectorMatrix<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>
      Returns:
      the maximum value of the entries of the vector or matrix
    • median

      public Q median()
      Description copied from class: VectorMatrix
      Return the median value of the entries of the vector or matrix.
      Overrides:
      median in class VectorMatrix<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>
      Returns:
      the median value of the entries of the vector or matrix
    • sum

      public Q sum()
      Description copied from class: VectorMatrix
      Return the sum of the values of the entries of the vector or matrix.
      Overrides:
      sum in class VectorMatrix<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>
      Returns:
      the sum of the values of the entries of the vector or matrix
    • add

      public V add(Q increment)
      Description copied from class: VectorMatrix
      Return the a vector or matrix with entries that contain the sum of the element and the increment.
      Overrides:
      add in class VectorMatrix<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>
      Parameters:
      increment - the quantity by which to increase the values of the vector or matrix
      Returns:
      a vector or matrix with entries that are incremented by the given quantity
    • subtract

      public V subtract(Q decrement)
      Description copied from class: VectorMatrix
      Return the a vector or matrix with entries that contain the value minus the decrement.
      Overrides:
      subtract in class VectorMatrix<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>
      Parameters:
      decrement - the quantity by which to decrease the values of the vector or matrix
      Returns:
      a vector or matrix with entries that are decremented by the given quantity
    • isRelative

      public boolean isRelative()
      Description copied from interface: Value
      Indicate whether this is a Relative Value.
      Specified by:
      isRelative in interface Value<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>>
      Overrides:
      isRelative in class VectorMatrix<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>
      Returns:
      whether this is a Relative Value
    • isColumnVector

      public abstract boolean isColumnVector()
      Return whether this vector is a column vector.
      Specified by:
      isColumnVector in class Vector<Q extends Quantity<Q>,V extends Vector3<Q,V,SI,H,VT>,SI extends Vector3<SIQuantity,SI,?,?,?>,H extends Vector3<?,?,?,?,?>,VT extends Vector3<Q,VT,?,?,V>>
      Returns:
      whether this vector is a column vector
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object