com.metsci.glimpse.util.vector
Class Vector3d

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

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

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

Author:
moskowitz
See Also:
Serialized Form

Constructor Summary
Vector3d()
          Default constructor.
Vector3d(double x, double y, double z)
          Standard constructor.
 
Method Summary
 double angleWith(Vector3d v)
          Returns the conical (unsigned) angle between this vector and vector v.
 double cosAngleWith(Vector3d v)
          Returns cosine of the angle between this vector and vector v.
static Vector3d createCylindrical(double radius, double theta, double z)
          Create Vector3d from cylindrical coordinates.
 Vector3d crossProduct(Vector3d v)
           
 double distance(Vector3d v)
           
 double distanceOnXYPlane(Vector2d v)
           
 double distanceOnXYPlane(Vector3d v)
           
 double distanceOnXYPlaneSquared(Vector2d v)
           
 double distanceOnXYPlaneSquared(Vector3d v)
           
 double distanceSquared(Vector3d v)
           
 double dotProduct(Vector3d v)
           
 double elevationAngle()
          Returns the conical angle between this vector and the xy-plane.
 boolean equals(java.lang.Object o)
           
 java.lang.String format(java.lang.String coordFormat)
          Get formatted String representation.
static Vector3d fromArray(double[] coords)
           
 double getX()
           
 Vector2d getXY()
           
 double getY()
           
 double getZ()
           
 int hashCode()
           
 double horizontalAzimuthAngle()
          Returns the azimuth angle of the projection of this vector on the xy-plane.
 double horizontalAzimuthAngleFast()
          Returns the azimuth angle of the projection of this vector on the xy-plane.
static Vector3d interpolate(double t, Vector3d v0, Vector3d v1)
          Linear interpolation between vectors v0 and v1.
 boolean isValid()
          False if any of the coordinates is NaN or Infinite.
 boolean isZero()
           
static Vector3d linearCombination(double[] a, Vector3d[] w)
           
static Vector3d linearCombination(double a1, Vector3d v1, double a2, Vector3d v2)
           
static Vector3d linearCombination(double a1, Vector3d v1, double a2, Vector3d v2, double a3, Vector3d v3)
           
 Vector3d minus(Vector3d v)
           
 double norm()
           
 Vector3d normalized()
          Returns normalized (rescaled to norm = 1) version of this vector.
 Vector3d normalizedLenient()
          Returns normalized (rescaled to norm = 1) version of this vector.
 double normSquared()
           
 Vector3d[] orthonormalVectors()
          Returns unit vectors w0 and w1 which are orthogonal to this vector and each other.
 double phiAngle()
          Returns the conical angle between this vector and the positive z axis.
 Vector3d plus(Vector3d v)
           
 Vector3d projectionOnto(Vector3d v)
          Returns the projection of this vector onto the vector v.
 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.
 Vector3d rotatedAboutXAxisBy(double theta)
           
 Vector3d rotatedAboutYAxisBy(double theta)
           
 Vector3d rotatedAboutZAxisBy(double theta)
           
 Vector3d scalarProduct(double alpha)
           
 Vector3d scaledBy(double scaleFactor)
           
 double[] toArray()
           
 java.lang.String toString()
           
 Vector3d withZ(double z)
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Vector3d

public Vector3d(double x,
                double y,
                double z)
Standard constructor.

Parameters:
x -
y -
z -

Vector3d

public Vector3d()
Default constructor. Creates zero vector.

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()

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

toArray

public double[] toArray()

fromArray

public static Vector3d fromArray(double[] coords)

toString

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

plus

public Vector3d plus(Vector3d v)

minus

public Vector3d minus(Vector3d v)

scalarProduct

public Vector3d scalarProduct(double alpha)

scaledBy

public Vector3d scaledBy(double scaleFactor)

dotProduct

public double dotProduct(Vector3d v)

crossProduct

public Vector3d crossProduct(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).


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.


projectionOnto

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


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 plane
normal - 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)

linearCombination

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

interpolate

public static Vector3d interpolate(double t,
                                   Vector3d v0,
                                   Vector3d v1)
Linear interpolation between vectors v0 and v1. t = 0 returns v0 and t = 1 returns v1.



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