public class ThreeDimensionalVector
extends java.lang.Object
implements java.lang.Comparable
Constructor and Description |
---|
ThreeDimensionalVector(double x,
double y,
double z)
Default constructor
|
Modifier and Type | Method and Description |
---|---|
ThreeDimensionalVector |
add(ThreeDimensionalVector other)
Returns a new vector with the result of the specified vector plus this.
|
int |
compareTo(java.lang.Object o) |
ThreeDimensionalVector |
crossProduct(ThreeDimensionalVector other)
Finds the cross product of the current vector and the other specified vector
|
double |
distanceTo(ThreeDimensionalVector other)
Finds the distance between two vectors
|
double |
dotProduct()
Finds the dot product of the current vector and itself
|
double |
dotProduct(ThreeDimensionalVector 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
|
int |
getRoundedZ()
Returns the z coord as an int
|
double |
getX()
Gets the x coord of the vector
|
double |
getY()
Gets the y coord of the vector
|
double |
getZ()
Gets the z coord of the vector
|
double |
length()
Finds the length of the vector
|
ThreeDimensionalVector |
midpoint(ThreeDimensionalVector other)
Returns a vector representing the midpoint between the current vector and another
|
ThreeDimensionalVector |
normalize()
Normalizes the vector to a length of 1 (all coords add up to one)
|
ThreeDimensionalVector |
rotateX(double angle)
Rotates the vector around the X-axis about the origin
|
ThreeDimensionalVector |
rotateX(ThreeDimensionalVector center,
double angle)
Rotates the vector around the X-axis
|
ThreeDimensionalVector |
rotateY(double angle)
Rotates the vector around the Y-axis about the origin
|
ThreeDimensionalVector |
rotateY(ThreeDimensionalVector center,
double angle)
Rotates the vector around the Y-axis
|
ThreeDimensionalVector |
rotateZ(double angle)
Rotates the vector around the Z-axis about the origin
|
ThreeDimensionalVector |
rotateZ(ThreeDimensionalVector center,
double angle)
Rotates the vector around the Z-axis
|
void |
setComponents(double x,
double y,
double z)
Sets the coordinates
|
ThreeDimensionalVector |
subtract(ThreeDimensionalVector other)
Returns a new vector with the result of the specified vector minus this.
|
TwoDimensionalVector |
to2D()
Converts this vector from a 3D plane to a 2D plane
|
java.lang.String |
toString() |
public ThreeDimensionalVector(double x, double y, double z)
x
- X coordinatey
- Y coordinatez
- Z coordinatepublic void setComponents(double x, double y, double z)
x
- X coordinatey
- Y coordinatez
- Z coordinatepublic int getRoundedX()
public int getRoundedY()
public int getRoundedZ()
public double getX()
public double getY()
public double getZ()
public ThreeDimensionalVector subtract(ThreeDimensionalVector other)
other
- The vector to subtract frompublic ThreeDimensionalVector add(ThreeDimensionalVector other)
other
- The vector to add topublic ThreeDimensionalVector normalize()
public double dotProduct()
public double dotProduct(ThreeDimensionalVector other)
other
- The other vectorpublic ThreeDimensionalVector crossProduct(ThreeDimensionalVector other)
other
- The other vectorpublic double distanceTo(ThreeDimensionalVector other)
other
- The other vectorpublic double length()
public ThreeDimensionalVector midpoint(ThreeDimensionalVector other)
other
- The other vectorpublic ThreeDimensionalVector rotateX(ThreeDimensionalVector center, double angle)
center
- The coordinate to rotate aroundangle
- The angle to rotate bypublic ThreeDimensionalVector rotateX(double angle)
angle
- The angle to rotate bypublic ThreeDimensionalVector rotateY(ThreeDimensionalVector center, double angle)
center
- The coordinate to rotate aroundangle
- The angle to rotate bypublic ThreeDimensionalVector rotateY(double angle)
angle
- The angle to rotate bypublic ThreeDimensionalVector rotateZ(ThreeDimensionalVector center, double angle)
center
- The coordinate to rotate aroundangle
- The angle to rotate bypublic ThreeDimensionalVector rotateZ(double angle)
angle
- The angle to rotate bypublic TwoDimensionalVector to2D()
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