Contents
- Description
- Constructor Summary
- Method Summary
- Constructor Details
- Method Details
- copy(Vector3D)
- clone()
- fromSpherical(double, double, double)
- setXYZ(double, double, double)
- setX(double)
- setY(double)
- setZ(double)
- x()
- y()
- z()
- r2()
- r()
- phi()
- costheta()
- theta()
- rho2()
- rho()
- isNull()
- mag2()
- mag()
- setMagThetaPhi(double, double, double)
- negative()
- add(Vector3D)
- sub(Vector3D)
- scale(double)
- unit()
- asUnit()
- setMag(double)
- add(double)
- subtract(double)
- multiply(double)
- divide(double)
- dot(Vector3D)
- cross(Vector3D)
- toPoint3D()
- compare(Vector3D)
- rotate(Point3D, double)
- rotate(Vector3D, double)
- angle(Vector3D, Vector3D)
- projection(Vector3D)
- angle(Vector3D)
- translateXYZ(double, double, double)
- rotateX(double)
- rotateY(double)
- rotateZ(double)
- show()
- toString()
- toStringBrief(int)
- toStringBrief()
- main(String[])
Class Vector3D
java.lang.Object
org.jlab.geom.prim.Vector3D
- All Implemented Interfaces:
Transformable
,Showable
A 3D vector represented by three Cartesian coordinates (x, y, z).
Though internally represented in Cartesian coordinates, the position of a
point can be set using spherical coordinates via
setMagThetaPhi(double, double, double)
, and the spherical
coordinates of any vector can be obtained via mag()
,
theta()
, and phi()
.
In addition to containing functions for performing normal mathematical
procedures involving vectors such as negate/inverse
,
addition
,
subtraction
,
scalar products
,
dot products
,
cross products
, and
normalization
, Vector3D
can be used to rotate a
point or vector around an arbitrary axes that passes through the origin via
rotate(Point3D, doubele)
and
rotate(Vector3D, double)
.
The inverse of the rotation functions is provided via
angle(Vector3D, Vector3D)
.
- Author:
- gavalian
-
Constructor Summary
ConstructorsConstructorDescriptionVector3D()
Constructs a new emptyVector3D
that is a null vector, ie (0,0,0).Vector3D
(double[] xyz) Constructs a newVector3D
with the given xyz[0], xyz[1], xyz[2] componentsVector3D
(double x, double y, double z) Constructs a newVector3D
with the given x, y, and z components.Constructs a newVector3D
identical to the given vector. -
Method Summary
Modifier and TypeMethodDescriptionadd
(double a) Adds the given vector to this vector.double
Angle between this and another vectordouble
Calculates the clockwise angle of rotation from the image of the first given vector to the image of the second given vector projected onto a plane who's normal is this vector and using this vector as an axis.asUnit()
Create unit vector from thisclone()
Returns a new instance of this vector.double
Returns a value greater than or equal to zero proportional to the amount that the two vectors differ.void
Sets the components of this vector to be equal the components of the given vector.double
costheta()
Constructs a newVector3D
containing the cross product of this vector and the given vector.divide
(double a) double
Returns the dot product of this vector and the given vector.static Vector3D
fromSpherical
(double r, double phi, double theta) Creates a new Vector3D instance from spherical coordinatesboolean
isNull()
Returns true if this vector is a null vector.double
mag()
Returns the magnitude of this vector.double
mag2()
Returns the square of the magnitude of this vector.static void
multiply
(double a) void
negative()
Negates this vector's components.double
phi()
Returns the angle between the x axis and the orthogonal projection of this vector onto the x-y plane.Projection of this vector onto another vectordouble
r()
double
r2()
double
rho()
Returns the length of the orthogonal projection of this vector onto the x-y plane.double
rho2()
void
Rotates the given point clockwise around the axis produced by this vector by the given anglevoid
Rotates the given vector clockwise around the axis produced by this vector by the given angle.void
rotateX
(double angle) Rotates this object clockwise around the x axis.void
rotateY
(double angle) Rotates this object clockwise around the y axis.void
rotateZ
(double angle) Rotates this object clockwise around the z axis.void
scale
(double factor) Scales each of this vectors components by the given scale factor.boolean
setMag
(double mag) Sets the magnitude of this vector to equal the given magnitude unless vector is a null vector.void
setMagThetaPhi
(double mag, double theta, double phi) Sets this vector based on the given spherical coordinates.void
setX
(double x) Sets the x component.void
setXYZ
(double x, double y, double z) Sets the x, y and z components of this vector.void
setY
(double y) Sets the y component.void
setZ
(double z) Sets the z component.void
show()
InvokesSystem.out.println(this)
.Subtracts the given vector from this vectorsubtract
(double a) double
theta()
Returns the angle between this vector and the z axis.Constructs a newPoint3D
using this vector's x, y, and z components.toString()
toStringBrief
(int ndigits) void
translateXYZ
(double x, double y, double z) Does nothing; vectors cannot be translated.boolean
unit()
Sets the magnitude of this vector to equal one unless this vector is a null vector.double
x()
Returns the x component.double
y()
Returns the y component.double
z()
Returns the z component.
-
Constructor Details
-
Vector3D
public Vector3D()Constructs a new emptyVector3D
that is a null vector, ie (0,0,0). -
Vector3D
public Vector3D(double x, double y, double z) Constructs a newVector3D
with the given x, y, and z components.- Parameters:
x
- the x componenty
- the y componentz
- the z component
-
Vector3D
public Vector3D(double[] xyz) Constructs a newVector3D
with the given xyz[0], xyz[1], xyz[2] components- Parameters:
xyz
- where x/y/z-components are xyz[0]/[1]/[2]
-
Vector3D
Constructs a newVector3D
identical to the given vector.- Parameters:
vector
- the vector to copy
-
-
Method Details
-
copy
Sets the components of this vector to be equal the components of the given vector.- Parameters:
vector
- the vector to copy
-
clone
-
fromSpherical
Creates a new Vector3D instance from spherical coordinates- Parameters:
r
- radial distance from the originphi
- azimuthal angle from the positive x-axis (right-handed)theta
- polar angle from the positive z-axis
-
setXYZ
public void setXYZ(double x, double y, double z) Sets the x, y and z components of this vector.- Parameters:
x
- the x componenty
- the y componentz
- the z component
-
setX
public void setX(double x) Sets the x component.- Parameters:
x
- the x component
-
setY
public void setY(double y) Sets the y component.- Parameters:
y
- the y component
-
setZ
public void setZ(double z) Sets the z component.- Parameters:
z
- the z component
-
x
public double x()Returns the x component.- Returns:
- the x component
-
y
public double y()Returns the y component.- Returns:
- the y component
-
z
public double z()Returns the z component.- Returns:
- the z component
-
r2
public double r2() -
r
public double r() -
phi
public double phi()Returns the angle between the x axis and the orthogonal projection of this vector onto the x-y plane.- Returns:
- the phi component of this vector's spherical coordinates
-
costheta
public double costheta() -
theta
public double theta()Returns the angle between this vector and the z axis.- Returns:
- the theta component of this vector's spherical coordinates
-
rho2
public double rho2() -
rho
public double rho()Returns the length of the orthogonal projection of this vector onto the x-y plane.- Returns:
- sqrt(x*x + y*y)
-
isNull
public boolean isNull()Returns true if this vector is a null vector.- Returns:
- true if this vector is a null vector
-
mag2
public double mag2()Returns the square of the magnitude of this vector.- Returns:
- the square of the magnitude of this vector
-
mag
public double mag()Returns the magnitude of this vector.- Returns:
- the magnitude of this vector
-
setMagThetaPhi
public void setMagThetaPhi(double mag, double theta, double phi) Sets this vector based on the given spherical coordinates.- Parameters:
mag
- the magnitudetheta
- the angle between the vector and the z axisphi
- the angle between the x axis and the orthogonal projection of the vector onto the x-y plane
-
negative
public void negative()Negates this vector's components. -
add
-
sub
-
scale
public void scale(double factor) Scales each of this vectors components by the given scale factor.- Parameters:
factor
- the amount to scale the components of this vector
-
unit
public boolean unit()Sets the magnitude of this vector to equal one unless this vector is a null vector.- Returns:
- returns false if this vector is a null vector
-
asUnit
-
setMag
public boolean setMag(double mag) Sets the magnitude of this vector to equal the given magnitude unless vector is a null vector.- Parameters:
mag
- the desired magnitude- Returns:
- returns false if this vector is a null vector
-
add
-
subtract
-
multiply
-
divide
-
dot
Returns the dot product of this vector and the given vector.- Parameters:
vector
- the vector to dot product with this vector- Returns:
- the dot product
-
cross
-
toPoint3D
Constructs a newPoint3D
using this vector's x, y, and z components.- Returns:
- a point representation of this vector
-
compare
Returns a value greater than or equal to zero proportional to the amount that the two vectors differ. If the two vectors are equal then the returned value is 0.- Parameters:
vector
- the vector to compare to- Returns:
- the comparison result
-
rotate
Rotates the given point clockwise around the axis produced by this vector by the given angle- Parameters:
point
- the point to rotateangle
- the angle of rotation
-
rotate
Rotates the given vector clockwise around the axis produced by this vector by the given angle.- Parameters:
vector
- the vector to rotateangle
- the angle of rotation
-
angle
Calculates the clockwise angle of rotation from the image of the first given vector to the image of the second given vector projected onto a plane who's normal is this vector and using this vector as an axis.- Parameters:
vector0
- the first vectorvector1
- the second vector- Returns:
- the angle between the two vectors
-
projection
-
angle
Angle between this and another vector- Parameters:
v
- another vector- Returns:
- the angle between the two vectors
-
translateXYZ
public void translateXYZ(double x, double y, double z) Does nothing; vectors cannot be translated.- Specified by:
translateXYZ
in interfaceTransformable
- Parameters:
x
- ignoredy
- ignoredz
- ignored
-
rotateX
public void rotateX(double angle) Description copied from interface:Transformable
Rotates this object clockwise around the x axis.- Specified by:
rotateX
in interfaceTransformable
- Parameters:
angle
- rotation angle in radians
-
rotateY
public void rotateY(double angle) Description copied from interface:Transformable
Rotates this object clockwise around the y axis.- Specified by:
rotateY
in interfaceTransformable
- Parameters:
angle
- rotation angle in radians
-
rotateZ
public void rotateZ(double angle) Description copied from interface:Transformable
Rotates this object clockwise around the z axis.- Specified by:
rotateZ
in interfaceTransformable
- Parameters:
angle
- rotation angle in radians
-
show
-
toString
-
toStringBrief
-
toStringBrief
-
main
-