Class Vector


  • public final class Vector
    extends Object
    A Vector object holds three doubles, which makes it a vector in 3-dimensional space.
    • Field Detail

      • x

        public final double x
      • y

        public final double y
      • z

        public final double z
    • Constructor Detail

      • Vector

        public Vector​(double x,
                      double y,
                      double z)
        Construct a new Vector using the given x, y, and z coordinates.
        Parameters:
        x - x-coordinate of the new Vector
        y - y-coordinate of the new Vector
        z - z-coordinate of the new Vector
      • Vector

        public Vector​(Vertex v)
        Construct a new Vector from a Vertex.
        Parameters:
        v - Vertex object to convert into a Vector
    • Method Detail

      • dotProduct

        public double dotProduct​(Vector v)
        The dot-product of two Vectors returns a scalar.
        Parameters:
        v - Vector object to multiply with this Vector
        Returns:
        a double that is the dot-product of this Vector and v
      • crossProduct

        public Vector crossProduct​(Vector v)
        The cross-product of two Vectors returns a (new) Vector.
        Parameters:
        v - Vector object to multiply with this Vector
        Returns:
        a new Vector object that is the cross-product of this Vector and v
      • times

        public Vector times​(double s)
        A scalar times a Vector returns a (new) Vector.
        Parameters:
        s - number to multiply this Vector by
        Returns:
        a new Vector object that is the scalar times this Vector
      • plus

        public Vector plus​(Vector v)
        A Vector plus a Vector returns a (new) Vector.
        Parameters:
        v - Vector object to add to this Vector
        Returns:
        a new Vector object that is the sum of this Vector and v
      • minus

        public Vector minus​(Vector v)
        A Vector minus a Vector returns a (new) Vector.
        Parameters:
        v - Vector object to subtract from this Vector
        Returns:
        a new Vector object that is this Vector minus v
      • normalize

        public Vector normalize()
        Return the normalized version of this Vector.

        That is, return the Vector with length 1 that points in the same direction as this Vector.

        Returns:
        a new Vector that has length one and has the same direction as this Vector
      • plus

        public Vertex plus​(Vertex v)
        A Vector plus a Vertex returns a (new) Vertex.

        The vector translates the vertex to a new location.

        Parameters:
        v - Vertex object to add to this Vector
        Returns:
        a new Vertex object that is the translation of v by this Vector
      • toString

        public String toString​(int precision)
        For debugging.

        Allow the precision of the formatted output to be specified.

        Parameters:
        precision - precision value for the format string
        Returns:
        String representation of this Vector object
      • toString

        public String toString​(int precision,
                               int iWidth)
        For debugging.

        Allow the precision and width of the formatted output to be specified. By width, we mean the width of the integer part of each number.

        Parameters:
        precision - precision value for the format string
        iWidth - width of the integer part of the format string
        Returns:
        String representation of this Vector object