inra.ijpb.measure

## Class Vector3d

• java.lang.Object
• inra.ijpb.measure.Vector3d

• ```public class Vector3d
extends java.lang.Object```
Represents a triplet of coordinates in linear space, and provides some computing methods. The class is immutable.
Author:
dlegland
• ### Constructor Summary

Constructors
Constructor and Description
`Vector3d()`
Empty constructor, with all coordinates initialized to zero.
```Vector3d(double x, double y, double z)```
Initialization constructor.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`boolean` ```almostEquals(Vector3d v, double eps)```
Checks if this vector is close to the given vector, by checking each coordinate using the given threshold.
`static double` ```angle(Vector3d v1, Vector3d v2)```
Computes the angle between two 3D vectors.
`static Vector3d` ```crossProduct(Vector3d v1, Vector3d v2)```
Computes the cross product of the two vectors.
`static double` ```dotProduct(Vector3d v1, Vector3d v2)```
Computes the dot product of two vectors, defined by:
`double` `getNorm()`
Computes the norm of the vector, given as the square root of the sum of squared coordinates.
`double` `getX()`
Returns the x coordinate of the vector.
`double` `getY()`
Returns the y coordinate of the vector.
`double` `getZ()`
Returns the z coordinate of the vector.
`Vector3d` `minus(Vector3d v)`
Returns the result of the subtraction of this vector with another vector.
`Vector3d` `normalize()`
Returns a normalized vector with same direction as this vector
`Vector3d` `plus(Vector3d v)`
Returns the result of the addition of this vector with another vector.
`Vector3d` `times(double k)`
Returns the result of the multiplication of this vector with a scalar value.
• ### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Constructor Detail

• #### Vector3d

`public Vector3d()`
Empty constructor, with all coordinates initialized to zero.
• #### Vector3d

```public Vector3d(double x,
double y,
double z)```
Initialization constructor.
Parameters:
`x` - the x coordinate
`y` - the y coordinate
`z` - the z coordinate
• ### Method Detail

• #### crossProduct

```public static final Vector3d crossProduct(Vector3d v1,
Vector3d v2)```
Computes the cross product of the two vectors. Cross product is zero for colinear vectors.
Parameters:
`v1` - the first vector
`v2` - the second vector
Returns:
the cross product of the two vectors
• #### dotProduct

```public static final double dotProduct(Vector3d v1,
Vector3d v2)```
Computes the dot product of two vectors, defined by:

` x1 * x2 + y1 * y2 + z1 * z2`

Dot product is zero if the vectors are orthogonal. It is positive if vectors are in the same direction, and negative if they are in opposite direction.

Parameters:
`v1` - the first vector
`v2` - the second vector
Returns:
the dot product of the two vectors
• #### angle

```public static final double angle(Vector3d v1,
Vector3d v2)```
Computes the angle between two 3D vectors. The result is given between 0 and PI.
Parameters:
`v1` - the first vector
`v2` - the second vector
Returns:
the angle between the two vectors, in radians
• #### getX

`public double getX()`
Returns the x coordinate of the vector.
Returns:
the x coordinate of the vector
• #### getY

`public double getY()`
Returns the y coordinate of the vector.
Returns:
the y coordinate of the vector
• #### getZ

`public double getZ()`
Returns the z coordinate of the vector.
Returns:
the z coordinate of the vector
• #### plus

`public Vector3d plus(Vector3d v)`
Returns the result of the addition of this vector with another vector.
Parameters:
`v` - the vector to add
Returns:
the results of the vector addition
• #### minus

`public Vector3d minus(Vector3d v)`
Returns the result of the subtraction of this vector with another vector.
Parameters:
`v` - the vector to subtract
Returns:
the results of the vector subtraction
• #### times

`public Vector3d times(double k)`
Returns the result of the multiplication of this vector with a scalar value.
Parameters:
`k` - the scalar coefficient
Returns:
the results of scalar multiplication
• #### normalize

`public Vector3d normalize()`
Returns a normalized vector with same direction as this vector
Returns:
the normalized vector with same direction as this.
• #### getNorm

`public double getNorm()`
Computes the norm of the vector, given as the square root of the sum of squared coordinates.
Returns:
the norm of the vector
• #### almostEquals

```public boolean almostEquals(Vector3d v,
double eps)```
Checks if this vector is close to the given vector, by checking each coordinate using the given threshold.
Parameters:
`v` - the vector to compare to
`eps` - the absolute tolerance for comparing coodinates
Returns:
true if vector have same coordinates with respect to tolerance