http://www.jpicedt.org

jpicedt.graphic
Class PicVector

java.lang.Object
  extended by java.awt.geom.Point2D
      extended by java.awt.geom.Point2D.Double
          extended by jpicedt.graphic.PicPoint
              extended by jpicedt.graphic.PicVector
All Implemented Interfaces:
Serializable, Cloneable

public class PicVector
extends PicPoint

This class encapsulates a geometrical vector (ie it has absolutely no relation with java.util.Vector !). It is based on PicPoint, from where it conveniently inherits formatting methods, yet add some useful vector-calculus related methods, e.g. dot product, norm, etc... Being a subclass of PicPoint is a major benefit where polymorphism is concerned, since instances of this class can be fed as argument to most getters and setters in jpicedt.graphic.model.Element.

Since:
jPicEdt 1.3.3
Version:
$Id: PicVector.java,v 1.19 2013/03/27 07:00:38 vincentb1 Exp $
Author:
Sylvain Reynal
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class jpicedt.graphic.PicPoint
PicPoint.XComparator, PicPoint.YComparator
 
Nested classes/interfaces inherited from class java.awt.geom.Point2D
Point2D.Double, Point2D.Float
 
Field Summary
static PicVector X_AXIS
          the (1,0) unit vector ; this may be used to compute e.g. angles, projections, ...
static PicVector Y_AXIS
          the (0,1) unit vector ; this may be used to compute e.g. angles, projections, ...
 
Fields inherited from class jpicedt.graphic.PicPoint
X_COMPARATOR, Y_COMPARATOR
 
Fields inherited from class java.awt.geom.Point2D.Double
x, y
 
Constructor Summary
PicVector()
          Construct a null vector.
PicVector(Complex z)
          Construct a vector with same coordinate as real part and imaginary part as a complex number.
PicVector(double[] f)
          Construct a vector from the first two elements of the given array.
PicVector(double x, double y)
          Construct a vector with coordinates (x,y)
PicVector(float[] f)
          Construct a vector from the first two elements of the given array.
PicVector(Line2D line)
          Construct a new PicVector from the two end-points of the given Line2D object.
PicVector(Number x, Number y)
          Construct a vector from the given pair of Number (using their double value).
PicVector(PicVector picVec)
          Clone the given vector.
PicVector(Point2D pt)
          Construct a new PicVector pointing from (0,0) to the given point
PicVector(Point2D pt1, Point2D pt2)
          Construct a new PicVector from the two given points
PicVector(String str)
          Construct a point by parsing a String similar to that given by the toString() method, ie (x,y).
 
Method Summary
 PicVector add(PicPoint other)
          Add the given vector to this vector, which modifies this, and return this for convenience.
 PicVector add(PicPoint other, double a)
          Add the given vector scaled by "a" to this vector, which modifies this, and return this for convenience.
 double angle(PicVector other)
          Return the (CCW oriented) angle, in radians, of the other vector relative to this vector.
 double angleDegrees(PicVector other)
          Return the (CCW oriented) angle between this vector and the given vector, in degrees.
 PicVector cAdd(PicPoint other)
          Make the addition the given vector to this vector, without modifying this, and return the result.
 PicVector cAdd(PicVector other, double a)
          Make the addition the given other vector scaled by a to this vector, without modifying this nor other, and return the result.
 PicVector cIMul()
          Rotate this by PI/2 radian, without modifying this, and return the result of this rotation.
 PicVector cInverse()
           
 PicVector cMIMul()
          Rotate this by -PI/2 radian, without modifying this, and return the result of this rotation.
 PicVector cMul(double s)
          Multiplie le vecteur this par s, sans modifier this.
 PicVector cSub(PicPoint other)
          Make the subtraction the given vector from this vector, without modifying this, and return the result.
 double det(PicVector other)
          Return the determinant of {{x,y},{other.x,other.y}} ; this is aka vector product, where only the z-coordinate gets returned.
 double dot(PicPoint other)
          Return the dot product of this vector with the given vector other
static PicVector getDirector(double startPtX, double startPtY, double endPtX, double endPtY, PicVector dest)
          Return a unitary vector pointing from startPt to endPt ; if dest is non-null, it's filled with the result and returned for convenience ; otherwise, a new PicPoint gets allocated.
static PicVector getDirector(PicPoint startPt, PicPoint endPt)
          Return a unitary vector pointing from startPt to endPt
static PicVector getDirector(PicPoint startPt, PicPoint endPt, PicVector dest)
          Return a unitary vector pointing from startPt to endPt ; if dest is non-null, it's filled with the result and returned for convenience ; otherwise, a new PicPoint gets allocated.
static PicVector getOrthogonal(PicPoint startPt, PicPoint endPt)
          Return a UNITARY vector orthogonal to the vector pointing from startPt to endPt and built by rotating this vector CCW.
 PicVector iMul()
          Rotate this by PI/2 radian, which modifies this, and return this for convenience.
 PicVector inverse()
          Change the sign of each coordinate of this vector
 boolean isColinear(PicVector other)
          Return whether this vector is proportional to the given vector
 boolean isNull()
          Return true if this vector has a null-norm
 boolean isOrthogonal(PicVector other)
          Return whether this vector is orthogonal to the given vector
