Class Vector2d

  • All Implemented Interfaces:
    Serializable

    public final class Vector2d
    extends Object
    implements Serializable
    Basic class representing an immutable vector containing 2 doubles. All inputs and outputs are in system units.
    Author:
    moskowitz
    See Also:
    Serialized Form
    • Constructor Detail

      • Vector2d

        public Vector2d​(double x,
                        double y)
      • Vector2d

        public Vector2d()
    • Method Detail

      • getX

        public double getX()
      • getY

        public double getY()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • format

        public String format​(String coordFormat)
        Get formatted String representation.
        Parameters:
        coordFormat - format applied to each coordinate (as in String.format)
        Returns:
        formatted string with comma separated coordinates
      • scaledBy

        public Vector2d scaledBy​(double scaleFactor)
      • dotProduct

        public double dotProduct​(Vector2d v)
      • crossProduct

        public double crossProduct​(Vector2d v)
      • isToRightOf

        public boolean isToRightOf​(Vector2d v)
      • azimuthAngle

        public double azimuthAngle()
      • azimuthAngleFast

        public double azimuthAngleFast()
      • normSquared

        public double normSquared()
      • norm

        public double norm()
      • isZero

        public boolean isZero()
      • normalized

        public Vector2d normalized()
        Returns normalized (rescaled to norm = 1) version of this vector.

        Note: "Strict" version: if zero vector, returned vector will contain all NaN values and a warning will be logged.

        Returns:
        normalized version of this vector
      • normalizedLenient

        public Vector2d normalizedLenient()
        Returns normalized (rescaled to norm = 1) version of this vector.

        Note: "Lenient" version: If zero vector, returned vector will be (1, 0).

        Returns:
        normalized version of this vector
      • distanceSquared

        public double distanceSquared​(Vector2d v)
      • distance

        public double distance​(Vector2d v)
      • cosAngleWith

        public double cosAngleWith​(Vector2d v)
        Returns cosine of the angle between this vector and vector v.
      • angleWith

        public double angleWith​(Vector2d v)
        Returns the conical (unsigned) angle between this vector and vector v.
      • projectionOnto

        public Vector2d projectionOnto​(Vector2d v,
                                       boolean isLenient)
        Returns the projection of this vector onto the vector v. Lenient version treats zero vector for v as (1,0) in order to avoid returning vector containing NaN values.
      • rotatedAboutOriginBy

        public Vector2d rotatedAboutOriginBy​(double theta)
        Parameters:
        theta - rotation angle
        Returns:
        rotated copy
      • perpendicularVector

        public Vector2d perpendicularVector()
        Returns a vector perpendicular to this one, with same norm.
      • toVector3d

        public Vector3d toVector3d​(double z)
        Concatenate z component to form ThreeVector.
        Parameters:
        z -
        Returns:
        ThreeVector
      • toArray

        public double[] toArray()
      • fromArray

        public static Vector2d fromArray​(double[] coords)
      • createPolar

        public static Vector2d createPolar​(double radius,
                                           double theta)
        Create Vector2d from polar coordinates.
        Parameters:
        radius - distance from center (0,0)
        theta - azimuth angle
        Returns:
        Vector2d
      • createPolarTranslated

        public static Vector2d createPolarTranslated​(double radius,
                                                     double theta,
                                                     double translateX,
                                                     double translateY)
        Create Vector2d from polar coordinates with given translation of origin.
        Parameters:
        radius - distance from center (translateX, translateY)
        theta - azimuth angle
        translateX -
        translateY -
        Returns:
        Vector2d
      • linearCombination

        public static Vector2d linearCombination​(double[] a,
                                                 Vector2d[] w)