com.metsci.glimpse.util.vector
Class Vector2d

java.lang.Object
  extended by com.metsci.glimpse.util.vector.Vector2d
All Implemented Interfaces:
java.io.Serializable

public final class Vector2d
extends java.lang.Object
implements java.io.Serializable

Basic class representing an immutable vector containing 2 doubles. All inputs and outputs are in system units.

Author:
moskowitz
See Also:
Serialized Form

Constructor Summary
Vector2d()
           
Vector2d(double x, double y)
           
 
Method Summary
 double angleWith(Vector2d v)
          Returns the conical (unsigned) angle between this vector and vector v.
 double azimuthAngle()
           
 double cosAngleWith(Vector2d v)
          Returns cosine of the angle between this vector and vector v.
static Vector2d createPolar(double radius, double theta)
          Create Vector2d from polar coordinates.
static Vector2d createPolarTranslated(double radius, double theta, double translateX, double translateY)
          Create Vector2d from polar coordinates with given translation of origin.
 double distance(Vector2d v)
           
 double distanceSquared(Vector2d v)
           
 double dotProduct(Vector2d v)
           
 boolean equals(java.lang.Object o)
           
 java.lang.String format(java.lang.String coordFormat)
          Get formatted String representation.
static Vector2d fromArray(double[] coords)
           
 double getX()
           
 double getY()
           
 int hashCode()
           
 boolean isZero()
           
static Vector2d linearCombination(double[] a, Vector2d[] w)
           
static Vector2d linearCombination(double a1, Vector2d v1, double a2, Vector2d v2)
           
 Vector2d minus(Vector2d v)
           
 double norm()
           
 Vector2d normalized()
          Returns normalized (rescaled to norm = 1) version of this vector.
 Vector2d normalizedLenient()
          Returns normalized (rescaled to norm = 1) version of this vector.
 double normSquared()
           
 Vector2d perpendicularVector()
          Returns a vector perpendicular to this one, with same norm.
 Vector2d plus(Vector2d v)
           
 Vector2d projectionOnto(Vector2d v)
          Returns the projection of this vector onto the vector v.
 Vector2d rotatedAboutOriginBy(double theta)
           
 Vector2d scalarProduct(double alpha)
           
 Vector2d scaledBy(double scaleFactor)
           
 double[] toArray()
           
 java.lang.String toString()
           
 Vector3d toVector3d(double z)
          Concatenate z component to form ThreeVector.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Vector2d

public Vector2d(double x,
                double y)

Vector2d

public Vector2d()
Method Detail

getX

public double getX()

getY

public double getY()

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

format

public java.lang.String format(java.lang.String coordFormat)
Get formatted String representation.

Parameters:
coordFormat - format applied to each coordinate (as in String.format)
Returns:
formatted string with comma separated coordinates

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

plus

public Vector2d plus(Vector2d v)

minus

public Vector2d minus(Vector2d v)

scalarProduct

public Vector2d scalarProduct(double alpha)

scaledBy

public Vector2d scaledBy(double scaleFactor)

dotProduct

public double dotProduct(Vector2d v)

azimuthAngle

public double azimuthAngle()

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.


projectionOnto

public Vector2d projectionOnto(Vector2d v)
Returns the projection of this vector onto the vector v.


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 angle
translateX -
translateY -
Returns:
Vector2d

linearCombination

public static Vector2d linearCombination(double a1,
                                         Vector2d v1,
                                         double a2,
                                         Vector2d v2)

linearCombination

public static Vector2d linearCombination(double[] a,
                                         Vector2d[] w)


Copyright © 2012 Metron, Inc.. All Rights Reserved.