ProGAL.geomNd
Class Vector

java.lang.Object
  extended by ProGAL.geomNd.Vector
Direct Known Subclasses:
Vector, Vector

public class Vector
extends java.lang.Object

A vector in metric space represented with double precision.


Constructor Summary
Vector(double[] coords)
          Construct a vector with the specified coordinates
Vector(int dim)
           
Vector(Point p)
          Construct a vector pointing from origo to p.
Vector(Point p1, Point p2)
          Constructs a vector between two points p1 and p2 - added by pawel 12-11-2011
Vector(Vector v)
          Construct a vector that is a clone of v.
 
Method Summary
 Vector add(Vector v)
          Add v to this vector and return the result (without changing this object).
 Vector addThis(Vector v)
          Add v to this vector and return the result (changing this object).
 double angle(Vector v)
          Get the angle between this vector and v.
 Vector clone()
          Create a clone of this vector.
 Vector divide(double s)
          Divide this vector by s and return the result (without changing this object).
 Vector divideThis(double s)
          Divide this vector by s and return the result (changing this object).
 double dot(Vector v)
          Get the dot-product of this vector and v.
 boolean equals(java.lang.Object v)
           
 boolean equals(Vector v)
          Return true if this vector equals v.
 double get(int i)
          Get the i'th coordinate.
static double getAngle(Vector u, Vector v)
          Get the angle between vector u and v.
 double getCoord(int i)
          Get the i'th coordinate.
 int getDimensions()
          Get the dimensionality of this vector
 double getLengthSquared()
          Get the squared length of this vector.
 boolean isZeroVector()
          Return true if the length of this vector is 0.
 double length()
          Get the length of this vector.
 Vector multiply(double s)
          Multiply this vector by s and return the result (without changing this object).
 Vector multiplyThis(double s)
          Multiply this vector by s and return the result (changing this object).
 Vector normalize()
          Normalize this vector and return the result (without changing this object).
 Vector normalizeThis()
          Normalize this vector and return the result (changing this object).
 Matrix outerProduct(Vector v)
           
 Vector scaleToLength(double length)
          Scale this vector to a certain length (returns new object and does not change this object).
 Vector scaleToLengthThis(double length)
          Scale this vector to a certain length (changes this object).
 void set(int i, double v)
          Set the i'th coordinate to v
 void setCoord(int i, double v)
          Set the i'th coordinate to v
 void setCoords(double[] coords)
          Set the coordinates
 Vector subtract(Vector v)
          Subtract v from this vector and return the result (without changing this object).
 Vector subtractThis(Vector v)
          Subtract v from this vector and return the result (changing this object).
 void toConsole()
          Writes this vector to System.out.
 void toConsole(int dec)
          Writes this vector to System.out with dec decimals precision.
 Point toPoint()
          Convert this vector to a point.
 java.lang.String toString()
          Returns a string-representation of this vector formatted with two decimals precision.
 java.lang.String toString(int dec)
          Returns a string-representation of this vector formatted with dec decimals precision.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Vector

public Vector(Point p)
Construct a vector pointing from origo to p.


Vector

public Vector(Point p1,
              Point p2)
Constructs a vector between two points p1 and p2 - added by pawel 12-11-2011


Vector

public Vector(Vector v)
Construct a vector that is a clone of v.


Vector

public Vector(double[] coords)
Construct a vector with the specified coordinates


Vector

public Vector(int dim)
Method Detail

getCoord

public double getCoord(int i)
Get the i'th coordinate.


get

public double get(int i)
Get the i'th coordinate.


getDimensions

public int getDimensions()
Get the dimensionality of this vector


setCoord

public void setCoord(int i,
                     double v)
Set the i'th coordinate to v


setCoords

public void setCoords(double[] coords)
Set the coordinates


set

public void set(int i,
                double v)
Set the i'th coordinate to v


getLengthSquared

public double getLengthSquared()
Get the squared length of this vector.


length

public double length()
Get the length of this vector.


isZeroVector

public boolean isZeroVector()
Return true if the length of this vector is 0.


dot

public double dot(Vector v)
Get the dot-product of this vector and v.


angle

public double angle(Vector v)
Get the angle between this vector and v.


add

public Vector add(Vector v)
Add v to this vector and return the result (without changing this object).


addThis

public Vector addThis(Vector v)
Add v to this vector and return the result (changing this object).


subtract

public Vector subtract(Vector v)
Subtract v from this vector and return the result (without changing this object).


subtractThis

public Vector subtractThis(Vector v)
Subtract v from this vector and return the result (changing this object).


multiply

public Vector multiply(double s)
Multiply this vector by s and return the result (without changing this object).


multiplyThis

public Vector multiplyThis(double s)
Multiply this vector by s and return the result (changing this object).


divide

public Vector divide(double s)
Divide this vector by s and return the result (without changing this object).


divideThis

public Vector divideThis(double s)
Divide this vector by s and return the result (changing this object).


outerProduct

public Matrix outerProduct(Vector v)

normalize

public Vector normalize()
Normalize this vector and return the result (without changing this object).


normalizeThis

public Vector normalizeThis()
Normalize this vector and return the result (changing this object).


scaleToLength

public Vector scaleToLength(double length)
Scale this vector to a certain length (returns new object and does not change this object).


scaleToLengthThis

public Vector scaleToLengthThis(double length)
Scale this vector to a certain length (changes this object).


toPoint

public Point toPoint()
Convert this vector to a point.


toString

public java.lang.String toString()
Returns a string-representation of this vector formatted with two decimals precision.

Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(int dec)
Returns a string-representation of this vector formatted with dec decimals precision.


toConsole

public void toConsole()
Writes this vector to System.out.


toConsole

public void toConsole(int dec)
Writes this vector to System.out with dec decimals precision.


equals

public boolean equals(Vector v)
Return true if this vector equals v.


equals

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

clone

public Vector clone()
Create a clone of this vector.

Overrides:
clone in class java.lang.Object

getAngle

public static double getAngle(Vector u,
                              Vector v)
Get the angle between vector u and v.