Class Vector3D

java.lang.Object
ucar.nc2.dt.ugrid.geom.Vector3D

public class Vector3D extends Object
Holds the u, v and w components of a vector as well as it's origin (Point3D).

The class also provides methods to perform mathematical operations on this and other vectors (addition, subtraction, multiplication, division, cross multiplication, and dot multiplication)

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance of Vector3D with an origin of (0, 0, 0) and no magnitude (u=0, v=0, w=0)
    Vector3D(double u, double v, double w)
    Creates a new instance of Vector3D with an origin of (0, 0, 0) and the specified u, v, and w magnitudes.
    Vector3D(Point3D origin, double u, double v, double w)
    Creates a new instance of Vector3D with the specified origin and u, v, and w magnitudes.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Vector3D
    Adds the numerical value of each component of the first vector with the values in the second vector.
    cross(Vector3D other)
    Determines the cross product of this Vector3D with the one given
    static Vector3D
    Determines the cross product of the two given vectors
    static Vector3D
    div(Vector3D v, double d)
    Divides the numerical value of each component of the vector by a given scalar.
    double
    dot(Vector3D other)
    Determines the dot product of this Vector3D with the one given
    static double
    Determines the dot product of the two given vectors
    Gets the Point3D indicated by applying the vector (u, v, w) components to the origin
    double
    Gets the magnitude of this Vector3D.
    Gets the origin of this Vector3D
    double
    Returns the u component of the vector.
    double
    Returns the v component of the vector.
    double
    Returns the w component of the vector.
    static Vector3D
    mult(Vector3D v, double d)
    Multiplies the numerical value of each component of the vector by a given scalar.
    void
    Sets the origin of this Vector3D
    void
    setU(double u)
    Sets the u component of the vector.
    void
    setV(double v)
    Sets the v component of the vector.
    void
    setW(double w)
    Sets the w component of the vector.
    static Vector3D
    Subtracts the numerical value of each component of the second vector from the values in the first vector.
    Builds a descriptive string presenting the u, v, and w components of this vector

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Vector3D

      public Vector3D()
      Creates a new instance of Vector3D with an origin of (0, 0, 0) and no magnitude (u=0, v=0, w=0)
    • Vector3D

      public Vector3D(double u, double v, double w)
      Creates a new instance of Vector3D with an origin of (0, 0, 0) and the specified u, v, and w magnitudes.
      Parameters:
      u - The double u-component of the vector.
      v - The double v-component of the vector.
      w - The double w-component of the vector.
    • Vector3D

      public Vector3D(Point3D origin, double u, double v, double w)
      Creates a new instance of Vector3D with the specified origin and u, v, and w magnitudes.
      Parameters:
      origin - the Point3D origin of the vector.
      u - The double u-component of the vector.
      v - The double v-component of the vector.
      w - The double w-component of the vector.
  • Method Details

    • getOrigin

      public Point3D getOrigin()
      Gets the origin of this Vector3D
      Returns:
      the origin
    • setOrigin

      public void setOrigin(Point3D origin)
      Sets the origin of this Vector3D
      Parameters:
      origin - the new origin
    • getU

      public double getU()
      Returns the u component of the vector.
      Returns:
      double The u component.
    • setU

      public void setU(double u)
      Sets the u component of the vector.
      Parameters:
      u - double The u component.
    • getV

      public double getV()
      Returns the v component of the vector.
      Returns:
      double The v component.
    • setV

      public void setV(double v)
      Sets the v component of the vector.
      Parameters:
      v - double The v component.
    • getW

      public double getW()
      Returns the w component of the vector.
      Returns:
      double The w component.
    • setW

      public void setW(double w)
      Sets the w component of the vector.
      Parameters:
      w - double The w component.
    • toString2

      public String toString2()
      Builds a descriptive string presenting the u, v, and w components of this vector
      Returns:
      a descriptive String
    • getMagnitude

      public double getMagnitude()
      Gets the magnitude of this Vector3D.

      NOTE: Units are NOT considered, the units of magnitude are the same as those of the vector components.

      Returns:
      the vector magnitude
    • getEndPoint

      public Point3D getEndPoint()
      Gets the Point3D indicated by applying the vector (u, v, w) components to the origin

      NOTE: Units are NOT considered. The units of the origin and (u, v, w) components are assumed to be the same.
      Therefore conversions (i.e. from DD to Meters) should happen BEFORE calling this method.

      Returns:
      the end point.
    • add

      public static Vector3D add(Vector3D v1, Vector3D v2)
      Adds the numerical value of each component of the first vector with the values in the second vector.
      Parameters:
      v1 - the first Vector3D
      v2 - the second Vector3D
      Returns:
      a Vector3D representing the addition of the two vectors
    • sub

      public static Vector3D sub(Vector3D v1, Vector3D v2)
      Subtracts the numerical value of each component of the second vector from the values in the first vector.
      Parameters:
      v1 - the first Vector3D
      v2 - the second Vector3D
      Returns:
      a Vector3D representing the subtraction of the two vectors
    • mult

      public static Vector3D mult(Vector3D v, double d)
      Multiplies the numerical value of each component of the vector by a given scalar.
      Parameters:
      v - the Vector3D
      d - the value to multiply the vector by
      Returns:
      a Vector3D representing the rescaled vector
    • div

      public static Vector3D div(Vector3D v, double d)
      Divides the numerical value of each component of the vector by a given scalar.
      Parameters:
      v - the Vector3D
      d - the value to divide the vector by
      Returns:
      a Vector3D representing the rescaled vector
    • cross

      public static Vector3D cross(Vector3D v1, Vector3D v2)
      Determines the cross product of the two given vectors
      Parameters:
      v1 - the first Vector3D
      v2 - the second Vector3D
      Returns:
      a Vector3D which is perpendicular to the plane containing the given vector's. i.e. Cross product.
    • cross

      public Vector3D cross(Vector3D other)
      Determines the cross product of this Vector3D with the one given
      Parameters:
      other - another Vector3D
      Returns:
      a Vector3D representing the cross product of this vector and the one given
    • dot

      public static double dot(Vector3D v1, Vector3D v2)
      Determines the dot product of the two given vectors
      Parameters:
      v1 - the first Vector3D
      v2 - the second Vector3D
      Returns:
      a Vector3D which represents the dot product of the given vectors.
    • dot

      public double dot(Vector3D other)
      Determines the dot product of this Vector3D with the one given
      Parameters:
      other - another Vector3D
      Returns:
      a Vector3D representing the dot product of this vector and the one given