static void main(String[] args)
          validation tests
 PicVector miMul()
          Rotate this by -PI/2 radian, which modifies this, and return this for convenience.
 double norm()
          Return the norm of this vector
 double norm1()
          Return the abs(x)+abs(y) norm1 for this vector=(x,y)
 double norm2()
          Return the squared of the norm of this vector
 PicVector normalize()
          Normalize this vector so that this becomes a unitary vector Does nothing if this vector is a null-vector.
static PicVector normalize(PicVector src, PicVector dest)
          Return a normalized copy of the given vector.
 PicVector rotate(double angle)
          Rotate this vector by the given (CCW-oriented) angle in radians.
static PicVector rotate(PicVector src, PicVector dest, double angle)
          Return a rotated copy of the given vector.
 PicVector scale(double a)
          Multiply each coordinate of this vector by the given double
 PicVector scale(double ax, double ay)
          Multiply each coordinate of this vector by the given pair of double
static PicVector scale(PicVector src, PicVector dest, double scale)
          Return a scaled copy of the given vector.
 PicVector setCoordinates(Line2D line)
          Set the coordinates of this vector from the given Line2D object
 PicVector setCoordinates(Point2D pt1, Point2D pt2)
          Set the coordinates of this vector from the two given points.
 PicVector subtract(PicPoint other)
          Subtract the given vector from this vector, which modifies this, and return this for convenience.
 
Methods inherited from class jpicedt.graphic.PicPoint
apply, clone, middle, mirror, mirror, norm1Distance, normInfDistance, project, project, rotate, scale, scale, scale, scale, setCoordinates, setCoordinates, shear, symmetry, symmetry, toComplex, toDoubleArray, toFloatArray, toMm, toMm, toString, translate, translate, translate, translate, translate
 
Methods inherited from class java.awt.geom.Point2D.Double
getX, getY, setLocation
 
Methods inherited from class java.awt.geom.Point2D
distance, distance, distance, distanceSq, distanceSq, distanceSq, equals, hashCode, setLocation
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

X_AXIS

public static final PicVector X_AXIS
the (1,0) unit vector ; this may be used to compute e.g. angles, projections, ...


Y_AXIS

public static final PicVector Y_AXIS
the (0,1) unit vector ; this may be used to compute e.g. angles, projections, ...

Constructor Detail

PicVector

public PicVector()
Construct a null vector.


PicVector

public PicVector(PicVector picVec)
Clone the given vector.


PicVector

public PicVector(double x,
                 double y)
Construct a vector with coordinates (x,y)


PicVector

public PicVector(Complex z)
Construct a vector with same coordinate as real part and imaginary part as a complex number.

Since:
jPicEdt 1.6

PicVector

public PicVector(Number x,
                 Number y)
Construct a vector from the given pair of Number (using their double value).


PicVector

public PicVector(float[] f)
Construct a vector from the first two elements of the given array.


PicVector

public PicVector(double[] f)
Construct a vector from the first two elements of the given array.


PicVector

public PicVector(String str)
          throws NumberFormatException
Construct a point by parsing a String similar to that given by the toString() method, ie (x,y).
author: Sylvain Reynal

Throws:
NumberFormatException
Since:
jpicedt 1.3.3

PicVector

public PicVector(Point2D pt1,
                 Point2D pt2)
Construct a new PicVector from the two given points


PicVector

public PicVector(Point2D pt)
Construct a new PicVector pointing from (0,0) to the given point


PicVector

public PicVector(Line2D line)
Construct a new PicVector from the two end-points of the given Line2D object.

Method Detail

setCoordinates

public PicVector setCoordinates(Point2D pt1,
                                Point2D pt2)
Set the coordinates of this vector from the two given points.

Returns:
this for convenience

setCoordinates

public PicVector setCoordinates(Line2D line)
Set the coordinates of this vector from the given Line2D object

Returns:
this for convenience

add

public PicVector add(PicPoint other)
Add the given vector to this vector, which modifies this, and return this for convenience.


add

public PicVector add(PicPoint other,
                     double a)
Add the given vector scaled by "a" to this vector, which modifies this, and return this for convenience.


subtract

public PicVector subtract(PicPoint other)
Subtract the given vector from this vector, which modifies this, and return this for convenience.


cSub

public PicVector cSub(PicPoint other)
Make the subtraction the given vector from this vector, without modifying this, and return the result.

Since:
jPicEdt 1.6

cAdd

public PicVector cAdd(PicPoint other)
Make the addition the given vector to this vector, without modifying this, and return the result.

Since:
jPicEdt 1.6

cAdd

public PicVector cAdd(PicVector other,
                      double a)
Make the addition the given other vector scaled by a to this vector, without modifying this nor other, and return the result.

Since:
jPicEdt 1.6

iMul

