Package org.joml

Class Vector2d

  • All Implemented Interfaces:
    java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, Vector2dc

    public class Vector2d
    extends java.lang.Object
    implements java.io.Externalizable, java.lang.Cloneable, Vector2dc
    Represents a 2D vector with double-precision.
    Author:
    RGreenlees, Kai Burjack, F. Neurath
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      double x
      The x component of the vector.
      double y
      The y component of the vector.
    • Constructor Summary

      Constructors 
      Constructor Description
      Vector2d()
      Create a new Vector2d and initialize its components to zero.
      Vector2d​(double d)
      Create a new Vector2d and initialize both of its components with the given value.
      Vector2d​(double[] xy)
      Create a new Vector2d and initialize its two components from the first two elements of the given array.
      Vector2d​(double x, double y)
      Create a new Vector2d and initialize its components to the given values.
      Vector2d​(float[] xy)
      Create a new Vector2d and initialize its two components from the first two elements of the given array.
      Vector2d​(int index, java.nio.ByteBuffer buffer)
      Create a new Vector2d and read this vector from the supplied ByteBuffer starting at the specified absolute buffer position/index.
      Vector2d​(int index, java.nio.DoubleBuffer buffer)
      Create a new Vector2d and read this vector from the supplied DoubleBuffer starting at the specified absolute buffer position/index.
      Vector2d​(java.nio.ByteBuffer buffer)
      Create a new Vector2d and read this vector from the supplied ByteBuffer at the current buffer position.
      Vector2d​(java.nio.DoubleBuffer buffer)
      Create a new Vector2d and read this vector from the supplied DoubleBuffer at the current buffer position.
      Vector2d​(Vector2dc v)
      Create a new Vector2d and initialize its components to the one of the given vector.
      Vector2d​(Vector2fc v)
      Create a new Vector2d and initialize its components to the one of the given vector.
      Vector2d​(Vector2ic v)
      Create a new Vector2d and initialize its components to the one of the given vector.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Vector2d absolute()
      Set this vector's components to their respective absolute values.
      Vector2d absolute​(Vector2d dest)
      Compute the absolute of each of this vector's components and store the result into dest.
      Vector2d add​(double x, double y)
      Add (x, y) to this vector.
      Vector2d add​(double x, double y, Vector2d dest)
      Add (x, y) to this vector and store the result in dest.
      Vector2d add​(Vector2dc v)
      Add v to this vector.
      Vector2d add​(Vector2dc v, Vector2d dest)
      Add v to this vector and store the result in dest.
      Vector2d add​(Vector2fc v)
      Add v to this vector.
      Vector2d add​(Vector2fc v, Vector2d dest)
      Add v to this vector and store the result in dest.
      double angle​(Vector2dc v)
      Return the angle between this vector and the supplied vector.
      Vector2d ceil()
      Set each component of this vector to the smallest (closest to negative infinity) double value that is greater than or equal to that component and is equal to a mathematical integer.
      Vector2d ceil​(Vector2d dest)
      Compute for each component of this vector the smallest (closest to negative infinity) double value that is greater than or equal to that component and is equal to a mathematical integer and store the result in dest.
      java.lang.Object clone()  
      double distance​(double x, double y)
      Return the distance between this vector and (x, y).
      static double distance​(double x1, double y1, double x2, double y2)
      Return the distance between (x1, y1) and (x2, y2).
      double distance​(Vector2dc v)
      Return the distance between this and v.
      double distance​(Vector2fc v)
      Return the distance between this and v.
      double distanceSquared​(double x, double y)
      Return the distance squared between this vector and (x, y).
      static double distanceSquared​(double x1, double y1, double x2, double y2)
      Return the squared distance between (x1, y1) and (x2, y2).
      double distanceSquared​(Vector2dc v)
      Return the distance squared between this and v.
      double distanceSquared​(Vector2fc v)
      Return the distance squared between this and v.
      Vector2d div​(double scalar)
      Divide this Vector2d by the given scalar value.
      Vector2d div​(double x, double y)
      Divide the components of this Vector2d by the given scalar values and store the result in this.
      Vector2d div​(double x, double y, Vector2d dest)
      Divide the components of this Vector3f by the given scalar values and store the result in dest.
      Vector2d div​(double scalar, Vector2d dest)
      Divide this Vector2d by the given scalar value and store the result in dest.
      Vector2d div​(Vector2d v)
      Divide this Vector2d component-wise by another Vector2dc.
      Vector2d div​(Vector2dc v, Vector2d dest)
      Divide this by v component-wise and store the result into dest.
      Vector2d div​(Vector2fc v)
      Divide this Vector3d component-wise by another Vector2fc.
      Vector2d div​(Vector2fc v, Vector2d dest)
      Divide this Vector2d component-wise by another Vector2f and store the result in dest.
      double dot​(Vector2dc v)
      Return the dot product of this vector and v.
      boolean equals​(double x, double y)
      Compare the vector components of this vector with the given (x, y) and return whether all of them are equal.
      boolean equals​(java.lang.Object obj)  
      boolean equals​(Vector2dc v, double delta)
      Compare the vector components of this vector with the given vector using the given delta and return whether all of them are equal within a maximum difference of delta.
      Vector2d floor()
      Set each component of this vector to the largest (closest to positive infinity) double value that is less than or equal to that component and is equal to a mathematical integer.
      Vector2d floor​(Vector2d dest)
      Compute for each component of this vector the largest (closest to positive infinity) double value that is less than or equal to that component and is equal to a mathematical integer and store the result in dest.
      Vector2d fma​(double a, Vector2dc b)
      Add the component-wise multiplication of a * b to this vector.
      Vector2d fma​(double a, Vector2dc b, Vector2d dest)
      Add the component-wise multiplication of a * b to this vector and store the result in dest.
      Vector2d fma​(Vector2dc a, Vector2dc b)
      Add the component-wise multiplication of a * b to this vector.
      Vector2d fma​(Vector2dc a, Vector2dc b, Vector2d dest)
      Add the component-wise multiplication of a * b to this vector and store the result in dest.
      double get​(int component)
      Get the value of the specified component of this vector.
      java.nio.ByteBuffer get​(int index, java.nio.ByteBuffer buffer)
      Store this vector into the supplied ByteBuffer starting at the specified absolute buffer position/index.
      java.nio.DoubleBuffer get​(int index, java.nio.DoubleBuffer buffer)
      Store this vector into the supplied DoubleBuffer starting at the specified absolute buffer position/index.
      Vector2i get​(int mode, Vector2i dest)
      Set the components of the given vector dest to those of this vector using the given RoundingMode.
      java.nio.ByteBuffer get​(java.nio.ByteBuffer buffer)
      Store this vector into the supplied ByteBuffer at the current buffer position.
      java.nio.DoubleBuffer get​(java.nio.DoubleBuffer buffer)
      Store this vector into the supplied DoubleBuffer at the current buffer position.
      Vector2d get​(Vector2d dest)
      Set the components of the given vector dest to those of this vector.
      Vector2f get​(Vector2f dest)
      Set the components of the given vector dest to those of this vector.
      Vector2dc getToAddress​(long address)
      Store this vector at the given off-heap memory address.
      int hashCode()  
      boolean isFinite()
      Determine whether all components are finite floating-point values, that is, they are not NaN and not infinity.
      double length()
      Return the length of this vector.
      static double length​(double x, double y)
      Get the length of a 2-dimensional double-precision vector.
      double lengthSquared()
      Return the length squared of this vector.
      static double lengthSquared​(double x, double y)
      Get the length squared of a 2-dimensional double-precision vector.
      Vector2d lerp​(Vector2dc other, double t)
      Linearly interpolate this and other using the given interpolation factor t and store the result in this.
      Vector2d lerp​(Vector2dc other, double t, Vector2d dest)
      Linearly interpolate this and other using the given interpolation factor t and store the result in dest.
      Vector2d max​(Vector2dc v)
      Set the components of this vector to be the component-wise maximum of this and the other vector.
      Vector2d max​(Vector2dc v, Vector2d dest)
      Set the components of dest to be the component-wise maximum of this and the other vector.
      int maxComponent()
      Determine the component with the biggest absolute value.
      Vector2d min​(Vector2dc v)
      Set the components of this vector to be the component-wise minimum of this and the other vector.
      Vector2d min​(Vector2dc v, Vector2d dest)
      Set the components of dest to be the component-wise minimum of this and the other vector.
      int minComponent()
      Determine the component with the smallest (towards zero) absolute value.
      Vector2d mul​(double scalar)
      Multiply the components of this vector by the given scalar.
      Vector2d mul​(double x, double y)
      Multiply the components of this Vector2d by the given scalar values and store the result in this.
      Vector2d mul​(double x, double y, Vector2d dest)
      Multiply the components of this Vector2d by the given scalar values and store the result in dest.
      Vector2d mul​(double scalar, Vector2d dest)
      Multiply the components of this vector by the given scalar and store the result in dest.
      Vector2d mul​(Matrix2dc mat)
      Multiply the given matrix mat with this Vector2d.
      Vector2d mul​(Matrix2dc mat, Vector2d dest)
      Multiply the given matrix mat with this and store the result in dest.
      Vector2d mul​(Matrix2fc mat)
      Multiply the given matrix mat with this Vector2d.
      Vector2d mul​(Matrix2fc mat, Vector2d dest)
      Multiply the given matrix mat with this and store the result in dest.
      Vector2d mul​(Vector2dc v)
      Multiply this Vector2d component-wise by another Vector2d.
      Vector2d mul​(Vector2dc v, Vector2d dest)
      Multiply this Vector2d component-wise by another Vector2d and store the result in dest.
      Vector2d mulDirection​(Matrix3x2dc mat)
      Multiply the given 3x2 matrix mat with this.
      Vector2d mulDirection​(Matrix3x2dc mat, Vector2d dest)
      Multiply the given 3x2 matrix mat with this and store the result in dest.
      Vector2d mulPosition​(Matrix3x2dc mat)
      Multiply the given 3x2 matrix mat with this.
      Vector2d mulPosition​(Matrix3x2dc mat, Vector2d dest)
      Multiply the given 3x2 matrix mat with this and store the result in dest.
      Vector2d mulTranspose​(Matrix2dc mat)
      Multiply the transpose of the given matrix with this Vector2d and store the result in this.
      Vector2d mulTranspose​(Matrix2dc mat, Vector2d dest)
      Multiply the transpose of the given matrix with this Vector2f and store the result in dest.
      Vector2d mulTranspose​(Matrix2fc mat)
      Multiply the transpose of the given matrix with this Vector2d and store the result in this.
      Vector2d mulTranspose​(Matrix2fc mat, Vector2d dest)
      Multiply the transpose of the given matrix with this Vector2f and store the result in dest.
      Vector2d negate()
      Negate this vector.
      Vector2d negate​(Vector2d dest)
      Negate this vector and store the result in dest.
      Vector2d normalize()
      Normalize this vector.
      Vector2d normalize​(double length)
      Scale this vector to have the given length.
      Vector2d normalize​(double length, Vector2d dest)
      Scale this vector to have the given length and store the result in dest.
      Vector2d normalize​(Vector2d dest)
      Normalize this vector and store the result in dest.
      Vector2d perpendicular()
      Set this vector to be one of its perpendicular vectors.
      void readExternal​(java.io.ObjectInput in)  
      Vector2d round()
      Set each component of this vector to the closest double that is equal to a mathematical integer, with ties rounding to positive infinity.
      Vector2d round​(Vector2d dest)
      Compute for each component of this vector the closest double that is equal to a mathematical integer, with ties rounding to positive infinity and store the result in dest.
      Vector2d set​(double d)
      Set the x and y components to the supplied value.
      Vector2d set​(double[] xy)
      Set the two components of this vector to the first two elements of the given array.
      Vector2d set​(double x, double y)
      Set the x and y components to the supplied values.
      Vector2d set​(float[] xy)
      Set the two components of this vector to the first two elements of the given array.
      Vector2d set​(int index, java.nio.ByteBuffer buffer)
      Read this vector from the supplied ByteBuffer starting at the specified absolute buffer position/index.
      Vector2d set​(int index, java.nio.DoubleBuffer buffer)
      Read this vector from the supplied DoubleBuffer starting at the specified absolute buffer position/index.
      Vector2d set​(java.nio.ByteBuffer buffer)
      Read this vector from the supplied ByteBuffer at the current buffer position.
      Vector2d set​(java.nio.DoubleBuffer buffer)
      Read this vector from the supplied DoubleBuffer at the current buffer position.
      Vector2d set​(Vector2dc v)
      Set this Vector2d to the values of v.
      Vector2d set​(Vector2fc v)
      Set this Vector2d to be a clone of v.
      Vector2d set​(Vector2ic v)
      Set this Vector2d to be a clone of v.
      Vector2d setComponent​(int component, double value)
      Set the value of the specified component of this vector.
      Vector2d setFromAddress​(long address)
      Set the values of this vector by reading 2 double values from off-heap memory, starting at the given address.
      Vector2d sub​(double x, double y)
      Subtract (x, y) from this vector.
      Vector2d sub​(double x, double y, Vector2d dest)
      Subtract (x, y) from this vector and store the result in dest.
      Vector2d sub​(Vector2dc v)
      Subtract v from this vector.
      Vector2d sub​(Vector2dc v, Vector2d dest)
      Subtract v from this vector and store the result in dest.
      Vector2d sub​(Vector2fc v)
      Subtract v from this vector.
      Vector2d sub​(Vector2fc v, Vector2d dest)
      Subtract v from this vector and store the result in dest.
      java.lang.String toString()
      Return a string representation of this vector.
      java.lang.String toString​(java.text.NumberFormat formatter)
      Return a string representation of this vector by formatting the vector components with the given NumberFormat.
      void writeExternal​(java.io.ObjectOutput out)  
      double x()  
      double y()  
      Vector2d zero()
      Set all components to zero.
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • x

        public double x
        The x component of the vector.
      • y

        public double y
        The y component of the vector.
    • Constructor Detail

      • Vector2d

        public Vector2d()
        Create a new Vector2d and initialize its components to zero.
      • Vector2d

        public Vector2d​(double d)
        Create a new Vector2d and initialize both of its components with the given value.
        Parameters:
        d - the value of both components
      • Vector2d

        public Vector2d​(double x,
                        double y)
        Create a new Vector2d and initialize its components to the given values.
        Parameters:
        x - the x value
        y - the y value
      • Vector2d

        public Vector2d​(Vector2dc v)
        Create a new Vector2d and initialize its components to the one of the given vector.
        Parameters:
        v - the Vector2dc to copy the values from
      • Vector2d

        public Vector2d​(Vector2fc v)
        Create a new Vector2d and initialize its components to the one of the given vector.
        Parameters:
        v - the Vector2fc to copy the values from
      • Vector2d

        public Vector2d​(Vector2ic v)
        Create a new Vector2d and initialize its components to the one of the given vector.
        Parameters:
        v - the Vector2ic to copy the values from
      • Vector2d

        public Vector2d​(double[] xy)
        Create a new Vector2d and initialize its two components from the first two elements of the given array.
        Parameters:
        xy - the array containing at least three elements
      • Vector2d

        public Vector2d​(float[] xy)
        Create a new Vector2d and initialize its two components from the first two elements of the given array.
        Parameters:
        xy - the array containing at least two elements
      • Vector2d

        public Vector2d​(java.nio.ByteBuffer buffer)
        Create a new Vector2d and read this vector from the supplied ByteBuffer at the current buffer position.

        This method will not increment the position of the given ByteBuffer.

        In order to specify the offset into the ByteBuffer at which the vector is read, use Vector2d(int, ByteBuffer), taking the absolute position as parameter.

        Parameters:
        buffer - values will be read in x, y order
        See Also:
        Vector2d(int, ByteBuffer)
      • Vector2d

        public Vector2d​(int index,
                        java.nio.ByteBuffer buffer)
        Create a new Vector2d and read this vector from the supplied ByteBuffer starting at the specified absolute buffer position/index.

        This method will not increment the position of the given ByteBuffer.

        Parameters:
        index - the absolute position into the ByteBuffer
        buffer - values will be read in x, y order
      • Vector2d

        public Vector2d​(java.nio.DoubleBuffer buffer)
        Create a new Vector2d and read this vector from the supplied DoubleBuffer at the current buffer position.

        This method will not increment the position of the given DoubleBuffer.

        In order to specify the offset into the DoubleBuffer at which the vector is read, use Vector2d(int, DoubleBuffer), taking the absolute position as parameter.

        Parameters:
        buffer - values will be read in x, y order
        See Also:
        Vector2d(int, DoubleBuffer)
      • Vector2d

        public Vector2d​(int index,
                        java.nio.DoubleBuffer buffer)
        Create a new Vector2d and read this vector from the supplied DoubleBuffer starting at the specified absolute buffer position/index.

        This method will not increment the position of the given DoubleBuffer.

        Parameters:
        index - the absolute position into the DoubleBuffer
        buffer - values will be read in x, y order
    • Method Detail

      • x

        public double x()
        Specified by:
        x in interface Vector2dc
        Returns:
        the value of the x component
      • y

        public double y()
        Specified by:
        y in interface Vector2dc
        Returns:
        the value of the y component
      • set

        public Vector2d set​(double d)
        Set the x and y components to the supplied value.
        Parameters:
        d - the value of both components
        Returns:
        this
      • set

        public Vector2d set​(double x,
                            double y)
        Set the x and y components to the supplied values.
        Parameters:
        x - the x value
        y - the y value
        Returns:
        this
      • set

        public Vector2d set​(Vector2dc v)
        Set this Vector2d to the values of v.
        Parameters:
        v - the vector to copy from
        Returns:
        this
      • set

        public Vector2d set​(Vector2fc v)
        Set this Vector2d to be a clone of v.
        Parameters:
        v - the vector to copy from
        Returns:
        this
      • set

        public Vector2d set​(Vector2ic v)
        Set this Vector2d to be a clone of v.
        Parameters:
        v - the vector to copy from
        Returns:
        this
      • set

        public Vector2d set​(double[] xy)
        Set the two components of this vector to the first two elements of the given array.
        Parameters:
        xy - the array containing at least three elements
        Returns:
        this
      • set

        public Vector2d set​(float[] xy)
        Set the two components of this vector to the first two elements of the given array.
        Parameters:
        xy - the array containing at least two elements
        Returns:
        this
      • set

        public Vector2d set​(java.nio.ByteBuffer buffer)
        Read this vector from the supplied ByteBuffer at the current buffer position.

        This method will not increment the position of the given ByteBuffer.

        In order to specify the offset into the ByteBuffer at which the vector is read, use set(int, ByteBuffer), taking the absolute position as parameter.

        Parameters:
        buffer - values will be read in x, y order
        Returns:
        this
        See Also:
        set(int, ByteBuffer)
      • set

        public Vector2d set​(int index,
                            java.nio.ByteBuffer buffer)
        Read this vector from the supplied ByteBuffer starting at the specified absolute buffer position/index.

        This method will not increment the position of the given ByteBuffer.

        Parameters:
        index - the absolute position into the ByteBuffer
        buffer - values will be read in x, y order
        Returns:
        this
      • set

        public Vector2d set​(java.nio.DoubleBuffer buffer)
        Read this vector from the supplied DoubleBuffer at the current buffer position.

        This method will not increment the position of the given DoubleBuffer.

        In order to specify the offset into the DoubleBuffer at which the vector is read, use set(int, DoubleBuffer), taking the absolute position as parameter.

        Parameters:
        buffer - values will be read in x, y order
        Returns:
        this
        See Also:
        set(int, DoubleBuffer)
      • set

        public Vector2d set​(int index,
                            java.nio.DoubleBuffer buffer)
        Read this vector from the supplied DoubleBuffer starting at the specified absolute buffer position/index.

        This method will not increment the position of the given DoubleBuffer.

        Parameters:
        index - the absolute position into the DoubleBuffer
        buffer - values will be read in x, y order
        Returns:
        this
      • setFromAddress

        public Vector2d setFromAddress​(long address)
        Set the values of this vector by reading 2 double values from off-heap memory, starting at the given address.

        This method will throw an UnsupportedOperationException when JOML is used with `-Djoml.nounsafe`.

        This method is unsafe as it can result in a crash of the JVM process when the specified address range does not belong to this process.

        Parameters:
        address - the off-heap memory address to read the vector values from
        Returns:
        this
      • get

        public double get​(int component)
                   throws java.lang.IllegalArgumentException
        Description copied from interface: Vector2dc
        Get the value of the specified component of this vector.
        Specified by:
        get in interface Vector2dc
        Parameters:
        component - the component, within [0..1]
        Returns:
        the value
        Throws:
        java.lang.IllegalArgumentException - if component is not within [0..1]
      • get

        public Vector2i get​(int mode,
                            Vector2i dest)
        Description copied from interface: Vector2dc
        Set the components of the given vector dest to those of this vector using the given RoundingMode.
        Specified by:
        get in interface Vector2dc
        Parameters:
        mode - the RoundingMode to use
        dest - will hold the result
        Returns:
        dest
      • get

        public Vector2f get​(Vector2f dest)
        Description copied from interface: Vector2dc
        Set the components of the given vector dest to those of this vector.
        Specified by:
        get in interface Vector2dc
        Parameters:
        dest - will hold the result
        Returns:
        dest
      • get

        public Vector2d get​(Vector2d dest)
        Description copied from interface: Vector2dc
        Set the components of the given vector dest to those of this vector.
        Specified by:
        get in interface Vector2dc
        Parameters:
        dest - will hold the result
        Returns:
        dest
      • setComponent

        public Vector2d setComponent​(int component,
                                     double value)
                              throws java.lang.IllegalArgumentException
        Set the value of the specified component of this vector.
        Parameters:
        component - the component whose value to set, within [0..1]
        value - the value to set
        Returns:
        this
        Throws:
        java.lang.IllegalArgumentException - if component is not within [0..1]
      • get

        public java.nio.ByteBuffer get​(java.nio.ByteBuffer buffer)
        Description copied from interface: Vector2dc
        Store this vector into the supplied ByteBuffer at the current buffer position.

        This method will not increment the position of the given ByteBuffer.

        In order to specify the offset into the ByteBuffer at which the vector is stored, use Vector2dc.get(int, ByteBuffer), taking the absolute position as parameter.

        Specified by:
        get in interface Vector2dc
        Parameters:
        buffer - will receive the values of this vector in x, y order
        Returns:
        the passed in buffer
        See Also:
        Vector2dc.get(int, ByteBuffer)
      • get

        public java.nio.ByteBuffer get​(int index,
                                       java.nio.ByteBuffer buffer)
        Description copied from interface: Vector2dc
        Store this vector into the supplied ByteBuffer starting at the specified absolute buffer position/index.

        This method will not increment the position of the given ByteBuffer.

        Specified by:
        get in interface Vector2dc
        Parameters:
        index - the absolute position into the ByteBuffer
        buffer - will receive the values of this vector in x, y order
        Returns:
        the passed in buffer
      • get

        public java.nio.DoubleBuffer get​(java.nio.DoubleBuffer buffer)
        Description copied from interface: Vector2dc
        Store this vector into the supplied DoubleBuffer at the current buffer position.

        This method will not increment the position of the given DoubleBuffer.

        In order to specify the offset into the DoubleBuffer at which the vector is stored, use Vector2dc.get(int, DoubleBuffer), taking the absolute position as parameter.

        Specified by:
        get in interface Vector2dc
        Parameters:
        buffer - will receive the values of this vector in x, y order
        Returns:
        the passed in buffer
        See Also:
        Vector2dc.get(int, DoubleBuffer)
      • get

        public java.nio.DoubleBuffer get​(int index,
                                         java.nio.DoubleBuffer buffer)
        Description copied from interface: Vector2dc
        Store this vector into the supplied DoubleBuffer starting at the specified absolute buffer position/index.

        This method will not increment the position of the given DoubleBuffer.

        Specified by:
        get in interface Vector2dc
        Parameters:
        index - the absolute position into the DoubleBuffer
        buffer - will receive the values of this vector in x, y order
        Returns:
        the passed in buffer
      • getToAddress

        public Vector2dc getToAddress​(long address)
        Description copied from interface: Vector2dc
        Store this vector at the given off-heap memory address.

        This method will throw an UnsupportedOperationException when JOML is used with `-Djoml.nounsafe`.

        This method is unsafe as it can result in a crash of the JVM process when the specified address range does not belong to this process.

        Specified by:
        getToAddress in interface Vector2dc
        Parameters:
        address - the off-heap address where to store this vector
        Returns:
        this
      • perpendicular

        public Vector2d perpendicular()
        Set this vector to be one of its perpendicular vectors.
        Returns:
        this
      • sub

        public Vector2d sub​(Vector2dc v)
        Subtract v from this vector.
        Parameters:
        v - the vector to subtract
        Returns:
        this
      • sub

        public Vector2d sub​(double x,
                            double y)
        Subtract (x, y) from this vector.
        Parameters:
        x - the x component to subtract
        y - the y component to subtract
        Returns:
        this
      • sub

        public Vector2d sub​(double x,
                            double y,
                            Vector2d dest)
        Description copied from interface: Vector2dc
        Subtract (x, y) from this vector and store the result in dest.
        Specified by:
        sub in interface Vector2dc
        Parameters:
        x - the x component to subtract
        y - the y component to subtract
        dest - will hold the result
        Returns:
        dest
      • sub

        public Vector2d sub​(Vector2fc v)
        Subtract v from this vector.
        Parameters:
        v - the vector to subtract
        Returns:
        this
      • sub

        public Vector2d sub​(Vector2dc v,
                            Vector2d dest)
        Description copied from interface: Vector2dc
        Subtract v from this vector and store the result in dest.
        Specified by:
        sub in interface Vector2dc
        Parameters:
        v - the vector to subtract
        dest - will hold the result
        Returns:
        dest
      • sub

        public Vector2d sub​(Vector2fc v,
                            Vector2d dest)
        Description copied from interface: Vector2dc
        Subtract v from this vector and store the result in dest.
        Specified by:
        sub in interface Vector2dc
        Parameters:
        v - the vector to subtract
        dest - will hold the result
        Returns:
        dest
      • mul

        public Vector2d mul​(double scalar)
        Multiply the components of this vector by the given scalar.
        Parameters:
        scalar - the value to multiply this vector's components by
        Returns:
        this
      • mul

        public Vector2d mul​(double scalar,
                            Vector2d dest)
        Description copied from interface: Vector2dc
        Multiply the components of this vector by the given scalar and store the result in dest.
        Specified by:
        mul in interface Vector2dc
        Parameters:
        scalar - the value to multiply this vector's components by
        dest - will hold the result
        Returns:
        dest
      • mul

        public Vector2d mul​(double x,
                            double y)
        Multiply the components of this Vector2d by the given scalar values and store the result in this.
        Parameters:
        x - the x component to multiply this vector by
        y - the y component to multiply this vector by
        Returns:
        this
      • mul

        public Vector2d mul​(double x,
                            double y,
                            Vector2d dest)
        Description copied from interface: Vector2dc
        Multiply the components of this Vector2d by the given scalar values and store the result in dest.
        Specified by:
        mul in interface Vector2dc
        Parameters:
        x - the x component to multiply this vector by
        y - the y component to multiply this vector by
        dest - will hold the result
        Returns:
        dest
      • mul

        public Vector2d mul​(Vector2dc v)
        Multiply this Vector2d component-wise by another Vector2d.
        Parameters:
        v - the vector to multiply by
        Returns:
        this
      • mul

        public Vector2d mul​(Vector2dc v,
                            Vector2d dest)
        Description copied from interface: Vector2dc
        Multiply this Vector2d component-wise by another Vector2d and store the result in dest.
        Specified by:
        mul in interface Vector2dc
        Parameters:
        v - the vector to multiply by
        dest - will hold the result
        Returns:
        dest
      • div

        public Vector2d div​(double scalar)
        Divide this Vector2d by the given scalar value.
        Parameters:
        scalar - the scalar to divide this vector by
        Returns:
        this
      • div

        public Vector2d div​(double scalar,
                            Vector2d dest)
        Description copied from interface: Vector2dc
        Divide this Vector2d by the given scalar value and store the result in dest.
        Specified by:
        div in interface Vector2dc
        Parameters:
        scalar - the scalar to divide this vector by
        dest - will hold the result
        Returns:
        dest
      • div

        public Vector2d div​(double x,
                            double y)
        Divide the components of this Vector2d by the given scalar values and store the result in this.
        Parameters:
        x - the x component to divide this vector by
        y - the y component to divide this vector by
        Returns:
        this
      • div

        public Vector2d div​(double x,
                            double y,
                            Vector2d dest)
        Description copied from interface: Vector2dc
        Divide the components of this Vector3f by the given scalar values and store the result in dest.
        Specified by:
        div in interface Vector2dc
        Parameters:
        x - the x component to divide this vector by
        y - the y component to divide this vector by
        dest - will hold the result
        Returns:
        dest
      • div

        public Vector2d div​(Vector2d v)
        Divide this Vector2d component-wise by another Vector2dc.
        Parameters:
        v - the vector to divide by
        Returns:
        this
      • div

        public Vector2d div​(Vector2fc v)
        Divide this Vector3d component-wise by another Vector2fc.
        Parameters:
        v - the vector to divide by
        Returns:
        this
      • div

        public Vector2d div​(Vector2fc v,
                            Vector2d dest)
        Description copied from interface: Vector2dc
        Divide this Vector2d component-wise by another Vector2f and store the result in dest.
        Specified by:
        div in interface Vector2dc
        Parameters:
        v - the vector to divide by
        dest - will hold the result
        Returns:
        dest
      • div

        public Vector2d div​(Vector2dc v,
                            Vector2d dest)
        Description copied from interface: Vector2dc
        Divide this by v component-wise and store the result into dest.
        Specified by:
        div in interface Vector2dc
        Parameters:
        v - the vector to divide by
        dest - will hold the result
        Returns:
        dest
      • mul

        public Vector2d mul​(Matrix2fc mat)
        Multiply the given matrix mat with this Vector2d.
        Parameters:
        mat - the matrix to multiply this vector by
        Returns:
        this
      • mul

        public Vector2d mul​(Matrix2dc mat)
        Multiply the given matrix mat with this Vector2d.
        Parameters:
        mat - the matrix to multiply this vector by
        Returns:
        this
      • mul

        public Vector2d mul​(Matrix2dc mat,
                            Vector2d dest)
        Description copied from interface: Vector2dc
        Multiply the given matrix mat with this and store the result in dest.
        Specified by:
        mul in interface Vector2dc
        Parameters:
        mat - the matrix to multiply this vector by
        dest - will hold the result
        Returns:
        dest
      • mul

        public Vector2d mul​(Matrix2fc mat,
                            Vector2d dest)
        Description copied from interface: Vector2dc
        Multiply the given matrix mat with this and store the result in dest.
        Specified by:
        mul in interface Vector2dc
        Parameters:
        mat - the matrix to multiply this vector by
        dest - will hold the result
        Returns:
        dest
      • mulTranspose

        public Vector2d mulTranspose​(Matrix2dc mat)
        Multiply the transpose of the given matrix with this Vector2d and store the result in this.
        Parameters:
        mat - the matrix
        Returns:
        this
      • mulTranspose

        public Vector2d mulTranspose​(Matrix2dc mat,
                                     Vector2d dest)
        Description copied from interface: Vector2dc
        Multiply the transpose of the given matrix with this Vector2f and store the result in dest.
        Specified by:
        mulTranspose in interface Vector2dc
        Parameters:
        mat - the matrix
        dest - will hold the result
        Returns:
        dest
      • mulTranspose

        public Vector2d mulTranspose​(Matrix2fc mat)
        Multiply the transpose of the given matrix with this Vector2d and store the result in this.
        Parameters:
        mat - the matrix
        Returns:
        this
      • mulTranspose

        public Vector2d mulTranspose​(Matrix2fc mat,
                                     Vector2d dest)
        Description copied from interface: Vector2dc
        Multiply the transpose of the given matrix with this Vector2f and store the result in dest.
        Specified by:
        mulTranspose in interface Vector2dc
        Parameters:
        mat - the matrix
        dest - will hold the result
        Returns:
        dest
      • mulPosition

        public Vector2d mulPosition​(Matrix3x2dc mat)
        Multiply the given 3x2 matrix mat with this.

        This method assumes the z component of this to be 1.0.

        Parameters:
        mat - the matrix to multiply this vector by
        Returns:
        this
      • mulPosition

        public Vector2d mulPosition​(Matrix3x2dc mat,
                                    Vector2d dest)
        Description copied from interface: Vector2dc
        Multiply the given 3x2 matrix mat with this and store the result in dest.

        This method assumes the z component of this to be 1.0.

        Specified by:
        mulPosition in interface Vector2dc
        Parameters:
        mat - the matrix to multiply this vector by
        dest - will hold the result
        Returns:
        dest
      • mulDirection

        public Vector2d mulDirection​(Matrix3x2dc mat)
        Multiply the given 3x2 matrix mat with this.

        This method assumes the z component of this to be 0.0.

        Parameters:
        mat - the matrix to multiply this vector by
        Returns:
        this
      • mulDirection

        public Vector2d mulDirection​(Matrix3x2dc mat,
                                     Vector2d dest)
        Description copied from interface: Vector2dc
        Multiply the given 3x2 matrix mat with this and store the result in dest.

        This method assumes the z component of this to be 0.0.

        Specified by:
        mulDirection in interface Vector2dc
        Parameters:
        mat - the matrix to multiply this vector by
        dest - will hold the result
        Returns:
        dest
      • dot

        public double dot​(Vector2dc v)
        Description copied from interface: Vector2dc
        Return the dot product of this vector and v.
        Specified by:
        dot in interface Vector2dc
        Parameters:
        v - the other vector
        Returns:
        the dot product
      • angle

        public double angle​(Vector2dc v)
        Description copied from interface: Vector2dc
        Return the angle between this vector and the supplied vector.
        Specified by:
        angle in interface Vector2dc
        Parameters:
        v - the other vector
        Returns:
        the angle, in radians
      • lengthSquared

        public double lengthSquared()
        Description copied from interface: Vector2dc
        Return the length squared of this vector.
        Specified by:
        lengthSquared in interface Vector2dc
        Returns:
        the length squared
      • lengthSquared

        public static double lengthSquared​(double x,
                                           double y)
        Get the length squared of a 2-dimensional double-precision vector.
        Parameters:
        x - The vector's x component
        y - The vector's y component
        Returns:
        the length squared of the given vector
      • length

        public double length()
        Description copied from interface: Vector2dc
        Return the length of this vector.
        Specified by:
        length in interface Vector2dc
        Returns:
        the length
      • length

        public static double length​(double x,
                                    double y)
        Get the length of a 2-dimensional double-precision vector.
        Parameters:
        x - The vector's x component
        y - The vector's y component
        Returns:
        the length of the given vector
      • distance

        public double distance​(Vector2dc v)
        Description copied from interface: Vector2dc
        Return the distance between this and v.
        Specified by:
        distance in interface Vector2dc
        Parameters:
        v - the other vector
        Returns:
        the distance
      • distanceSquared

        public double distanceSquared​(Vector2dc v)
        Description copied from interface: Vector2dc
        Return the distance squared between this and v.
        Specified by:
        distanceSquared in interface Vector2dc
        Parameters:
        v - the other vector
        Returns:
        the distance squared
      • distance

        public double distance​(Vector2fc v)
        Description copied from interface: Vector2dc
        Return the distance between this and v.
        Specified by:
        distance in interface Vector2dc
        Parameters:
        v - the other vector
        Returns:
        the distance
      • distanceSquared

        public double distanceSquared​(Vector2fc v)
        Description copied from interface: Vector2dc
        Return the distance squared between this and v.
        Specified by:
        distanceSquared in interface Vector2dc
        Parameters:
        v - the other vector
        Returns:
        the distance squared
      • distance

        public double distance​(double x,
                               double y)
        Description copied from interface: Vector2dc
        Return the distance between this vector and (x, y).
        Specified by:
        distance in interface Vector2dc
        Parameters:
        x - the x component of the other vector
        y - the y component of the other vector
        Returns:
        the euclidean distance
      • distanceSquared

        public double distanceSquared​(double x,
                                      double y)
        Description copied from interface: Vector2dc
        Return the distance squared between this vector and (x, y).
        Specified by:
        distanceSquared in interface Vector2dc
        Parameters:
        x - the x component of the other vector
        y - the y component of the other vector
        Returns:
        the euclidean distance squared
      • distance

        public static double distance​(double x1,
                                      double y1,
                                      double x2,
                                      double y2)
        Return the distance between (x1, y1) and (x2, y2).
        Parameters:
        x1 - the x component of the first vector
        y1 - the y component of the first vector
        x2 - the x component of the second vector
        y2 - the y component of the second vector
        Returns:
        the euclidean distance
      • distanceSquared

        public static double distanceSquared​(double x1,
                                             double y1,
                                             double x2,
                                             double y2)
        Return the squared distance between (x1, y1) and (x2, y2).
        Parameters:
        x1 - the x component of the first vector
        y1 - the y component of the first vector
        x2 - the x component of the second vector
        y2 - the y component of the second vector
        Returns:
        the euclidean distance squared
      • normalize

        public Vector2d normalize()
        Normalize this vector.
        Returns:
        this
      • normalize

        public Vector2d normalize​(Vector2d dest)
        Description copied from interface: Vector2dc
        Normalize this vector and store the result in dest.
        Specified by:
        normalize in interface Vector2dc
        Parameters:
        dest - will hold the result
        Returns:
        dest
      • normalize

        public Vector2d normalize​(double length)
        Scale this vector to have the given length.
        Parameters:
        length - the desired length
        Returns:
        this
      • normalize

        public Vector2d normalize​(double length,
                                  Vector2d dest)
        Description copied from interface: Vector2dc
        Scale this vector to have the given length and store the result in dest.
        Specified by:
        normalize in interface Vector2dc
        Parameters:
        length - the desired length
        dest - will hold the result
        Returns:
        dest
      • add

        public Vector2d add​(Vector2dc v)
        Add v to this vector.
        Parameters:
        v - the vector to add
        Returns:
        this
      • add

        public Vector2d add​(double x,
                            double y)
        Add (x, y) to this vector.
        Parameters:
        x - the x component to add
        y - the y component to add
        Returns:
        this
      • add

        public Vector2d add​(double x,
                            double y,
                            Vector2d dest)
        Description copied from interface: Vector2dc
        Add (x, y) to this vector and store the result in dest.
        Specified by:
        add in interface Vector2dc
        Parameters:
        x - the x component to add
        y - the y component to add
        dest - will hold the result
        Returns:
        dest
      • add

        public Vector2d add​(Vector2fc v)
        Add v to this vector.
        Parameters:
        v - the vector to add
        Returns:
        this
      • add

        public Vector2d add​(Vector2dc v,
                            Vector2d dest)
        Description copied from interface: Vector2dc
        Add v to this vector and store the result in dest.
        Specified by:
        add in interface Vector2dc
        Parameters:
        v - the vector to add
        dest - will hold the result
        Returns:
        dest
      • add

        public Vector2d add​(Vector2fc v,
                            Vector2d dest)
        Description copied from interface: Vector2dc
        Add v to this vector and store the result in dest.
        Specified by:
        add in interface Vector2dc
        Parameters:
        v - the vector to add
        dest - will hold the result
        Returns:
        dest
      • zero

        public Vector2d zero()
        Set all components to zero.
        Returns:
        this
      • writeExternal

        public void writeExternal​(java.io.ObjectOutput out)
                           throws java.io.IOException
        Specified by:
        writeExternal in interface java.io.Externalizable
        Throws:
        java.io.IOException
      • readExternal

        public void readExternal​(java.io.ObjectInput in)
                          throws java.io.IOException,
                                 java.lang.ClassNotFoundException
        Specified by:
        readExternal in interface java.io.Externalizable
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • negate

        public Vector2d negate()
        Negate this vector.
        Returns:
        this
      • negate

        public Vector2d negate​(Vector2d dest)
        Description copied from interface: Vector2dc
        Negate this vector and store the result in dest.
        Specified by:
        negate in interface Vector2dc
        Parameters:
        dest - will hold the result
        Returns:
        dest
      • lerp

        public Vector2d lerp​(Vector2dc other,
                             double t)
        Linearly interpolate this and other using the given interpolation factor t and store the result in this.

        If t is 0.0 then the result is this. If the interpolation factor is 1.0 then the result is other.

        Parameters:
        other - the other vector
        t - the interpolation factor between 0.0 and 1.0
        Returns:
        this
      • lerp

        public Vector2d lerp​(Vector2dc other,
                             double t,
                             Vector2d dest)
        Description copied from interface: Vector2dc
        Linearly interpolate this and other using the given interpolation factor t and store the result in dest.

        If t is 0.0 then the result is this. If the interpolation factor is 1.0 then the result is other.

        Specified by:
        lerp in interface Vector2dc
        Parameters:
        other - the other vector
        t - the interpolation factor between 0.0 and 1.0
        dest - will hold the result
        Returns:
        dest
      • hashCode

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

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

        public boolean equals​(Vector2dc v,
                              double delta)
        Description copied from interface: Vector2dc
        Compare the vector components of this vector with the given vector using the given delta and return whether all of them are equal within a maximum difference of delta.

        Please note that this method is not used by any data structure such as ArrayList HashSet or HashMap and their operations, such as ArrayList.contains(Object) or HashSet.remove(Object), since those data structures only use the Object.equals(Object) and Object.hashCode() methods.

        Specified by:
        equals in interface Vector2dc
        Parameters:
        v - the other vector
        delta - the allowed maximum difference
        Returns:
        true whether all of the vector components are equal; false otherwise
      • equals

        public boolean equals​(double x,
                              double y)
        Description copied from interface: Vector2dc
        Compare the vector components of this vector with the given (x, y) and return whether all of them are equal.
        Specified by:
        equals in interface Vector2dc
        Parameters:
        x - the x component to compare to
        y - the y component to compare to
        Returns:
        true if all the vector components are equal
      • toString

        public java.lang.String toString()
        Return a string representation of this vector.

        This method creates a new DecimalFormat on every invocation with the format string "0.000E0;-".

        Overrides:
        toString in class java.lang.Object
        Returns:
        the string representation
      • toString

        public java.lang.String toString​(java.text.NumberFormat formatter)
        Return a string representation of this vector by formatting the vector components with the given NumberFormat.
        Parameters:
        formatter - the NumberFormat used to format the vector components with
        Returns:
        the string representation
      • fma

        public Vector2d fma​(Vector2dc a,
                            Vector2dc b)
        Add the component-wise multiplication of a * b to this vector.
        Parameters:
        a - the first multiplicand
        b - the second multiplicand
        Returns:
        this
      • fma

        public Vector2d fma​(double a,
                            Vector2dc b)
        Add the component-wise multiplication of a * b to this vector.
        Parameters:
        a - the first multiplicand
        b - the second multiplicand
        Returns:
        this
      • fma

        public Vector2d fma​(Vector2dc a,
                            Vector2dc b,
                            Vector2d dest)
        Description copied from interface: Vector2dc
        Add the component-wise multiplication of a * b to this vector and store the result in dest.
        Specified by:
        fma in interface Vector2dc
        Parameters:
        a - the first multiplicand
        b - the second multiplicand
        dest - will hold the result
        Returns:
        dest
      • fma

        public Vector2d fma​(double a,
                            Vector2dc b,
                            Vector2d dest)
        Description copied from interface: Vector2dc
        Add the component-wise multiplication of a * b to this vector and store the result in dest.
        Specified by:
        fma in interface Vector2dc
        Parameters:
        a - the first multiplicand
        b - the second multiplicand
        dest - will hold the result
        Returns:
        dest
      • min

        public Vector2d min​(Vector2dc v)
        Set the components of this vector to be the component-wise minimum of this and the other vector.
        Parameters:
        v - the other vector
        Returns:
        this
      • min

        public Vector2d min​(Vector2dc v,
                            Vector2d dest)
        Description copied from interface: Vector2dc
        Set the components of dest to be the component-wise minimum of this and the other vector.
        Specified by:
        min in interface Vector2dc
        Parameters:
        v - the other vector
        dest - will hold the result
        Returns:
        dest
      • max

        public Vector2d max​(Vector2dc v)
        Set the components of this vector to be the component-wise maximum of this and the other vector.
        Parameters:
        v - the other vector
        Returns:
        this
      • max

        public Vector2d max​(Vector2dc v,
                            Vector2d dest)
        Description copied from interface: Vector2dc
        Set the components of dest to be the component-wise maximum of this and the other vector.
        Specified by:
        max in interface Vector2dc
        Parameters:
        v - the other vector
        dest - will hold the result
        Returns:
        dest
      • maxComponent

        public int maxComponent()
        Description copied from interface: Vector2dc
        Determine the component with the biggest absolute value.
        Specified by:
        maxComponent in interface Vector2dc
        Returns:
        the component index, within [0..1]
      • minComponent

        public int minComponent()
        Description copied from interface: Vector2dc
        Determine the component with the smallest (towards zero) absolute value.
        Specified by:
        minComponent in interface Vector2dc
        Returns:
        the component index, within [0..1]
      • floor

        public Vector2d floor()
        Set each component of this vector to the largest (closest to positive infinity) double value that is less than or equal to that component and is equal to a mathematical integer.
        Returns:
        this
      • floor

        public Vector2d floor​(Vector2d dest)
        Description copied from interface: Vector2dc
        Compute for each component of this vector the largest (closest to positive infinity) double value that is less than or equal to that component and is equal to a mathematical integer and store the result in dest.
        Specified by:
        floor in interface Vector2dc
        Parameters:
        dest - will hold the result
        Returns:
        dest
      • ceil

        public Vector2d ceil()
        Set each component of this vector to the smallest (closest to negative infinity) double value that is greater than or equal to that component and is equal to a mathematical integer.
        Returns:
        this
      • ceil

        public Vector2d ceil​(Vector2d dest)
        Description copied from interface: Vector2dc
        Compute for each component of this vector the smallest (closest to negative infinity) double value that is greater than or equal to that component and is equal to a mathematical integer and store the result in dest.
        Specified by:
        ceil in interface Vector2dc
        Parameters:
        dest - will hold the result
        Returns:
        dest
      • round

        public Vector2d round()
        Set each component of this vector to the closest double that is equal to a mathematical integer, with ties rounding to positive infinity.
        Returns:
        this
      • round

        public Vector2d round​(Vector2d dest)
        Description copied from interface: Vector2dc
        Compute for each component of this vector the closest double that is equal to a mathematical integer, with ties rounding to positive infinity and store the result in dest.
        Specified by:
        round in interface Vector2dc
        Parameters:
        dest - will hold the result
        Returns:
        dest
      • isFinite

        public boolean isFinite()
        Description copied from interface: Vector2dc
        Determine whether all components are finite floating-point values, that is, they are not NaN and not infinity.
        Specified by:
        isFinite in interface Vector2dc
        Returns:
        true if all components are finite floating-point values; false otherwise
      • absolute

        public Vector2d absolute()
        Set this vector's components to their respective absolute values.
        Returns:
        this
      • absolute

        public Vector2d absolute​(Vector2d dest)
        Description copied from interface: Vector2dc
        Compute the absolute of each of this vector's components and store the result into dest.
        Specified by:
        absolute in interface Vector2dc
        Parameters:
        dest - will hold the result
        Returns:
        dest
      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Overrides:
        clone in class java.lang.Object
        Throws:
        java.lang.CloneNotSupportedException