Class Vector3D

java.lang.Object
inra.ijpb.geometry.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 Description
    Vector3D()
    Empty constructor, with all coordinates initialized to zero.
    Vector3D​(double x, double y, double z)
    Initialization constructor.
  • Method Summary

    Modifier and Type Method 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 Details

    • 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 Details

    • 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