Top Description Methods
org.apache.commons.math3.geometry

public Interface Vector<S extends Space>

extends Point<S extends Space>
Known Direct Implementers
org.apache.commons.math3.geometry.euclidean.oned.Vector1D, org.apache.commons.math3.geometry.euclidean.threed.Vector3D, org.apache.commons.math3.geometry.euclidean.twod.Vector2D
Type Parameters
<S>
Type of the space.
Imports
java.text.NumberFormat, org.apache.commons.math3.exception.MathArithmeticException

This interface represents a generic vector in a vectorial space or a point in an affine space.
Since
3.0
See Also
Space, Point

Method Summary

Modifier and TypeMethod and Description
public Vector<S>

Returns:

a new vector
add
(Vector<S>
vector to add
v
)

Add a vector to the instance.

public Vector<S>

Returns:

a new vector
add
(double
scale factor to apply to v before adding it
factor
,
Vector<S>
vector to add
v
)

Add a scaled vector to the instance.

public double

Returns:

the distance between the instance and p according to the L2 norm
distance
(Vector<S>
second vector
v
)

Compute the distance between the instance and another vector according to the L2 norm.

public double

Returns:

the distance between the instance and p according to the L1 norm
distance1
(Vector<S>
second vector
v
)

Compute the distance between the instance and another vector according to the L1 norm.

public double

Returns:

the distance between the instance and p according to the L∞ norm
distanceInf
(Vector<S>
second vector
v
)

Compute the distance between the instance and another vector according to the L∞ norm.

public double

Returns:

the square of the distance between the instance and p
distanceSq
(Vector<S>
second vector
v
)

Compute the square of the distance between the instance and another vector.

public double

Returns:

the dot product this.v
dotProduct
(Vector<S>
second vector
v
)

Compute the dot-product of the instance and another vector.

public double

Returns:

Euclidean norm for the vector
getNorm
()

Get the L2 norm for the vector.

public double

Returns:

L1 norm for the vector
getNorm1
()

Get the L1 norm for the vector.

public double

Returns:

L∞ norm for the vector
getNormInf
()

Get the L∞ norm for the vector.

public double

Returns:

square of the Euclidean norm for the vector
getNormSq
()

Get the square of the norm for the vector.

public Vector<S>

Returns:

null vector of the vectorial space or origin point of the affine space
getZero
()

Get the null vector of the vectorial space or origin point of the affine space.

public boolean

Returns:

true if any coordinate of this vector is infinite and none are NaN; false otherwise
isInfinite
()

Returns true if any coordinate of this vector is infinite and none are NaN; false otherwise

public Vector<S>

Returns:

a new vector which is opposite to the instance
negate
()

Get the opposite of the instance.

public Vector<S>

Returns:

a new normalized vector
normalize
()

Get a normalized vector aligned with the instance.

public Vector<S>

Returns:

a new vector
scalarMultiply
(double
scalar
a
)

Multiply the instance by a scalar.

public Vector<S>

Returns:

a new vector
subtract
(Vector<S>
vector to subtract
v
)

Subtract a vector from the instance.

public Vector<S>

Returns:

a new vector
subtract
(double
scale factor to apply to v before subtracting it
factor
,
Vector<S>
vector to subtract
v
)

Subtract a scaled vector from the instance.

public String

Returns:

a string representation of this vector
toString
(final NumberFormat
the custom format for components
format
)

Get a string representation of this vector.

Inherited from org.apache.commons.math3.geometry.Point:
distancegetSpaceisNaN

Method Detail

addback to summary
public Vector<S> add(Vector<S> v)

Add a vector to the instance.

Parameters
v:Vector<S>

vector to add

Returns:Vector<S>

a new vector

addback to summary
public Vector<S> add(double factor, Vector<S> v)

Add a scaled vector to the instance.

Parameters
factor:double

scale factor to apply to v before adding it

v:Vector<S>

vector to add

Returns:Vector<S>

a new vector

distanceback to summary
public double distance(Vector<S> v)

Compute the distance between the instance and another vector according to the L2 norm.

Calling this method is equivalent to calling: q.subtract(p).getNorm() except that no intermediate vector is built

Parameters
v:Vector<S>

second vector

Returns:double

the distance between the instance and p according to the L2 norm

distance1back to summary
public double distance1(Vector<S> v)

Compute the distance between the instance and another vector according to the L1 norm.

Calling this method is equivalent to calling: q.subtract(p).getNorm1() except that no intermediate vector is built

Parameters
v:Vector<S>

second vector

Returns:double

the distance between the instance and p according to the L1 norm

distanceInfback to summary
public double distanceInf(Vector<S> v)

Compute the distance between the instance and another vector according to the L∞ norm.

Calling this method is equivalent to calling: q.subtract(p).getNormInf() except that no intermediate vector is built

Parameters
v:Vector<S>

second vector

Returns:double

the distance between the instance and p according to the L∞ norm

distanceSqback to summary
public double distanceSq(Vector<S> v)

Compute the square of the distance between the instance and another vector.

Calling this method is equivalent to calling: q.subtract(p).getNormSq() except that no intermediate vector is built

Parameters
v:Vector<S>

second vector

Returns:double

the square of the distance between the instance and p

dotProductback to summary
public double dotProduct(Vector<S> v)

Compute the dot-product of the instance and another vector.

Parameters
v:Vector<S>

second vector

Returns:double

the dot product this.v

getNormback to summary
public double getNorm()

Get the L2 norm for the vector.

Returns:double

Euclidean norm for the vector

getNorm1back to summary
public double getNorm1()

Get the L1 norm for the vector.

Returns:double

L1 norm for the vector

getNormInfback to summary
public double getNormInf()

Get the L∞ norm for the vector.

Returns:double

L∞ norm for the vector

getNormSqback to summary
public double getNormSq()

Get the square of the norm for the vector.

Returns:double

square of the Euclidean norm for the vector

getZeroback to summary
public Vector<S> getZero()

Get the null vector of the vectorial space or origin point of the affine space.

Returns:Vector<S>

null vector of the vectorial space or origin point of the affine space

isInfiniteback to summary
public boolean isInfinite()

Returns true if any coordinate of this vector is infinite and none are NaN; false otherwise

Returns:boolean

true if any coordinate of this vector is infinite and none are NaN; false otherwise

negateback to summary
public Vector<S> negate()

Get the opposite of the instance.

Returns:Vector<S>

a new vector which is opposite to the instance

normalizeback to summary
public Vector<S> normalize() throws MathArithmeticException

Get a normalized vector aligned with the instance.

Returns:Vector<S>

a new normalized vector

Exceptions
MathArithmeticException:
if the norm is zero
scalarMultiplyback to summary
public Vector<S> scalarMultiply(double a)

Multiply the instance by a scalar.

Parameters
a:double

scalar

Returns:Vector<S>

a new vector

subtractback to summary
public Vector<S> subtract(Vector<S> v)

Subtract a vector from the instance.

Parameters
v:Vector<S>

vector to subtract

Returns:Vector<S>

a new vector

subtractback to summary
public Vector<S> subtract(double factor, Vector<S> v)

Subtract a scaled vector from the instance.

Parameters
factor:double

scale factor to apply to v before subtracting it

v:Vector<S>

vector to subtract

Returns:Vector<S>

a new vector

toStringback to summary
public String toString(final NumberFormat format)

Get a string representation of this vector.

Parameters
format:NumberFormat

the custom format for components

Returns:String

a string representation of this vector