Package com.metsci.glimpse.util.vector
Class Vector2d
- java.lang.Object
-
- com.metsci.glimpse.util.vector.Vector2d
-
- All Implemented Interfaces:
Serializable
public final class Vector2d extends Object implements Serializable
Basic class representing an immutable vector containing 2 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(Vector2d v)Returns the conical (unsigned) angle between this vector and vector v.doubleazimuthAngle()doubleazimuthAngleFast()doublecosAngleWith(Vector2d v)Returns cosine of the angle between this vector and vector v.static Vector2dcreatePolar(double radius, double theta)Create Vector2d from polar coordinates.static Vector2dcreatePolarTranslated(double radius, double theta, double translateX, double translateY)Create Vector2d from polar coordinates with given translation of origin.doublecrossProduct(Vector2d v)doubledistance(Vector2d v)doubledistanceSquared(Vector2d v)doubledotProduct(Vector2d v)booleanequals(Object o)Stringformat(String coordFormat)Get formatted String representation.static Vector2dfromArray(double[] coords)doublegetX()doublegetY()inthashCode()booleanisToRightOf(Vector2d v)booleanisZero()static Vector2dlinearCombination(double[] a, Vector2d[] w)static Vector2dlinearCombination(double a1, Vector2d v1, double a2, Vector2d v2)Vector2dminus(Vector2d v)doublenorm()Vector2dnormalized()Returns normalized (rescaled to norm = 1) version of this vector.Vector2dnormalizedLenient()Returns normalized (rescaled to norm = 1) version of this vector.doublenormSquared()Vector2dperpendicularVector()Returns a vector perpendicular to this one, with same norm.Vector2dplus(Vector2d v)Vector2dprojectionOnto(Vector2d v, boolean isLenient)Returns the projection of this vector onto the vector v.Vector2dprojectOnto(Vector2d v)Returns the projection of this vector onto the vector v.Vector2drotatedAboutOriginBy(double theta)Vector2dscalarProduct(double alpha)Deprecated.usescaledBy(double)Vector2dscaledBy(double scaleFactor)double[]toArray()StringtoString()Vector3dtoVector3d(double z)Concatenate z component to form ThreeVector.
-
-
-
Method Detail
-
getX
public double getX()
-
getY
public double getY()
-
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
-
scalarProduct
@Deprecated public Vector2d scalarProduct(double alpha)
Deprecated.usescaledBy(double)
-
scaledBy
public Vector2d scaledBy(double scaleFactor)
-
dotProduct
public double dotProduct(Vector2d v)
-
crossProduct
public double crossProduct(Vector2d v)
-
isToRightOf
public boolean isToRightOf(Vector2d v)
-
azimuthAngle
public double azimuthAngle()
-
azimuthAngleFast
public double azimuthAngleFast()
-
normSquared
public double normSquared()
-
norm
public double norm()
-
isZero
public boolean isZero()
-
normalized
public Vector2d 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 Vector2d normalizedLenient()
Returns normalized (rescaled to norm = 1) version of this vector.Note: "Lenient" version: If zero vector, returned vector will be (1, 0).
- Returns:
- normalized version of this vector
-
distanceSquared
public double distanceSquared(Vector2d v)
-
distance
public double distance(Vector2d v)
-
cosAngleWith
public double cosAngleWith(Vector2d v)
Returns cosine of the angle between this vector and vector v.
-
angleWith
public double angleWith(Vector2d v)
Returns the conical (unsigned) angle between this vector and vector v.
-
projectOnto
public Vector2d projectOnto(Vector2d v)
Returns the projection of this vector onto the vector v.- See Also:
for lenient handling of v
-
projectionOnto
public Vector2d projectionOnto(Vector2d v, boolean isLenient)
Returns the projection of this vector onto the vector v. Lenient version treats zero vector for v as (1,0) in order to avoid returning vector containing NaN values.
-
rotatedAboutOriginBy
public Vector2d rotatedAboutOriginBy(double theta)
- Parameters:
theta- rotation angle- Returns:
- rotated copy
-
perpendicularVector
public Vector2d perpendicularVector()
Returns a vector perpendicular to this one, with same norm.
-
toVector3d
public Vector3d toVector3d(double z)
Concatenate z component to form ThreeVector.- Parameters:
z-- Returns:
- ThreeVector
-
toArray
public double[] toArray()
-
fromArray
public static Vector2d fromArray(double[] coords)
-
createPolar
public static Vector2d createPolar(double radius, double theta)
Create Vector2d from polar coordinates.- Parameters:
radius- distance from center (0,0)theta- azimuth angle- Returns:
- Vector2d
-
createPolarTranslated
public static Vector2d createPolarTranslated(double radius, double theta, double translateX, double translateY)
Create Vector2d from polar coordinates with given translation of origin.- Parameters:
radius- distance from center (translateX, translateY)theta- azimuth angletranslateX-translateY-- Returns:
- Vector2d
-
linearCombination
public static Vector2d linearCombination(double a1, Vector2d v1, double a2, Vector2d v2)
-
-