Package snap.geom

Class Vect

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

public class Vect 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.
    Vect(double aX, double aY)
    Constructor for given XY coords.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(Vect aVect)
    Add the given vector to this.
    Standard clone implementation.
    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 magnitude of the vector.
    static double
    getMagnitude(double aX, double aY)
    Returns the magnitude of a vector.
    static double
    getProjectedDistance(double aX, double aY, double bX, double bY)
    Returns the length of V1 as projected onto V2 (using given vector points).
    boolean
    isAligned(Vect aVect, boolean includePerpendiculars)
    Returns whether given vector is in same general direction of this (with option to include perpendiculars).
    boolean
    isAway(Vect aVect, 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(Vect aVect)
    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

    • Vect

      public Vect()
      Constructor.
    • Vect

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

    • getMagnitude

      public double getMagnitude()
      Returns the magnitude of the vector.
    • normalize

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

      public void add(Vect aVect)
      Add the given vector to this.
    • getDotProduct

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

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

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

      public double getAngleBetween(Vect aVect)
      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(Vect aVect)
      Sets the X/Y values.
    • setXY

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

      public Vect 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
    • getMagnitude

      public static double getMagnitude(double aX, double aY)
      Returns the magnitude of a vector.
    • 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).