Class Vector

java.lang.Object
cnuphys.adaptiveSwim.geometry.Point
cnuphys.adaptiveSwim.geometry.Vector

public class Vector extends Point
Ordinary 3D vector
Author:
heddle
  • Constructor Details

    • Vector

      public Vector()
      Create a new vetor with a zero components
    • Vector

      public Vector(Point p)
      Create a Vector from a point
      Parameters:
      p - the point
    • Vector

      public Vector(double x, double y, double z)
      Create a vector
      Parameters:
      x - the x coordinate
      y - the y coordinate
      z - the z coordinate
  • Method Details

    • lengthSquared

      public double lengthSquared()
      The square of the length of the vector
      Returns:
      the square of the length of the vector
    • length

      public double length()
      The length of the vector
      Returns:
      the length of the vector
    • set

      public void set(double x, double y, double z)
      Set the components of the vector
      Overrides:
      set in class Point
      Parameters:
      x - the x component
      y - the y component
      z - the z component
    • cross

      public static Vector cross(Vector a, Vector b)
      The cross product of two vectors
      Parameters:
      a - one vector
      b - other vector
      Returns:
      c = a x b
    • cross

      public static void cross(Vector a, Vector b, Vector c)
      The in-place cross product of two vectors
      Parameters:
      a - one vector
      b - other vector
      c - on return c = a x b
    • scale

      public void scale(double scaleFactor)
      Scale a vector
      Parameters:
      scaleFactor - the scale factor
    • angleBetween

      public static double angleBetween(Vector a, Vector b)
      Compute the angle between two vectors in radians
      Parameters:
      a - one vector
      b - the other vector
      Returns:
      the angle between two vectors in radians
    • angleBetweenDeg

      public static double angleBetweenDeg(Vector a, Vector b)
      Compute the angle between two vectors in degrees
      Parameters:
      a - one vector
      b - the other vector
      Returns:
      the angle between two vectors in degrees
    • unitVector

      public Vector unitVector()
      Get a unit vector in the same direction as this
      Returns:
      a unit vector
    • project

      public static Vector project(Vector a, Vector b)
      project vector a in the direction of vector b
      Parameters:
      a - the vector to project
      b - the vector whose direction we project on
      Returns:
      the projection of a
    • difference

      public static Vector difference(Vector a, Vector b)
      Get the difference between two vectors
      Parameters:
      a - one vector
      b - the other vector
      Returns:
      the difference between two vectors a - b
    • difference

      public static void difference(Vector a, Vector b, Vector c)
      Get the in-place difference between two vectors
      Parameters:
      a - one vector
      b - the other vector
      c - upon return the difference between two vectors a - b