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
-
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
-
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
-
sub
-
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
-
cross
-
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
-
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
-