public class Vector3d extends Object
Modifier and Type | Field and Description |
---|---|
double |
x
First element
|
double |
y
Second element
|
double |
z
Third element
|
Constructor and Description |
---|
Vector3d()
Creates a 3-vector and initializes its elements to 0.
|
Vector3d(double x,
double y,
double z)
Creates a 3-vector with the supplied element values.
|
Vector3d(Vector3d v)
Creates a 3-vector by copying an existing one.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Vector3d v1)
Adds this vector to v1 and places the result in this vector.
|
void |
add(Vector3d v1,
Vector3d v2)
Adds vector v1 to v2 and places the result in this vector.
|
void |
cross(Vector3d v1,
Vector3d v2)
Computes the cross product of v1 and v2 and places the result
in this vector.
|
double |
distance(Vector3d v)
Returns the Euclidean distance between this vector and vector v.
|
double |
distanceSquared(Vector3d v)
Returns the squared of the Euclidean distance between this vector
and vector v.
|
double |
dot(Vector3d v1)
Returns the dot product of this vector and v1.
|
double |
get(int i)
Gets a single element of this vector.
|
double |
norm()
Returns the 2 norm of this vector.
|
void |
normalize()
Normalizes this vector in place.
|
double |
normSquared()
Returns the square of the 2 norm of this vector.
|
void |
scale(double s)
Scales the elements of this vector by
s . |
void |
scale(double s,
Vector3d v1)
Scales the elements of vector v1 by
s and places
the results in this vector. |
void |
set(double x,
double y,
double z)
Sets the elements of this vector to the prescribed values.
|
void |
set(int i,
double value)
Sets a single element of this vector.
|
void |
set(Vector3d v1)
Sets the values of this vector to those of v1.
|
void |
setZero()
Sets the elements of this vector to zero.
|
void |
sub(Vector3d v1)
Subtracts v1 from this vector and places the result in this vector.
|
void |
sub(Vector3d v1,
Vector3d v2)
Subtracts vector v1 from v2 and places the result in this vector.
|
String |
toString()
Returns a string representation of this vector, consisting
of the x, y, and z coordinates.
|
public double x
public double y
public double z
public Vector3d()
public Vector3d(Vector3d v)
v
- vector to be copiedpublic Vector3d(double x, double y, double z)
x
- first elementy
- second elementz
- third elementpublic double get(int i)
i
- element indexpublic void set(int i, double value)
i
- element indexvalue
- element valuepublic void set(Vector3d v1)
v1
- vector whose values are copiedpublic void add(Vector3d v1, Vector3d v2)
v1
- left-hand vectorv2
- right-hand vectorpublic void add(Vector3d v1)
v1
- right-hand vectorpublic void sub(Vector3d v1, Vector3d v2)
v1
- left-hand vectorv2
- right-hand vectorpublic void sub(Vector3d v1)
v1
- right-hand vectorpublic void scale(double s)
s
.s
- scaling factorpublic void scale(double s, Vector3d v1)
s
and places
the results in this vector.s
- scaling factorv1
- vector to be scaledpublic double norm()
public double normSquared()
public double distance(Vector3d v)
public double distanceSquared(Vector3d v)
public double dot(Vector3d v1)
v1
- right-hand vectorpublic void normalize()
public void setZero()
public void set(double x, double y, double z)
x
- value for first elementy
- value for second elementz
- value for third elementpublic void cross(Vector3d v1, Vector3d v2)
v1
- left-hand vectorv2
- right-hand vectorProcessing Library ComputationalGeometry by Mark Collins & Toru Hasegawa. (c) 2015