Package ffx.numerics.quickhull
Class Vector3d
java.lang.Object
ffx.numerics.quickhull.Vector3d
- Direct Known Subclasses:
Point3d
A three-element vector. This class is actually a reduced version of the
Vector3d class contained in the author's matlib package (which was partly
inspired by javax.vecmath). Only a mininal number of methods which are
relevant to convex hull generation are supplied here.
- Since:
- 1.0
- Author:
- John E. Lloyd, Fall 2004, Michael J. Schnieders
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds this vector to v1 and places the result in this vector.void
Adds vector v1 to v2 and places the result in this vector.void
Computes the cross product of v1 and v2 and places the result in this vector.double
Returns the Euclidean distance between this vector and vector v.double
Returns the squared of the Euclidean distance between this vector and vector v.double
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
Normalizes this vector in place.double
Returns the square of the 2 norm of this vector.void
scale
(double s) Scales the elements of this vector bys
.void
Scales the elements of vector v1 bys
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
Sets the values of this vector to those of v1.protected void
Sets the elements of this vector to uniformly distributed random values in a specified range, using a supplied random number generator.void
setZero()
Sets the elements of this vector to zero.void
Subtracts v1 from this vector and places the result in this vector.void
Subtracts vector v1 from v2 and places the result in this vector.toString()
Returns a string representation of this vector, consisting of the x, y, and z coordinates.
-
Field Details
-
x
public double xFirst element -
y
public double ySecond element -
z
public double zThird element
-
-
Constructor Details
-
Vector3d
public Vector3d()Creates a 3-vector and initializes its elements to 0. -
Vector3d
Creates a 3-vector by copying an existing one.- Parameters:
v
- vector to be copied
-
Vector3d
public Vector3d(double x, double y, double z) Creates a 3-vector with the supplied element values.- Parameters:
x
- first elementy
- second elementz
- third element
-
-
Method Details
-
get
public double get(int i) Gets a single element of this vector. Elements 0, 1, and 2 correspond to x, y, and z.- Parameters:
i
- element index- Returns:
- element value throws ArrayIndexOutOfBoundsException if i is not in the range 0 to 2.
-
set
public void set(int i, double value) Sets a single element of this vector. Elements 0, 1, and 2 correspond to x, y, and z. Element value throws ArrayIndexOutOfBoundsException if i is not in the range 0 to 2.- Parameters:
i
- element indexvalue
- element value
-
set
Sets the values of this vector to those of v1.- Parameters:
v1
- vector whose values are copied
-
add
Adds vector v1 to v2 and places the result in this vector.- Parameters:
v1
- left-hand vectorv2
- right-hand vector
-
add
Adds this vector to v1 and places the result in this vector.- Parameters:
v1
- right-hand vector
-
sub
Subtracts vector v1 from v2 and places the result in this vector.- Parameters:
v1
- left-hand vectorv2
- right-hand vector
-
sub
Subtracts v1 from this vector and places the result in this vector.- Parameters:
v1
- right-hand vector
-
scale
public void scale(double s) Scales the elements of this vector bys
.- Parameters:
s
- scaling factor
-
scale
Scales the elements of vector v1 bys
and places the results in this vector.- Parameters:
s
- scaling factorv1
- vector to be scaled
-
norm
public double norm()Returns the 2 norm of this vector. This is the square root of the sum of the squares of the elements.- Returns:
- vector 2 norm
-
normSquared
public double normSquared()Returns the square of the 2 norm of this vector. This is the sum of the squares of the elements.- Returns:
- square of the 2 norm
-
distance
Returns the Euclidean distance between this vector and vector v.- Returns:
- distance between this vector and v
-
distanceSquared
Returns the squared of the Euclidean distance between this vector and vector v.- Returns:
- squared distance between this vector and v
-
dot
Returns the dot product of this vector and v1.- Parameters:
v1
- right-hand vector- Returns:
- dot product
-
normalize
public void normalize()Normalizes this vector in place. -
setZero
public void setZero()Sets the elements of this vector to zero. -
set
public void set(double x, double y, double z) Sets the elements of this vector to the prescribed values.- Parameters:
x
- value for first elementy
- value for second elementz
- value for third element
-
cross
Computes the cross product of v1 and v2 and places the result in this vector.- Parameters:
v1
- left-hand vectorv2
- right-hand vector
-
setRandom
Sets the elements of this vector to uniformly distributed random values in a specified range, using a supplied random number generator.- Parameters:
lower
- lower random value (inclusive)upper
- upper random value (exclusive)generator
- random number generator
-
toString
Returns a string representation of this vector, consisting of the x, y, and z coordinates.
-