Package org.evoludo.geom
Class Vector3D
- All Implemented Interfaces:
Point
Utility class for 3D vector manipulations.
- Author:
- Christoph Hauert
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(double dx, double dy, double dz) Shift the coordinates of this 3D vector bydx,dyanddzin thex-,y-, andz-coordinates, respectively.Add the 3D vectorsaandband store result in this vector.Add the 3D vectoraddto this vector.Calculate the cross product of the 3D vectordand this vector.Calculate the cross product of two 3D vectorsa,band store result in this vector.doubleCalculate the dot product of 3D vectordand this vector.doublelength()Calculate the length of the 3D vector.doublelength2()Calculate the length squared of the 3D vector,|v|2.doubleSame aslength2().negate()Negates the coordinates of 3D vectorvto obtain-v.Normalizes the 3D vectorvsuch that its length is|v|=1while preserving the direction.normalize(double l) Normalizes the 3D vectorvsuch that its length isl, i.e.Scales the 3D vectorvby the scalar factorsand adds the 3D vectora,v=s*v+a.Set the 3D vector pointing fromfromtoto.sub(double dx, double dy, double dz) Subtractdx,dyanddzfrom thex-,y-, andz-coordinates, respectively.Subtract the 3D vectorsubfrom this vector.Subtract 3D vectorsbfromaand store result in this 3D vector.toString()
-
Constructor Details
-
Vector3D
public Vector3D()Create a new 3D vector(0,0,0). -
Vector3D
Create a new 3D vector from pointp.- Parameters:
p- the point/vector to copy
-
Vector3D
public Vector3D(double x, double y, double z) Create a new 3D vector with coordinates(x,y,z).- Parameters:
x- thex-coordinatey- they-coordinatez- thez-coordinate
-
-
Method Details
-
set
Set the 3D vector pointing fromfromtoto.- Parameters:
from- the starting pointto- the end point- Returns:
- the new vector
-
add
Shift the coordinates of this 3D vector bydx,dyanddzin thex-,y-, andz-coordinates, respectively.- Parameters:
dx- the shift in thex-coordinatedy- the shift in they-coordinatedz- the shift in thez-coordinate- Returns:
- the shifted vector
(x+dx,y+dy,z+dz)
-
add
Add the 3D vectoraddto this vector.- Parameters:
add- the vector to add- Returns:
- this new vector
-
add
Add the 3D vectorsaandband store result in this vector.- Parameters:
a- the first vectorb- the second vector- Returns:
- the new vector
a+b
-
sub
Subtractdx,dyanddzfrom thex-,y-, andz-coordinates, respectively. This yields the same result asadd(-dx, -dy, -dz).- Parameters:
dx- the shift in thex-coordinatedy- the shift in they-coordinatedz- the shift in thez-coordinate- Returns:
- this new 3D vector
(x-dx,y-dy,z-dz)
-
sub
Subtract the 3D vectorsubfrom this vector.- Parameters:
sub- the vector to subtract- Returns:
- this new vector
-
sub
Subtract 3D vectorsbfromaand store result in this 3D vector.- Parameters:
a- the first vector for subtractionb- the vector to subtract froma- Returns:
- the vector
a-b
-
dot
Calculate the dot product of 3D vectordand this vector.- Parameters:
d- the vector to calculate the dot product with- Returns:
- the dot product
v.d
-
cross
Calculate the cross product of the 3D vectordand this vector.- Parameters:
d- the vector for cross product- Returns:
- the cross product
v x d
-
cross
Calculate the cross product of two 3D vectorsa,band store result in this vector.- Parameters:
a- the first vectorb- the second vector- Returns:
- the cross product
v=a x b
-
negate
Negates the coordinates of 3D vectorvto obtain-v.- Returns:
- the vector
v=-v
-
normalize
Normalizes the 3D vectorvsuch that its length is|v|=1while preserving the direction.- Returns:
- the normalized vector
- See Also:
-
normalize
Normalizes the 3D vectorvsuch that its length isl, i.e.|v|=l, while preserving the direction.- Parameters:
l- the new length of the vector- Returns:
- the scaled vector
- See Also:
-
scaleAdd
Scales the 3D vectorvby the scalar factorsand adds the 3D vectora,v=s*v+a. This is a shortcut forv.scale(s).add(a).- Parameters:
s- the scalar factora- the vector to add- Returns:
- the new vector
s*v+a
-
length
public double length()Calculate the length of the 3D vector.For computational efficiency the fairly expensive square-roots calculations should be avoided whenever possible.
- Returns:
- the length of vector
|v| - See Also:
-
length2
public double length2()Calculate the length squared of the 3D vector,|v|2.- Returns:
- the length squared
- See Also:
-
lengthSquared
public double lengthSquared()Same aslength2(). For (historical) compatibility withVector3ffrom java3d.- Returns:
- the length squared
- See Also:
-
toString
-