Package snap.geom

Class Vector

java.lang.Object
snap.geom.Vector
All Implemented Interfaces:
Cloneable

public class Vector extends Object implements Cloneable
This class represents a vector.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    double
     
    double
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor.
    Vector(double aX, double aY)
    Constructor for given XY coords.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(Vector aVector)
    Add the given vector to this.
    Standard clone implementation.
    double
    Return the direction of this vector (in degrees).
    static double
    getAngleBetween(double aX, double aY, double bX, double bY)
    Returns the angle between vectors (using given vector points).
    double
    Returns the angle between the receiver and the given vector.
    static double
    getDotProduct(double aX, double aY, double bX, double bY)
    Returns the dot product of two vectors.
    double
    Returns the dot product of the receiver and the given vector.
    double
    Returns the length of the vector.
    static double
    getLength(double aX, double aY)
    Returns the length of given vector XY.
    static double
    getProjectedDistance(double aX, double aY, double bX, double bY)
    Returns the length of V1 as projected onto V2 (using given vector points).
    static Vector
    getVectorForAngleAndLength(double anAngle, double length)
    Returns Vector for given angle and length.
    boolean
    isAligned(Vector aVector, boolean includePerpendiculars)
    Returns whether given vector is in same general direction of this (with option to include perpendiculars).
    boolean
    isAway(Vector aVector, boolean includePerpendiculars)
    Returns whether given vector is pointing away from the direction of this (with option to include perpendiculars).
    void
    Makes this receiver point in the opposite direction.
    void
    Makes the vector unit length.
    void
    setXY(double aX, double aY)
    Sets the X/Y values.
    void
    setXY(Vector aVector)
    Sets the X/Y values.
    Returns a string representation of the vector.
    void
    Transforms this vector by the given transform.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • x

      public double x
    • y

      public double y
  • Constructor Details

    • Vector

      public Vector()
      Constructor.
    • Vector

      public Vector(double aX, double aY)
      Constructor for given XY coords.
  • Method Details

    • getAngle

      public double getAngle()
      Return the direction of this vector (in degrees).
    • getLength

      public double getLength()
      Returns the length of the vector.
    • normalize

      public void normalize()
      Makes the vector unit length.
    • add

      public void add(Vector aVector)
      Add the given vector to this.
    • getDotProduct

      public double getDotProduct(Vector v2)
      Returns the dot product of the receiver and the given vector.
    • isAligned

      public boolean isAligned(Vector aVector, boolean includePerpendiculars)
      Returns whether given vector is in same general direction of this (with option to include perpendiculars).
    • isAway

      public boolean isAway(Vector aVector, boolean includePerpendiculars)
      Returns whether given vector is pointing away from the direction of this (with option to include perpendiculars).
    • getAngleBetween

      public double getAngleBetween(Vector aVector)
      Returns the angle between the receiver and the given vector.
    • negate

      public void negate()
      Makes this receiver point in the opposite direction.
    • transform

      public void transform(Transform aTrans)
      Transforms this vector by the given transform.
    • setXY

      public void setXY(Vector aVector)
      Sets the X/Y values.
    • setXY

      public void setXY(double aX, double aY)
      Sets the X/Y values.
    • clone

      public Vector clone()
      Standard clone implementation.
      Overrides:
      clone in class Object
    • toString

      public String toString()
      Returns a string representation of the vector.
      Overrides:
      toString in class Object
    • getLength

      public static double getLength(double aX, double aY)
      Returns the length of given vector XY.
    • getDotProduct

      public static double getDotProduct(double aX, double aY, double bX, double bY)
      Returns the dot product of two vectors.
    • getAngleBetween

      public static double getAngleBetween(double aX, double aY, double bX, double bY)
      Returns the angle between vectors (using given vector points).
    • getProjectedDistance

      public static double getProjectedDistance(double aX, double aY, double bX, double bY)
      Returns the length of V1 as projected onto V2 (using given vector points).
    • getVectorForAngleAndLength

      public static Vector getVectorForAngleAndLength(double anAngle, double length)
      Returns Vector for given angle and length.