Package snap.geom
Class Vector
java.lang.Object
snap.geom.Vector
- All Implemented Interfaces:
Cloneable
This class represents a vector.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add the given vector to this.clone()
Standard clone implementation.double
getAngle()
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
getAngleBetween
(Vector aVector) 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
getDotProduct
(Vector v2) 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
Returns whether given vector is in same general direction of this (with option to include perpendiculars).boolean
Returns whether given vector is pointing away from the direction of this (with option to include perpendiculars).void
negate()
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
Sets the X/Y values.toString()
Returns a string representation of the vector.void
Transforms this vector by the given transform.
-
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
Add the given vector to this. -
getDotProduct
Returns the dot product of the receiver and the given vector. -
isAligned
Returns whether given vector is in same general direction of this (with option to include perpendiculars). -
isAway
Returns whether given vector is pointing away from the direction of this (with option to include perpendiculars). -
getAngleBetween
Returns the angle between the receiver and the given vector. -
negate
public void negate()Makes this receiver point in the opposite direction. -
transform
Transforms this vector by the given transform. -
setXY
Sets the X/Y values. -
setXY
public void setXY(double aX, double aY) Sets the X/Y values. -
clone
Standard clone implementation. -
toString
Returns a string representation of the vector. -
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
Returns Vector for given angle and length.
-