public PicVector iMul()
Rotate this by PI/2 radian, which modifies this, and return this for convenience. This is the same thing as multiplying the equivalent complex number by i = exp(i*pi/2).

Since:
jPicEdt 1.6
See Also:
rotate(double angle), cIMul(), cMIMul()

cIMul

public PicVector cIMul()
Rotate this by PI/2 radian, without modifying this, and return the result of this rotation. This is the same thing as multiplying the equivalent complex number by i = exp(i*pi/2).

Since:
jPicEdt 1.6
See Also:
rotate(double angle), iMul(), miMul(), cMIMul()

miMul

public PicVector miMul()
Rotate this by -PI/2 radian, which modifies this, and return this for convenience. This is the same thing as multiplying the equivalent complex number by i = exp(-i*pi/2).

Since:
jPicEdt 1.6
See Also:
rotate(double angle), cIMul()

cMIMul

public PicVector cMIMul()
Rotate this by -PI/2 radian, without modifying this, and return the result of this rotation. This is the same thing as multiplying the equivalent complex number by -i = exp(-i*pi/2).

Since:
jPicEdt 1.6
See Also:
rotate(double angle), iMul()

cMul

public PicVector cMul(double s)
Multiplie le vecteur this par s, sans modifier this. Renvoie le résultat.

Since:
jPicEdt 1.6

norm

public double norm()
Return the norm of this vector


norm2

public double norm2()
Return the squared of the norm of this vector


norm1

public double norm1()
Return the abs(x)+abs(y) norm1 for this vector=(x,y)


normalize

public PicVector normalize()
Normalize this vector so that this becomes a unitary vector Does nothing if this vector is a null-vector.

Returns:
this for convenience

dot

public double dot(PicPoint other)
Return the dot product of this vector with the given vector other


isOrthogonal

public boolean isOrthogonal(PicVector other)
Return whether this vector is orthogonal to the given vector


isColinear

public boolean isColinear(PicVector other)
Return whether this vector is proportional to the given vector


scale

public PicVector scale(double a)
Multiply each coordinate of this vector by the given double

Returns:
this for convenience

scale

public PicVector scale(double ax,
                       double ay)
Multiply each coordinate of this vector by the given pair of double

Parameters:
ax - scale factor for the X-coord
ay - scale factor for the Y-coord
Returns:
this for convenience

inverse

public PicVector inverse()
Change the sign of each coordinate of this vector

Returns:
this for convenience

cInverse

public PicVector cInverse()
Returns:
un clone de ce PicVector dont le signe des coordonnées est changé.

isNull

public boolean isNull()
Return true if this vector has a null-norm


det

public double det(PicVector other)
Return the determinant of {{x,y},{other.x,other.y}} ; this is aka vector product, where only the z-coordinate gets returned.


angle

public double angle(PicVector other)
Return the (CCW oriented) angle, in radians, of the other vector relative to this vector.

Returns:
an angle in the range (-PI, PI]

angleDegrees

public double angleDegrees(PicVector other)
Return the (CCW oriented) angle between this vector and the given vector, in degrees.


rotate

public PicVector rotate(double angle)
Rotate this vector by the given (CCW-oriented) angle in radians.
Current implementation arranges for a very fast code if angle is PI, PI/2 or -PI/2.

Returns:
this for convenience
See Also:
iMul(), cIMul()

main

public static void main(String[] args)
validation tests


normalize

public static PicVector normalize(PicVector src,
                                  PicVector dest)
Return a normalized copy of the given vector. If dest==null, it is allocated and returned for convenience.


rotate

public static PicVector rotate(PicVector src,
                               PicVector dest,
                               double angle)
Return a rotated copy of the given vector. If dest==null, it is allocated and returned for convenience..

See Also:
rotate(double)

scale

public static PicVector scale(PicVector src,
                              PicVector dest,
                              double scale)
Return a scaled copy of the given vector. If dest==null, it is allocated and returned for convenience..

See Also:
rotate(double)

getDirector

public static PicVector getDirector(PicPoint startPt,
                                    PicPoint endPt)
Return a unitary vector pointing from startPt to endPt


getDirector

public static PicVector getDirector(PicPoint startPt,
                                    PicPoint endPt,
                                    PicVector dest)
Return a unitary vector pointing from startPt to endPt ; if dest is non-null, it's filled with the result and returned for convenience ; otherwise, a new PicPoint gets allocated.


getDirector

public static PicVector getDirector(double startPtX,
                                    double startPtY,
                                    double endPtX,
                                    double endPtY,
                                    PicVector dest)
Return a unitary vector pointing from startPt to endPt ; if dest is non-null, it's filled with the result and returned for convenience ; otherwise, a new PicPoint gets allocated.


getOrthogonal

public static PicVector getOrthogonal(PicPoint startPt,
                                      PicPoint endPt)
Return a UNITARY vector orthogonal to the vector pointing from startPt to endPt and built by rotating this vector CCW.


http://www.jpicedt.org

Submit a bug : syd@jpicedt.org