Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| http://www.jpicedt.org
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## jpicedt.graphic
Class PicVector

    java.lang.Object
      java.awt.geom.Point2D
          java.awt.geom.Point2D.Double
              jpicedt.graphic.PicPoint
                  jpicedt.graphic.PicVector

All Implemented Interfaces:
  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.7.2.1 2007/09/02 11:56:17 reynal Exp $
Author:
  Sylvain Reynal

Nested Class Summary

Nested classes inherited from class jpicedt.graphic.PicPoint
`PicPoint.XComparator, PicPoint.YComparator`

Nested classes 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.
`static PicVector` | `Y_AXIS` the (0,1) unit vector ; this may be used to compute e.g.

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(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(PicVector other)` Add the given vector to this vector, and return this for convenience.
`PicVector` | `add(PicVector other, double a)` Add the given vector scaled by "a" to this vector, and return this for convenience.
`double` | `angle(PicVector other)` Return the (CCW oriented) angle between this vector and the given vector, in radians.
`double` | `angleDegrees(PicVector other)` Return the (CCW oriented) angle between this vector and the given vector, in degrees.
`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(PicVector other)` Return the dot product of this vector with the given vector
`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` | `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
`double` | `norm()` Return the norm of this vector
`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. Current implementation arranges for a very fast code if angle is Math.PI, Math.PI/2 or -Math.PI/2.
`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(PicVector other)` Subtract the given vector from this vector, and return this for convenience.

Methods inherited from class jpicedt.graphic.PicPoint
`apply, clone, middle, project, project, rotate, scale, scale, scale, scale, setCoordinates, setCoordinates, shear, symmetry, symmetry, 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 PicVector X_AXIS

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

### Y_AXIS

    public static 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(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)`.

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

  Add the given vector to this vector, and return this for convenience.

### add

    public PicVector add(PicVector other,
                         double a)

  Add the given vector scaled by "a" to this vector, and return this for convenience.

### subtract

    public PicVector subtract(PicVector other)

  Subtract the given vector from this vector, and return this for convenience.

### norm

    public double norm()

  Return the norm of this vector

### norm2

    public double norm2()

  Return the squared of the norm of this vector

### 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(PicVector other)

  Return the dot product of this vector with the given vector

### 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

### 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 between this vector and the given vector, in radians.

  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 Math.PI, Math.PI/2 or -Math.PI/2.

  Returns:
    this for convenience

### 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.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| http://www.jpicedt.org
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Submit a bug : syd@jpicedt.org