- Object
-
- Vector3
-
-
Constructor Summary
Constructors Constructor Description Vector3()
Default constructor.Vector3(double x, double y, double z)
Optional constructor.Vector3(double x1, double y1, double z1, double x2, double y2, double z2)
Creates aVector3
from the first point to the second point.Vector3(Vector3 vector)
Copy constructor.Vector3(Vector3 p1, Vector3 p2)
Creates aVector3
from the first point to the second point.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Vector3
add(double x, double y, double z)
Vector3
add(Vector3 vector)
Vector3
copy()
Returns a deep copy of this object.Vector3
cross(double x, double y, double z)
Vector3
cross(Vector3 vector)
Vector3
difference(double x, double y, double z)
Vector3
difference(Vector3 vector)
double
distance(double x, double y, double z)
Returns the distance from this point to the given point.double
distance(Vector3 point)
Returns the distance from this point to the given point.double
distanceSquared(double x, double y, double z)
Returns the distance from this point to the given point squared.double
distanceSquared(Vector3 point)
Returns the distance from this point to the given point squared.double
dot(double x, double y, double z)
double
dot(Vector3 vector)
boolean
equals(double x, double y, double z)
Returns true if the x, y and z components of thisVector3
are the same as the given x, y and z components.boolean
equals(Object obj)
boolean
equals(Vector3 vector)
double
getMagnitude()
Returns the magnitude of thisVector3
.double
getMagnitudeSquared()
Returns the magnitude of thisVector3
squared.Vector3
getNegative()
Vector3
getNormalized()
Vector3
getXComponent()
Returns the x component of thisVector3
.Vector3
getYComponent()
Returns the y component of thisVector3
.Vector3
getZComponent()
Returns the z component of thisVector3
.int
hashCode()
boolean
isOrthogonal(double x, double y, double z)
boolean
isOrthogonal(Vector3 vector)
boolean
isZero()
Vector3
multiply(double scalar)
Multiplies thisVector3
by the given scalar.Vector3
negate()
Negates thisVector3
.double
normalize()
Vector3
product(double scalar)
Vector3
project(Vector3 vector)
Vector3
set(double x, double y, double z)
Vector3
set(Vector3 vector)
Vector3
setMagnitude(double magnitude)
Sets the magnitude of theVector3
.Vector3
subtract(double x, double y, double z)
Vector3
subtract(Vector3 vector)
Vector3
sum(double x, double y, double z)
Vector3
sum(Vector3 vector)
Vector3
to(double x, double y, double z)
Vector3
to(Vector3 vector)
String
toString()
static Vector3
tripleProduct(Vector3 a, Vector3 b, Vector3 c)
The triple product ofVector3
s is defined as:Vector3
zero()
-
-
-
Constructor Detail
-
Vector3
public Vector3()
Default constructor.
-
Vector3
public Vector3(Vector3 vector)
Copy constructor.- Parameters:
vector
- theVector3
to copy from
-
Vector3
public Vector3(double x, double y, double z)
Optional constructor.- Parameters:
x
- the x componenty
- the y componentz
- the z component
-
Vector3
public Vector3(double x1, double y1, double z1, double x2, double y2, double z2)
Creates aVector3
from the first point to the second point.- Parameters:
x1
- the x coordinate of the first pointy1
- the y coordinate of the first pointz1
- the z coordinate of the first pointx2
- the x coordinate of the second pointy2
- the y coordinate of the second pointz2
- the z coordinate of the second point
-
-
Method Detail
-
copy
public Vector3 copy()
Description copied from interface:Copyable
Returns a deep copy of this object.
-
distance
public double distance(double x, double y, double z)
Returns the distance from this point to the given point.- Parameters:
x
- the x coordinate of the pointy
- the y coordinate of the pointz
- the z coordinate of the point- Returns:
- double
-
distance
public double distance(Vector3 point)
Returns the distance from this point to the given point.- Parameters:
point
- the point- Returns:
- double
-
distanceSquared
public double distanceSquared(double x, double y, double z)
Returns the distance from this point to the given point squared.- Parameters:
x
- the x coordinate of the pointy
- the y coordinate of the pointz
- the z coordinate of the point- Returns:
- double
-
distanceSquared
public double distanceSquared(Vector3 point)
Returns the distance from this point to the given point squared.- Parameters:
point
- the point- Returns:
- double
-
tripleProduct
public static Vector3 tripleProduct(Vector3 a, Vector3 b, Vector3 c)
The triple product ofVector3
s is defined as:a x (b x c)
However, this method performs the following triple product:(a x b) x c
this can be simplified to:-a * (b · c) + b * (a · c)
or:b * (a · c) - a * (b · c)
-
equals
public boolean equals(Vector3 vector)
- Parameters:
vector
- theVector3
to compare to- Returns:
- boolean
-
equals
public boolean equals(double x, double y, double z)
Returns true if the x, y and z components of thisVector3
are the same as the given x, y and z components.
-
set
public Vector3 set(double x, double y, double z)
-
getXComponent
public Vector3 getXComponent()
Returns the x component of thisVector3
.- Returns:
Vector3
-
getYComponent
public Vector3 getYComponent()
Returns the y component of thisVector3
.- Returns:
Vector3
-
getZComponent
public Vector3 getZComponent()
Returns the z component of thisVector3
.- Returns:
Vector3
-
getMagnitude
public double getMagnitude()
Returns the magnitude of thisVector3
.- Returns:
- double
-
getMagnitudeSquared
public double getMagnitudeSquared()
Returns the magnitude of thisVector3
squared.- Returns:
- double
-
setMagnitude
public Vector3 setMagnitude(double magnitude)
Sets the magnitude of theVector3
.- Parameters:
magnitude
- the magnitude- Returns:
Vector3
this vector
-
add
public Vector3 add(double x, double y, double z)
-
sum
public Vector3 sum(double x, double y, double z)
-
subtract
public Vector3 subtract(double x, double y, double z)
-
difference
public Vector3 difference(double x, double y, double z)
-
to
public Vector3 to(double x, double y, double z)
-
multiply
public Vector3 multiply(double scalar)
Multiplies thisVector3
by the given scalar.- Parameters:
scalar
- the scalar- Returns:
Vector3
this vector
-
dot
public double dot(double x, double y, double z)
-
cross
public Vector3 cross(double x, double y, double z)
-
isOrthogonal
public boolean isOrthogonal(Vector3 vector)
Returns true if the givenVector3
is orthogonal (perpendicular) to thisVector3
.If the dot product of this vector and the given vector is zero then we know that they are perpendicular
- Parameters:
vector
- theVector3
- Returns:
- boolean
-
isOrthogonal
public boolean isOrthogonal(double x, double y, double z)
-
isZero
public boolean isZero()
- Returns:
- boolean
-
getNormalized
public Vector3 getNormalized()
Returns a unitVector3
of thisVector3
.This method requires the length of this
Vector3
is not zero.- Returns:
Vector3
-
-