|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectappletbots.geometry.Vector
public class Vector
This class represents an immutable two-dimensional vector
| Field Summary | |
|---|---|
double |
x
The x-component of the vector |
static Vector |
X_AXIS
A normalized vector in the direction of the x-axis |
double |
y
The y-component of the vector |
static Vector |
Y_AXIS
A normalized vector in the direction of the y-axis |
static Vector |
ZERO
A zero vector |
| Constructor Summary | |
|---|---|
Vector(double x,
double y)
Creates a new vector with the given x and y components |
|
Vector(Point start,
Point end)
Constructs a new vector from one point to another |
|
| Method Summary | |
|---|---|
Vector |
add(Vector v)
Returns the result of adding this vector to another vector |
static Vector |
average(java.util.Collection vectors)
Returns the average of a collection of vectors |
java.lang.Object |
clone()
Returns a copy of this vector |
int |
compareTo(java.lang.Object o)
Compares this vector to another based solely on magnitude. |
Vector |
divide(double divisor)
Returns the result of dividinig this vector by a scalar number |
double |
dotProduct(Vector v)
Returns the dot product of this vector and another vector |
boolean |
equals(java.lang.Object obj)
Returns whether or not this vector equals another vector |
double |
getAngleToVector(Vector v)
Returns the angle (in radians) from this vector to the given vector |
double |
getLength()
Returns the length of the vector |
static Vector |
getRandom(double length)
Returns a random vector of the given length |
boolean |
isAligned(Vector v)
Returns whether or not this vector is aligned (pointing in same direction) to the given vector |
boolean |
isParallel(Vector v)
Returns whether or not this vector is parellel to the given vector |
Vector |
multiply(double multiplicand)
Returns the result of multiplying this vector times a scalar number |
Vector |
normalize()
Creates a new vector aligned with this one with a length of 1 |
Vector |
rotate(double theta)
Returns the result of rotating this vector by theta radians |
Vector |
setLength(double length)
Creates a new vector aligned with this one with the given length |
Vector |
subtract(Vector v)
Returns the result of subtracting another vector from this vector |
java.lang.String |
toString()
Returns a string representation of this vector |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public double x
public double y
public static Vector ZERO
public static Vector X_AXIS
public static Vector Y_AXIS
| Constructor Detail |
|---|
public Vector(double x,
double y)
x - The x-component of the vectory - The y-component of the vector
public Vector(Point start,
Point end)
start - The start pointend - The end point| Method Detail |
|---|
public static Vector getRandom(double length)
length - The length of the vector
public static Vector average(java.util.Collection vectors)
vectors - A collection of vectors
public double getLength()
public Vector setLength(double length)
length - The length of the new vector
public Vector normalize()
public Vector multiply(double multiplicand)
multiplicand - The scalar number to multiply the vector by
public Vector divide(double divisor)
divisor - The scalar number to divide the vector by
public Vector add(Vector v)
v - Another vector
public Vector subtract(Vector v)
v - Another vector
public double dotProduct(Vector v)
v - Another vector
public Vector rotate(double theta)
theta - The number of radians to rotate the vector
public double getAngleToVector(Vector v)
v - Another vector
public boolean isParallel(Vector v)
v - Another vector
public boolean isAligned(Vector v)
v - Another vector
public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectobj - Another vector
public java.lang.Object clone()
clone in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic int compareTo(java.lang.Object o)
compareTo in interface java.lang.Comparableo - the Object to be compared.
java.lang.ClassCastException - if the specified object's type prevents it
from being compared to this Object.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||