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
,dy
anddz
in thex
-,y
-, andz
-coordinates, respectively.Add the 3D vectorsa
andb
and store result in this vector.Add the 3D vectoradd
to this vector.Calculate the cross product of the 3D vectord
and this vector.Calculate the cross product of two 3D vectorsa
,b
and store result in this vector.double
Calculate the dot product of 3D vectord
and this vector.double
length()
Calculate the length of the 3D vector.double
length2()
Calculate the length squared of the 3D vector,|v|2
.double
Same aslength2()
.negate()
Negates the coordinates of 3D vectorv
to obtain-v
.Normalizes the 3D vectorv
such that its length is|v|=1
while preserving the direction.normalize
(double l) Normalizes the 3D vectorv
such that its length isl
, i.e.Scales the 3D vectorv
by the scalar factors
and adds the 3D vectora
,v=s*v+a
.Set the 3D vector pointing fromfrom
toto
.sub
(double dx, double dy, double dz) Subtractdx
,dy
anddz
from thex
-,y
-, andz
-coordinates, respectively.Subtract the 3D vectorsub
from this vector.Subtract 3D vectorsb
froma
and 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 fromfrom
toto
.- Parameters:
from
- the starting pointto
- the end point- Returns:
- the new vector
-
add
Shift the coordinates of this 3D vector bydx
,dy
anddz
in 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 vectoradd
to this vector.- Parameters:
add
- the vector to add- Returns:
- this new vector
-
add
Add the 3D vectorsa
andb
and store result in this vector.- Parameters:
a
- the first vectorb
- the second vector- Returns:
- the new vector
a+b
-
sub
Subtractdx
,dy
anddz
from 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 vectorsub
from this vector.- Parameters:
sub
- the vector to subtract- Returns:
- this new vector
-
sub
Subtract 3D vectorsb
froma
and 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 vectord
and 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 vectord
and 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
,b
and 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 vectorv
to obtain-v
.- Returns:
- the vector
v=-v
-
normalize
Normalizes the 3D vectorv
such that its length is|v|=1
while preserving the direction.- Returns:
- the normalized vector
- See Also:
-
normalize
Normalizes the 3D vectorv
such 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 vectorv
by the scalar factors
and 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 withVector3f
from java3d.- Returns:
- the length squared
- See Also:
-
toString
-