public class Vector3D
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
double |
x
The public x-coordinate.
|
double |
y
The public y-coordinate.
|
double |
z
The public z-coordinate.
|
Constructor and Description |
---|
Vector3D()
Constructs a zero vector (with coordinates (0, 0, 0)).
|
Vector3D(double x,
double y,
double z)
Constructs a vector from given double x-y-coordinates.
|
Vector3D(float x,
float y,
float z)
Constructs a vector from given float x-y-coordinates.
|
Vector3D(int x,
int y,
int z)
Constructs a vector from given integer x-y-coordinates.
|
Modifier and Type | Method and Description |
---|---|
Vector3D |
add(Vector3D v)
Returns a new vector that is the vector sum of the current vector and the given vector.
|
Vector3D |
clone()
Returns a new vector with the same coordinates as the current vector.
|
double |
distanceTo(Vector3D v)
Returns the distance between the current vector and the given vector.
|
double |
dot(Vector3D v)
Returns the scalar product (dot product) of the current vector with the given vector.
|
Vector3D |
getNormalized()
Returns a new vector with magnitude 1 in the direction of the given vector.
|
double |
getPhi()
Returns the phi direction of the vector (range 0..2*pi).
|
double |
getTheta()
Returns the phi direction of the vector (range 0..2*pi).
|
Vector3D |
invert()
Returns a new vector with inverted coordinates.
|
boolean |
isEqual(Vector3D v)
Returns true, if the current vector is identical to the given vector.
|
double |
magnitude()
Returns the magnitude (length) of the vector.
|
double |
magnitude2()
Returns the square of the magnitude, without squareroot calculation.
|
Vector3D |
mult(double b)
Returns a new vector that is the product by a scalar of the current vector and the given double.
|
Vector3D |
mult(float b)
Returns a new vector that is the product by a scalar of the current vector and the given float.
|
Vector3D |
mult(int b)
Returns a new vector that is the product by a scalar of the current vector and the given integer.
|
void |
normalize()
Modifies the vector to unit magnitude.
|
Vector3D |
sub(Vector3D v)
Returns a new vector that is the vector difference of the current vector and the given vector.
|
java.lang.String |
toString()
Returns a string with the x-y-coordinates in the format (x,y,z).
|
public double x
public double y
public double z
public Vector3D()
public Vector3D(int x, int y, int z)
x
- the x-coordinate of the vectory
- the y-coordinate of the vectorz
- the z-coordinate of the vectorpublic Vector3D(float x, float y, float z)
x
- the x-coordinate of the vectory
- the y-coordinate of the vectorz
- the z-coordinate of the vectorpublic Vector3D(double x, double y, double z)
x
- the x-coordinate of the vectory
- the y-coordinate of the vectorz
- the z-coordinate of the vectorpublic double magnitude()
public double magnitude2()
public void normalize()
public Vector3D getNormalized()
public double getPhi()
public double getTheta()
public double dot(Vector3D v)
v
- the vector to take for the dot productpublic double distanceTo(Vector3D v)
v
- the vector to take for the distance measurementpublic Vector3D add(Vector3D v)
v
- the vector to be added to the current vectorpublic Vector3D invert()
public Vector3D sub(Vector3D v)
v
- the vector to be substracted from the current vectorpublic Vector3D mult(int b)
b
- the integer scale factorpublic Vector3D mult(float b)
b
- the float scale factorpublic Vector3D mult(double b)
b
- the double scale factorpublic Vector3D clone()
clone
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public boolean isEqual(Vector3D v)
v
- the vector to compare