Package ucar.nc2.dt.ugrid.geom
Class Vector3D
- java.lang.Object
-
- ucar.nc2.dt.ugrid.geom.Vector3D
-
public class Vector3D extends Object
Holds the u, v and w components of a vector as well as it's origin (Point3D).The class also provides methods to perform mathematical operations on this and other vectors (addition, subtraction, multiplication, division, cross multiplication, and dot multiplication)
-
-
Constructor Summary
Constructors Constructor Description Vector3D()Creates a new instance of Vector3D with an origin of (0, 0, 0) and no magnitude (u=0, v=0, w=0)Vector3D(double u, double v, double w)Creates a new instance of Vector3D with an origin of (0, 0, 0) and the specified u, v, and w magnitudes.Vector3D(Point3D origin, double u, double v, double w)Creates a new instance of Vector3D with the specified origin and u, v, and w magnitudes.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Vector3Dadd(Vector3D v1, Vector3D v2)Adds the numerical value of each component of the first vector with the values in the second vector.Vector3Dcross(Vector3D other)Determines the cross product of thisVector3Dwith the one givenstatic Vector3Dcross(Vector3D v1, Vector3D v2)Determines the cross product of the two given vectorsstatic Vector3Ddiv(Vector3D v, double d)Divides the numerical value of each component of the vector by a given scalar.doubledot(Vector3D other)Determines the dot product of thisVector3Dwith the one givenstatic doubledot(Vector3D v1, Vector3D v2)Determines the dot product of the two given vectorsPoint3DgetEndPoint()Gets thePoint3Dindicated by applying the vector(u, v, w)components to theorigindoublegetMagnitude()Gets the magnitude of thisVector3D.Point3DgetOrigin()Gets the origin of thisVector3DdoublegetU()Returns the u component of the vector.doublegetV()Returns the v component of the vector.doublegetW()Returns the w component of the vector.static Vector3Dmult(Vector3D v, double d)Multiplies the numerical value of each component of the vector by a given scalar.voidsetOrigin(Point3D origin)Sets the origin of thisVector3DvoidsetU(double u)Sets the u component of the vector.voidsetV(double v)Sets the v component of the vector.voidsetW(double w)Sets the w component of the vector.static Vector3Dsub(Vector3D v1, Vector3D v2)Subtracts the numerical value of each component of the second vector from the values in the first vector.StringtoString2()Builds a descriptive string presenting the u, v, and w components of this vector
-
-
-
Constructor Detail
-
Vector3D
public Vector3D()
Creates a new instance of Vector3D with an origin of (0, 0, 0) and no magnitude (u=0, v=0, w=0)
-
Vector3D
public Vector3D(double u, double v, double w)Creates a new instance of Vector3D with an origin of (0, 0, 0) and the specified u, v, and w magnitudes.- Parameters:
u- Thedoubleu-component of the vector.v- Thedoublev-component of the vector.w- Thedoublew-component of the vector.
-
Vector3D
public Vector3D(Point3D origin, double u, double v, double w)
Creates a new instance of Vector3D with the specified origin and u, v, and w magnitudes.- Parameters:
origin- thePoint3Dorigin of the vector.u- Thedoubleu-component of the vector.v- Thedoublev-component of the vector.w- Thedoublew-component of the vector.
-
-
Method Detail
-
getOrigin
public Point3D getOrigin()
Gets the origin of thisVector3D- Returns:
- the origin
-
setOrigin
public void setOrigin(Point3D origin)
Sets the origin of thisVector3D- Parameters:
origin- the new origin
-
getU
public double getU()
Returns the u component of the vector.- Returns:
doubleThe u component.
-
setU
public void setU(double u)
Sets the u component of the vector.- Parameters:
u-doubleThe u component.
-
getV
public double getV()
Returns the v component of the vector.- Returns:
doubleThe v component.
-
setV
public void setV(double v)
Sets the v component of the vector.- Parameters:
v-doubleThe v component.
-
getW
public double getW()
Returns the w component of the vector.- Returns:
doubleThe w component.
-
setW
public void setW(double w)
Sets the w component of the vector.- Parameters:
w-doubleThe w component.
-
toString2
public String toString2()
Builds a descriptive string presenting the u, v, and w components of this vector- Returns:
- a descriptive
String
-
getMagnitude
public double getMagnitude()
Gets the magnitude of thisVector3D.NOTE: Units are NOT considered, the units of magnitude are the same as those of the vector components.
- Returns:
- the vector magnitude
-
getEndPoint
public Point3D getEndPoint()
Gets thePoint3Dindicated by applying the vector(u, v, w)components to theoriginNOTE: Units are NOT considered. The units of the
originand(u, v, w)components are assumed to be the same.
Therefore conversions (i.e. from DD to Meters) should happen BEFORE calling this method.- Returns:
- the end point.
-
add
public static Vector3D add(Vector3D v1, Vector3D v2)
Adds the numerical value of each component of the first vector with the values in the second vector.- Parameters:
v1- the firstVector3Dv2- the secondVector3D- Returns:
- a
Vector3Drepresenting the addition of the two vectors
-
sub
public static Vector3D sub(Vector3D v1, Vector3D v2)
Subtracts the numerical value of each component of the second vector from the values in the first vector.- Parameters:
v1- the firstVector3Dv2- the secondVector3D- Returns:
- a
Vector3Drepresenting the subtraction of the two vectors
-
mult
public static Vector3D mult(Vector3D v, double d)
Multiplies the numerical value of each component of the vector by a given scalar.- Parameters:
v- theVector3Dd- the value to multiply the vector by- Returns:
- a
Vector3Drepresenting the rescaled vector
-
div
public static Vector3D div(Vector3D v, double d)
Divides the numerical value of each component of the vector by a given scalar.- Parameters:
v- theVector3Dd- the value to divide the vector by- Returns:
- a
Vector3Drepresenting the rescaled vector
-
cross
public static Vector3D cross(Vector3D v1, Vector3D v2)
Determines the cross product of the two given vectors- Parameters:
v1- the firstVector3Dv2- the secondVector3D- Returns:
- a
Vector3Dwhich is perpendicular to the plane containing the given vector's. i.e. Cross product.
-
cross
public Vector3D cross(Vector3D other)
Determines the cross product of thisVector3Dwith the one given- Parameters:
other- anotherVector3D- Returns:
- a
Vector3Drepresenting the cross product of this vector and the one given
-
dot
public static double dot(Vector3D v1, Vector3D v2)
Determines the dot product of the two given vectors- Parameters:
v1- the firstVector3Dv2- the secondVector3D- Returns:
- a
Vector3Dwhich represents the dot product of the given vectors.
-
dot
public double dot(Vector3D other)
Determines the dot product of thisVector3Dwith the one given- Parameters:
other- anotherVector3D- Returns:
- a
Vector3Drepresenting the dot product of this vector and the one given
-
-