Class Vector2d

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<Vector2d>

    public class Vector2d
    extends java.lang.Object
    implements java.lang.Comparable<Vector2d>, java.io.Serializable
    2D Vector object.
    See Also:
    Serialized Form
    • Field Detail

      • ZERO

        public static final Vector2d ZERO
        Zero vector: (0,0)
      • UNIT_X

        public static final Vector2d UNIT_X
        Unit-X vector: (1,0)
      • UNIT_Y

        public static final Vector2d UNIT_Y
        Unit-Y vector: (0,1)
      • ONE

        public static final Vector2d ONE
        One vector: (1,1)
      • X

        public double X
        Vector data X-Component:
      • Y

        public double Y
        Vector data Y-Component:
    • Constructor Detail

      • Vector2d

        public Vector2d()
        construction, defaults to (0,0)
      • Vector2d

        public Vector2d​(double fX,
                        double fY)
        construction
        Parameters:
        fX - x-value
        fY - y-value
      • Vector2d

        public Vector2d​(Vector2d rkV)
        copy construction
        Parameters:
        rkV - vector to copy.
    • Method Detail

      • add

        public Vector2d add​(double fX,
                            double fY)
        Add. this.X = this.X + fX; this.Y = this.Y + fY;
        Parameters:
        fX - x-value to add to this.
        fY - y-value to add to this.
      • add

        public Vector2d add​(Vector2d rkV)
        Add. this = this + rkV
        Parameters:
        rkV - vector to add to this.
      • add

        public static Vector2d add​(Vector2d rkV1,
                                   Vector2d rkV2)
        Add. this = rkV1 + rkV2.
        Parameters:
        rkV1 - first vector.
        rkV2 - second vector.
      • cross

        public double cross​(Vector2d kV)
        Returns Cross((x,y,0),(V.x,V.y,0)) = x*V.y - y*V.x.
        Parameters:
        kV - DOCUMENT ME!
        Returns:
        DOCUMENT ME!
      • dot

        public double dot​(Vector2d rkV)
        Compute dot-product of this vector with input vector:
        Returns:
        dot-product of this vector with input vector:
      • equals

        public boolean equals​(java.lang.Object kObject)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • length

        public double length()
        Compute length this vector:
        Returns:
        length this vector
      • neg

        public Vector2d neg()
        Negate this vector: this = - this.
      • normalize

        public double normalize()
        Normalize this vector, return original length:
        Returns:
        original length:
      • perp

        public Vector2d perp​(Vector2d kVector)
        Set this vector to the 'perp' of the specified vector.
        Parameters:
        kVector - DOCUMENT ME!
      • scale

        public Vector2d scale​(double fScalar)
        Scale this vector by input. this = this * fScalar.
        Parameters:
        fScalar - scale value.
      • scale

        public static Vector2d scale​(double fScalar,
                                     Vector2d rkV)
        Scale the input vector by input. this = rkV * fScalar.
        Parameters:
        fScalar - scale value.
        rkV - input vector.
      • scaleAdd

        public Vector2d scaleAdd​(double fScalar,
                                 Vector2d rkV1,
                                 Vector2d rkV2)
        Scale the input vector by the scalar, setting this: this = fScalar * rkV1 + rkV2.
        Parameters:
        fScalar - scale value
        rkV1 - input vector
        rkV2 - input vector
      • set

        public Vector2d set​(double fX,
                            double fY)
        construction
        Parameters:
        fX - x-value
        fY - y-value
      • squaredLength

        public double squaredLength()
        Compute squared-length this vector:
        Returns:
        squared-length this vector
      • sub

        public Vector2d sub​(double fX,
                            double fY)
        Sub. this.X = this.X - fX; this.Y = this.Y - fY;
        Parameters:
        fX - x-value to subtract from this.
        fY - y-value to subtract from this.
      • sub

        public Vector2d sub​(Vector2d rkV)
        Sub. this = this - rkV
        Parameters:
        rkV - vector to subtact from this.
      • sub

        public static Vector2d sub​(Vector2d rkV1,
                                   Vector2d rkV2)
        Sub. this = rkV1 - rkV2.
        Parameters:
        rkV1 - first vector.
        rkV2 - second vector.
      • sum

        public double sum()
        Sum the elements of the vector.
        Returns:
        vector sum
      • toString

        public java.lang.String toString()
        Returns a string representation of the vector values.
        Overrides:
        toString in class java.lang.Object
        Returns:
        string representation of the vector values.
      • compare

        public int compare​(Vector2d arg0,
                           Vector2d arg1)
        Sorting a list of Vector2d in order, where each element is a column when two Vector2d have equal X then the sort is by Y.
        Parameters:
        arg0 -
        arg1 -
        Returns:
      • compareTo

        public int compareTo​(Vector2d arg0)
        Specified by:
        compareTo in interface java.lang.Comparable<Vector2d>