public final class Vect
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static Vect |
X_HAT
A unit vector in the positive x direction
|
static Vect |
Y_HAT
A unit vector in the positive y direction
|
static Vect |
ZERO
A Vect with zero length
|
Constructor and Description |
---|
Vect(Angle angle) |
Vect(Angle angle,
double length) |
Vect(double x,
double y)
Constructs a new vector in Cartesian space with coordinates (x,y).
|
Vect(java.awt.geom.Point2D p) |
Modifier and Type | Method and Description |
---|---|
Angle |
angle() |
double |
distanceSquared(Vect b) |
double |
dot(Vect b) |
boolean |
equals(java.lang.Object o) |
boolean |
equals(Vect v) |
int |
hashCode() |
double |
length() |
Vect |
minus(Vect b) |
Vect |
neg() |
Vect |
plus(Vect b) |
Vect |
projectOn(Vect b)
Returns the projection of this onto the unit vector
b ![]() |
Vect |
rotateBy(Angle a) |
Vect |
times(double amt) |
java.awt.geom.Point2D.Double |
toPoint2D() |
java.lang.String |
toString() |
Vect |
unitSize() |
double |
x() |
double |
y() |
public static final Vect ZERO
public static final Vect X_HAT
public static final Vect Y_HAT
public Vect(Angle angle)
angle
- ; requires that angle
is not null
Constructs a new unit vector in the direction of angle
.public Vect(Angle angle, double length)
angle
- ; requires that angle
is not null
Constructs a new vector in the direction of angle
with length length
.public Vect(double x, double y)
public Vect(java.awt.geom.Point2D p)
p
- ; requires that p
is not null
Constructs a new vector in Cartesian space located at the
coordinates specified by p
public Angle angle()
this
in polar coordinatespublic double length()
this
public double x()
this
in Cartesian coordinatespublic double y()
this
in Cartesian coordinatespublic double distanceSquared(Vect b)
b
- vect of the d^2 to be computed; requires that b
is not nullthis
and b
public Vect plus(Vect b)
b
- vector to add to; requires that b
is not nullthis
and b
public Vect minus(Vect b)
b
- vect to subtract from this; requires that b
is not nullthis
and
b
public Vect rotateBy(Angle a)
a
- angle to rotate by; requires that a
is not nullthis
having been rotated around the origin by a
.public Vect neg()
this
being rotated by pi radians.public Vect times(double amt)
this
scaled
by amt
.public Vect projectOn(Vect b)
b
b
- vect to project on; requires that b
is a unit vectorthis
onto
b
. The resulting vector c has the same angle as
b
, but its length is such that this
-
c
is perpendicular to c
.public Vect unitSize()
this
public double dot(Vect b)
b
- vect to take dot product of; requires that
b
is not nullthis
and
b
.public java.awt.geom.Point2D.Double toPoint2D()
Point2D
object which is
located at the same point as this
.public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(Vect v)
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object