Class Vector3D

java.lang.Object
Vector3D
All Implemented Interfaces:
IVector3D

public class Vector3D
extends java.lang.Object
implements IVector3D
  • Field Summary

    Fields
    Modifier and Type Field Description
    static Vector3D I
    The constant vector I: 1i + 0j + 0k
    static Vector3D J
    The constant vector J: 0i + 1j + 0k
    static Vector3D K
    The constant vector K: 0i + oj + 1k
    static double TINY
    Constant for double tolerance
    static Vector3D ZERO
    The zero vector
  • Constructor Summary

    Constructors
    Constructor Description
    Vector3D()
    This makes the zero vector
    Vector3D​(int a, int b, int c)  
  • Method Summary

    Modifier and Type Method Description
    Vector3D add​(Vector3D that)  
    double angleBetween​(Vector3D that)  
    Vector3D cross​(Vector3D that)  
    int dot​(Vector3D that)  
    boolean equals​(java.lang.Object o)  
    double magnitude()  
    static void main​(java.lang.String[] args)  
    Vector3D scalarMultiply​(int scalar)  
    Vector3D subtract​(Vector3D that)  
    java.lang.String toString()  

    Methods inherited from class java.lang.Object

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

    • I

      public static final Vector3D I
      The constant vector I: 1i + 0j + 0k
    • J

      public static final Vector3D J
      The constant vector J: 0i + 1j + 0k
    • K

      public static final Vector3D K
      The constant vector K: 0i + oj + 1k
    • ZERO

      public static final Vector3D ZERO
      The zero vector
    • TINY

      public static final double TINY
      Constant for double tolerance
      See Also:
      Constant Field Values
  • Constructor Details

    • Vector3D

      public Vector3D​(int a, int b, int c)
      Parameters:
      a - the x-component of the vector we are creating
      b - the y-component of the vector we are creating
      c - the z-component of the vector we are creating
    • Vector3D

      public Vector3D()
      This makes the zero vector
  • Method Details

    • dot

      public int dot​(Vector3D that)
      Specified by:
      dot in interface IVector3D
      Parameters:
      that - another Vector3D
      Returns:
      the dot product of this vector and that.
    • cross

      public Vector3D cross​(Vector3D that)
      Specified by:
      cross in interface IVector3D
      Parameters:
      that - another Vector3D
      Returns:
      the cross product of this vector and that.
    • scalarMultiply

      public Vector3D scalarMultiply​(int scalar)
      Specified by:
      scalarMultiply in interface IVector3D
      Parameters:
      scalar - a integer we are scalar multiplying this vector by
      Returns:
      scalar*this
    • add

      public Vector3D add​(Vector3D that)
      Specified by:
      add in interface IVector3D
      Parameters:
      that - a vector we are adding to this vector
      Returns:
      this + that
    • subtract

      public Vector3D subtract​(Vector3D that)
      Specified by:
      subtract in interface IVector3D
      Parameters:
      that - a vector we are subtracting from this vector
      Returns:
      this - that
    • magnitude

      public double magnitude()
      Specified by:
      magnitude in interface IVector3D
      Returns:
      the length of this vector
    • angleBetween

      public double angleBetween​(Vector3D that)
      Specified by:
      angleBetween in interface IVector3D
      Parameters:
      that - another vector
      Returns:
      the angle between this and that in radians in [0,π]
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
      Returns:
      A string representation of the form ai + bj + ck. Make sure you have negative terms not looking like crap.
    • equals

      public boolean equals​(java.lang.Object o)
      Overrides:
      equals in class java.lang.Object
    • main

      public static void main​(java.lang.String[] args)