Class Vector3D

  • All Implemented Interfaces:
    CoordinateIfc

    public class Vector3D
    extends java.lang.Object
    implements CoordinateIfc
    The Vector3D class implements a 3D vector with the double values x1, x2, x3. Vectors can be thought of as either a (x1, x2, x3) point or at a vector from (0.0, 0.0, 0.0) to (x1, x2, x3)
    • Constructor Summary

      Constructors 
      Constructor Description
      Vector3D()
      Create a new Vector3D at (0.0, 0.0, 0.0)
      Vector3D​(double x1, double x2)
      Create a new Vector3D at (x, y, 0.0)
      Vector3D​(double x1, double x2, double x3)
      Create a new Vector3D at (x, y, z)
      Vector3D​(CoordinateIfc v)
      Create a new Vector3D with the same values as the specfied vector, v
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(double x1, double x2, double x3)
      Adds the given values from the vector
      void add​(CoordinateIfc v)
      Adds the given vector to this vector
      void divide​(double s)
      Divides each element by s
      boolean equals​(double x1, double x2, double x3)
      Checks if this vector is equal to the specified coordinates
      boolean equals​(java.lang.Object obj)
      Checks if this vector is equal to the specified Object They are equal if the specified Object is a Vector3D and the two vectors x, y, z coordinates are equal
      double getX1()  
      double getX2()  
      double getX3()  
      int hashcode()  
      double length()
      The length of the vector
      void multiply​(double s)
      Multiplies each element by s
      static Vector3D newInstance​(CoordinateIfc c)
      Returns a new instance of a Coordinate at the same underlying coordinates as the given coordinate
      void normalize()
      Converts the vector to a unit vector
      void setCoordinates​(double x1, double x2)
      Sets the coordinates of the vector to the values given, x3 is assumed 0.0
      void setCoordinates​(double x1, double x2, double x3)
      Sets the coordinates of the vector to the values given
      void setCoordinates​(CoordinateIfc c)
      Sets the coordinates of this vector to those given by the CoordinateIfc
      void subtract​(double x1, double x2, double x3)
      Subtracts the given values from the vector
      void subtract​(CoordinateIfc v)
      Subtracts the given vector from this vector
      java.lang.String toString()
      Returns the (x,y,z) coordinates as a string "(x1,x2,x3)=(" + x1 + "," + x2 + "," + x3 +")"
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Vector3D

        public Vector3D()
        Create a new Vector3D at (0.0, 0.0, 0.0)
      • Vector3D

        public Vector3D​(CoordinateIfc v)
        Create a new Vector3D with the same values as the specfied vector, v
        Parameters:
        v - the vector to replicate
      • Vector3D

        public Vector3D​(double x1,
                        double x2)
        Create a new Vector3D at (x, y, 0.0)
        Parameters:
        x1 - the 1st coordinate
        x2 - the 2nd coordinate
      • Vector3D

        public Vector3D​(double x1,
                        double x2,
                        double x3)
        Create a new Vector3D at (x, y, z)
        Parameters:
        x1 - the 1st coordinate
        x2 - the 2nd coordinate
        x3 - the 3rd coordinate
    • Method Detail

      • newInstance

        public static final Vector3D newInstance​(CoordinateIfc c)
        Returns a new instance of a Coordinate at the same underlying coordinates as the given coordinate
        Parameters:
        c -
        Returns:
      • equals

        public final boolean equals​(java.lang.Object obj)
        Checks if this vector is equal to the specified Object They are equal if the specified Object is a Vector3D and the two vectors x, y, z coordinates are equal
        Overrides:
        equals in class java.lang.Object
      • hashcode

        public final int hashcode()
      • equals

        public final boolean equals​(double x1,
                                    double x2,
                                    double x3)
        Checks if this vector is equal to the specified coordinates
        Parameters:
        x1 - the 1st coordinate
        x2 - the 2nd coordinate
        x3 - the 3rd coordinate
      • setCoordinates

        public final void setCoordinates​(double x1,
                                         double x2,
                                         double x3)
        Sets the coordinates of the vector to the values given
        Parameters:
        x1 - the 1st coordinate
        x2 - the 2nd coordinate
        x3 - the 3rd coordinate
      • setCoordinates

        public final void setCoordinates​(double x1,
                                         double x2)
        Sets the coordinates of the vector to the values given, x3 is assumed 0.0
        Parameters:
        x1 - the 1st coordinate
        x2 - the 2nd coordinate
      • setCoordinates

        public final void setCoordinates​(CoordinateIfc c)
        Sets the coordinates of this vector to those given by the CoordinateIfc
        Parameters:
        c -
      • add

        public final void add​(double x1,
                              double x2,
                              double x3)
        Adds the given values from the vector
        Parameters:
        x1 - the 1st coordinate
        x2 - the 2nd coordinate
        x3 - the 3rd coordinate
      • subtract

        public final void subtract​(double x1,
                                   double x2,
                                   double x3)
        Subtracts the given values from the vector
        Parameters:
        x1 - the 1st coordinate
        x2 - the 2nd coordinate
        x3 - the 3rd coordinate
      • add

        public final void add​(CoordinateIfc v)
        Adds the given vector to this vector
        Parameters:
        v -
      • subtract

        public final void subtract​(CoordinateIfc v)
        Subtracts the given vector from this vector
        Parameters:
        v -
      • multiply

        public final void multiply​(double s)
        Multiplies each element by s
        Parameters:
        s -
      • divide

        public final void divide​(double s)
        Divides each element by s
        Parameters:
        s - Must not be zero
      • length

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

        public final void normalize()
        Converts the vector to a unit vector
      • toString

        public java.lang.String toString()
        Returns the (x,y,z) coordinates as a string "(x1,x2,x3)=(" + x1 + "," + x2 + "," + x3 +")"
        Overrides:
        toString in class java.lang.Object
      • getX1

        public final double getX1()
        Specified by:
        getX1 in interface CoordinateIfc
        Returns:
        Returns the x1.
      • getX2

        public final double getX2()
        Specified by:
        getX2 in interface CoordinateIfc
        Returns:
        Returns the x2.
      • getX3

        public final double getX3()
        Specified by:
        getX3 in interface CoordinateIfc
        Returns:
        Returns the x3.