public class TwoDimensionalVector
extends java.lang.Object
implements java.lang.Comparable
Constructor and Description |
---|
TwoDimensionalVector(double x,
double y)
Default constructor
|
Modifier and Type | Method and Description |
---|---|
TwoDimensionalVector |
add(TwoDimensionalVector other)
Returns a new vector with the result of the specified vector plus this.
|
int |
compareTo(java.lang.Object o) |
double |
distanceTo(TwoDimensionalVector other)
Finds the distance between two vectors
|
double |
dotProduct()
Finds the dot product of the current vector and itself
|
double |
dotProduct(TwoDimensionalVector other)
Finds the dot product of the current vector and the other specified vector
|
boolean |
equals(java.lang.Object other) |
int |
getRoundedX()
Returns the x coord as an int
|
int |
getRoundedY()
Returns the y coord as an int
|
double |
getX()
Gets the x coord of the vector
|
double |
getY()
Gets the y coord of the vector
|
double |
length()
Finds the length of the vector
|
TwoDimensionalVector |
midpoint(TwoDimensionalVector other)
Returns a vector representing the midpoint between the current vector and another
|
TwoDimensionalVector |
normalize()
Normalizes the vector to a length of 1 (all coords add up to one)
|
TwoDimensionalVector |
rotate(double angle)
Rotates the vector around the origin
|
TwoDimensionalVector |
rotate(TwoDimensionalVector center,
double angle)
Rotates the vector around a given point
|
void |
setComponents(double x,
double y)
Sets the coordinates
|
TwoDimensionalVector |
subtract(TwoDimensionalVector other)
Returns a new vector with the result of the specified vector minus this.
|
ThreeDimensionalVector |
to3D()
Converts this vector from a 2D plane to a 3D plane (with a z of 0)
|
java.lang.String |
toString() |
public TwoDimensionalVector(double x, double y)
x
- X coordinatey
- Y coordinatepublic void setComponents(double x, double y)
x
- X coordinatey
- Y coordinatepublic int getRoundedX()
public int getRoundedY()
public double getX()
public double getY()
public TwoDimensionalVector subtract(TwoDimensionalVector other)
other
- The vector to subtract frompublic TwoDimensionalVector add(TwoDimensionalVector other)
other
- The vector to add topublic TwoDimensionalVector normalize()
public double dotProduct()
public double dotProduct(TwoDimensionalVector other)
other
- The other vectorpublic double distanceTo(TwoDimensionalVector other)
other
- The other vectorpublic double length()
public TwoDimensionalVector midpoint(TwoDimensionalVector other)
other
- The other vectorpublic TwoDimensionalVector rotate(TwoDimensionalVector center, double angle)
center
- The point to rotate aroundangle
- The angle to rotate bypublic TwoDimensionalVector rotate(double angle)
angle
- The angle to rotate bypublic ThreeDimensionalVector to3D()
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public int compareTo(java.lang.Object o)
compareTo
in interface java.lang.Comparable