Class Vector3d

java.lang.Object
ffx.numerics.quickhull.Vector3d
Direct Known Subclasses:
Point3d

public class Vector3d extends Object
A three-element vector. This class is actually a reduced version of the Vector3d class contained in the author's matlib package (which was partly inspired by javax.vecmath). Only a mininal number of methods which are relevant to convex hull generation are supplied here.
Since:
1.0
Author:
John E. Lloyd, Fall 2004, Michael J. Schnieders
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    double
    First element
    double
    Second element
    double
    Third element
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a 3-vector and initializes its elements to 0.
    Vector3d(double x, double y, double z)
    Creates a 3-vector with the supplied element values.
    Creates a 3-vector by copying an existing one.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds this vector to v1 and places the result in this vector.
    void
    Adds vector v1 to v2 and places the result in this vector.
    void
    Computes the cross product of v1 and v2 and places the result in this vector.
    double
    Returns the Euclidean distance between this vector and vector v.
    double
    Returns the squared of the Euclidean distance between this vector and vector v.
    double
    Returns the dot product of this vector and v1.
    double
    get(int i)
    Gets a single element of this vector.
    double
    Returns the 2 norm of this vector.
    void
    Normalizes this vector in place.
    double
    Returns the square of the 2 norm of this vector.
    void
    scale(double s)
    Scales the elements of this vector by s.
    void
    scale(double s, Vector3d v1)
    Scales the elements of vector v1 by s and places the results in this vector.
    void
    set(double x, double y, double z)
    Sets the elements of this vector to the prescribed values.
    void
    set(int i, double value)
    Sets a single element of this vector.
    void
    Sets the values of this vector to those of v1.
    protected void
    setRandom(double lower, double upper, Random generator)
    Sets the elements of this vector to uniformly distributed random values in a specified range, using a supplied random number generator.
    void
    Sets the elements of this vector to zero.
    void
    Subtracts v1 from this vector and places the result in this vector.
    void
    Subtracts vector v1 from v2 and places the result in this vector.
    Returns a string representation of this vector, consisting of the x, y, and z coordinates.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • x

      public double x
      First element
    • y

      public double y
      Second element
    • z

      public double z
      Third element
  • Constructor Details

    • Vector3d

      public Vector3d()
      Creates a 3-vector and initializes its elements to 0.
    • Vector3d

      public Vector3d(Vector3d v)
      Creates a 3-vector by copying an existing one.
      Parameters:
      v - vector to be copied
    • Vector3d

      public Vector3d(double x, double y, double z)
      Creates a 3-vector with the supplied element values.
      Parameters:
      x - first element
      y - second element
      z - third element
  • Method Details

    • get

      public double get(int i)
      Gets a single element of this vector. Elements 0, 1, and 2 correspond to x, y, and z.
      Parameters:
      i - element index
      Returns:
      element value throws ArrayIndexOutOfBoundsException if i is not in the range 0 to 2.
    • set

      public void set(int i, double value)
      Sets a single element of this vector. Elements 0, 1, and 2 correspond to x, y, and z. Element value throws ArrayIndexOutOfBoundsException if i is not in the range 0 to 2.
      Parameters:
      i - element index
      value - element value
    • set

      public void set(Vector3d v1)
      Sets the values of this vector to those of v1.
      Parameters:
      v1 - vector whose values are copied
    • add

      public void add(Vector3d v1, Vector3d v2)
      Adds vector v1 to v2 and places the result in this vector.
      Parameters:
      v1 - left-hand vector
      v2 - right-hand vector
    • add

      public void add(Vector3d v1)
      Adds this vector to v1 and places the result in this vector.
      Parameters:
      v1 - right-hand vector
    • sub

      public void sub(Vector3d v1, Vector3d v2)
      Subtracts vector v1 from v2 and places the result in this vector.
      Parameters:
      v1 - left-hand vector
      v2 - right-hand vector
    • sub

      public void sub(Vector3d v1)
      Subtracts v1 from this vector and places the result in this vector.
      Parameters:
      v1 - right-hand vector
    • scale

      public void scale(double s)
      Scales the elements of this vector by s.
      Parameters:
      s - scaling factor
    • scale

      public void scale(double s, Vector3d v1)
      Scales the elements of vector v1 by s and places the results in this vector.
      Parameters:
      s - scaling factor
      v1 - vector to be scaled
    • norm

      public double norm()
      Returns the 2 norm of this vector. This is the square root of the sum of the squares of the elements.
      Returns:
      vector 2 norm
    • normSquared

      public double normSquared()
      Returns the square of the 2 norm of this vector. This is the sum of the squares of the elements.
      Returns:
      square of the 2 norm
    • distance

      public double distance(Vector3d v)
      Returns the Euclidean distance between this vector and vector v.
      Returns:
      distance between this vector and v
    • distanceSquared

      public double distanceSquared(Vector3d v)
      Returns the squared of the Euclidean distance between this vector and vector v.
      Returns:
      squared distance between this vector and v
    • dot

      public double dot(Vector3d v1)
      Returns the dot product of this vector and v1.
      Parameters:
      v1 - right-hand vector
      Returns:
      dot product
    • normalize

      public void normalize()
      Normalizes this vector in place.
    • setZero

      public void setZero()
      Sets the elements of this vector to zero.
    • set

      public void set(double x, double y, double z)
      Sets the elements of this vector to the prescribed values.
      Parameters:
      x - value for first element
      y - value for second element
      z - value for third element
    • cross

      public void cross(Vector3d v1, Vector3d v2)
      Computes the cross product of v1 and v2 and places the result in this vector.
      Parameters:
      v1 - left-hand vector
      v2 - right-hand vector
    • setRandom

      protected void setRandom(double lower, double upper, Random generator)
      Sets the elements of this vector to uniformly distributed random values in a specified range, using a supplied random number generator.
      Parameters:
      lower - lower random value (inclusive)
      upper - upper random value (exclusive)
      generator - random number generator
    • toString

      public String toString()
      Returns a string representation of this vector, consisting of the x, y, and z coordinates.
      Overrides:
      toString in class Object
      Returns:
      string representation