Package com.metsci.glimpse.util.vector
Class Vector3d
- java.lang.Object
-
- com.metsci.glimpse.util.vector.Vector3d
-
- All Implemented Interfaces:
Serializable
public final class Vector3d extends Object implements Serializable
Basic class representing an immutable vector containing 3 doubles. All inputs and outputs are in system units.- Author:
- moskowitz
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description doubleangleWith(Vector3d v)Returns the conical (unsigned) angle between this vector and vector v.doublecosAngleWith(Vector3d v)Returns cosine of the angle between this vector and vector v.static Vector3dcreateCylindrical(double radius, double theta, double z)Create Vector3d from cylindrical coordinates.Vector3dcrossProduct(Vector3d v)doubledistance(Vector3d v)doubledistanceOnXYPlane(Vector2d v)doubledistanceOnXYPlane(Vector3d v)doubledistanceOnXYPlaneSquared(Vector2d v)doubledistanceOnXYPlaneSquared(Vector3d v)doubledistanceSquared(Vector3d v)doubledotProduct(Vector3d v)doubleelevationAngle()Returns the conical angle between this vector and the xy-plane.booleanequals(Object o)Stringformat(String coordFormat)Get formatted String representation.static Vector3dfromArray(double[] coords)doublegetX()Vector2dgetXY()doublegetY()doublegetZ()inthashCode()doublehorizontalAzimuthAngle()Returns the azimuth angle of the projection of this vector on the xy-plane.doublehorizontalAzimuthAngleFast()Returns the azimuth angle of the projection of this vector on the xy-plane.static Vector3dinterpolate(double t, Vector3d v0, Vector3d v1)Linear interpolation between vectors v0 and v1.booleanisValid()False if any of the coordinates is NaN or Infinite.booleanisZero()static Vector3dlinearCombination(double[] a, Vector3d[] w)static Vector3dlinearCombination(double a1, Vector3d v1, double a2, Vector3d v2)static Vector3dlinearCombination(double a1, Vector3d v1, double a2, Vector3d v2, double a3, Vector3d v3)Vector3dminus(Vector3d v)doublenorm()Vector3dnormalized()Returns normalized (rescaled to norm = 1) version of this vector.Vector3dnormalizedLenient()Returns normalized (rescaled to norm = 1) version of this vector.doublenormSquared()Vector3d[]orthonormalVectors()Returns unit vectors w0 and w1 which are orthogonal to this vector and each other.doublephiAngle()Returns the conical angle between this vector and the positive z axis.Vector3dplus(Vector3d v)Vector3dprojectionOnto(Vector3d v, boolean isLenient)Returns the projection of this vector onto the vector v.Vector3dprojectOnto(Vector3d v)Returns the projection of this vector onto the vector v.Vector3dreflectionThroughPlaneAt(Vector3d x0, Vector3d normal)Returns reflection of this vector through a plane specified by a point on the plane and a vector normal to the plane.Vector3drotated(double theta, Vector3d axis)Vector3drotatedAboutXAxisBy(double theta)Vector3drotatedAboutYAxisBy(double theta)Vector3drotatedAboutZAxisBy(double theta)Vector3dscalarProduct(double alpha)Deprecated.usescaledBy(double)Vector3dscaledBy(double scaleFactor)double[]toArray()StringtoString()Vector3dwithZ(double z)
-
-
-
Method Detail
-
createCylindrical
public static Vector3d createCylindrical(double radius, double theta, double z)
Create Vector3d from cylindrical coordinates.Note: Negative radius is allowed. This reverses the vector direction in x and y.
- Parameters:
radius- distance from z-axis (XY plane projection radius)theta- horizontal azimuth angle (XY plane projection theta)z- z-coordinate- Returns:
- Vector3d
-
getX
public double getX()
-
getY
public double getY()
-
getZ
public double getZ()
-
getXY
public Vector2d getXY()
-
format
public String format(String coordFormat)
Get formatted String representation.- Parameters:
coordFormat- format applied to each coordinate (as in String.format)- Returns:
- formatted string with comma separated coordinates
-
toArray
public double[] toArray()
-
fromArray
public static Vector3d fromArray(double[] coords)
-
scalarProduct
@Deprecated public Vector3d scalarProduct(double alpha)
Deprecated.usescaledBy(double)
-
scaledBy
public Vector3d scaledBy(double scaleFactor)
-
dotProduct
public double dotProduct(Vector3d v)
-
normSquared
public double normSquared()
-
distanceSquared
public double distanceSquared(Vector3d v)
-
distance
public double distance(Vector3d v)
-
norm
public double norm()
-
isZero
public boolean isZero()
-
distanceOnXYPlaneSquared
public double distanceOnXYPlaneSquared(Vector2d v)
-
distanceOnXYPlane
public double distanceOnXYPlane(Vector2d v)
-
distanceOnXYPlaneSquared
public double distanceOnXYPlaneSquared(Vector3d v)
-
distanceOnXYPlane
public double distanceOnXYPlane(Vector3d v)
-
isValid
public boolean isValid()
False if any of the coordinates is NaN or Infinite.
-
withZ
public Vector3d withZ(double z)
-
normalized
public Vector3d normalized()
Returns normalized (rescaled to norm = 1) version of this vector.Note: "Strict" version: if zero vector, returned vector will contain all NaN values and a warning will be logged.
- Returns:
- normalized version of this vector
-
normalizedLenient
public Vector3d normalizedLenient()
Returns normalized (rescaled to norm = 1) version of this vector.Note: "Lenient" version: If zero vector, returned vector will be (1, 0, 0).
- Returns:
- normalized version of this vector
-
horizontalAzimuthAngle
public double horizontalAzimuthAngle()
Returns the azimuth angle of the projection of this vector on the xy-plane.
-
horizontalAzimuthAngleFast
public double horizontalAzimuthAngleFast()
Returns the azimuth angle of the projection of this vector on the xy-plane.Note: This version uses a faster, less accurate, calculation.
-
phiAngle
public double phiAngle()
Returns the conical angle between this vector and the positive z axis. Zero on the +z axis. Positive elsewhere with max value of PI radians or 180 degrees (in system units).
-
elevationAngle
public double elevationAngle()
Returns the conical angle between this vector and the xy-plane. Zero on the xy-plane. Positive above the plane to a max of PI/2 or 90 degrees (in system units), negative below the plane to a min of -PI/2 or -90 degrees (in system units).
-
rotated
public Vector3d rotated(double theta, Vector3d axis)
- Parameters:
theta- rotation angle around the specified axis.axis- the axis about which to rotate.- Returns:
- rotated copy
-
rotatedAboutXAxisBy
public Vector3d rotatedAboutXAxisBy(double theta)
- Parameters:
theta- rotation angle around the x-axis.- Returns:
- rotated copy
-
rotatedAboutYAxisBy
public Vector3d rotatedAboutYAxisBy(double theta)
- Parameters:
theta- rotation angle around the y-axis.- Returns:
- rotated copy
-
rotatedAboutZAxisBy
public Vector3d rotatedAboutZAxisBy(double theta)
- Parameters:
theta- rotation angle around the z-axis.- Returns:
- rotated copy
-
cosAngleWith
public double cosAngleWith(Vector3d v)
Returns cosine of the angle between this vector and vector v.
-
angleWith
public double angleWith(Vector3d v)
Returns the conical (unsigned) angle between this vector and vector v.
-
projectOnto
public Vector3d projectOnto(Vector3d v)
Returns the projection of this vector onto the vector v.- See Also:
for lenient handling of v
-
projectionOnto
public Vector3d projectionOnto(Vector3d v, boolean isLenient)
Returns the projection of this vector onto the vector v. Lenient version treats zero vector for v as (1,0,0) in order to avoid returning vector containing NaN values.
-
reflectionThroughPlaneAt
public Vector3d reflectionThroughPlaneAt(Vector3d x0, Vector3d normal)
Returns reflection of this vector through a plane specified by a point on the plane and a vector normal to the plane.- Parameters:
x0- point on the planenormal- normal to the plane- Returns:
- reflected position
-
orthonormalVectors
public Vector3d[] orthonormalVectors()
Returns unit vectors w0 and w1 which are orthogonal to this vector and each other.
-
linearCombination
public static Vector3d linearCombination(double a1, Vector3d v1, double a2, Vector3d v2)
-
linearCombination
public static Vector3d linearCombination(double a1, Vector3d v1, double a2, Vector3d v2, double a3, Vector3d v3)
-
-