Package 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:
java.io.Serializable,java.lang.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
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jpicedt.graphic.PicPoint
PicPoint.XComparator, PicPoint.YComparator
-
-
Field Summary
Fields Modifier and Type Field Description static PicVectorX_AXISthe (1,0) unit vector ; this may be used to compute e.g.static PicVectorY_AXISthe (0,1) unit vector ; this may be used to compute e.g.-
Fields inherited from class jpicedt.graphic.PicPoint
X_COMPARATOR, Y_COMPARATOR
-
-
Constructor Summary
Constructors Constructor Description 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(java.awt.geom.Line2D line)Construct a new PicVector from the two end-points of the given Line2D object.PicVector(java.awt.geom.Point2D pt)Construct a new PicVector pointing from (0,0) to the given pointPicVector(java.awt.geom.Point2D pt1, java.awt.geom.Point2D pt2)Construct a new PicVector from the two given pointsPicVector(java.lang.Number x, java.lang.Number y)Construct a vector from the given pair of Number (using their double value).PicVector(java.lang.String str)Construct a point by parsing a String similar to that given by thetoString()method, ie(x,y).PicVector(PicVector picVec)Clone the given vector.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description PicVectoradd(PicVector other)Add the given vector to this vector, and return this for convenience.PicVectoradd(PicVector other, double a)Add the given vector scaled by "a" to this vector, and return this for convenience.doubleangle(PicVector other)Return the (CCW oriented) angle between this vector and the given vector, in radians.doubleangleDegrees(PicVector other)Return the (CCW oriented) angle between this vector and the given vector, in degrees.doubledet(PicVector other)Return the determinant of {{x,y},{other.x,other.y}} ; this is aka vector product, where only the z-coordinate gets returned.doubledot(PicVector other)Return the dot product of this vector with the given vectorstatic PicVectorgetDirector(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 PicVectorgetDirector(PicPoint startPt, PicPoint endPt)Return a unitary vector pointing from startPt to endPtstatic PicVectorgetDirector(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 PicVectorgetOrthogonal(PicPoint startPt, PicPoint endPt)Return a UNITARY vector orthogonal to the vector pointing from startPt to endPt and built by rotating this vector CCW.PicVectorinverse()Change the sign of each coordinate of this vectorbooleanisColinear(PicVector other)Return whether this vector is proportional to the given vectorbooleanisNull()Return true if this vector has a null-normbooleanisOrthogonal(PicVector other)Return whether this vector is orthogonal to the given vectorstatic voidmain(java.lang.String[] args)validation testsdoublenorm()Return the norm of this vectordoublenorm2()Return the squared of the norm of this vectorPicVectornormalize()Normalize this vector so that this becomes a unitary vector Does nothing if this vector is a null-vector.static PicVectornormalize(PicVector src, PicVector dest)Return a normalized copy of the given vector.PicVectorrotate(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 PicVectorrotate(PicVector src, PicVector dest, double angle)Return a rotated copy of the given vector.PicVectorscale(double a)Multiply each coordinate of this vector by the given doublePicVectorscale(double ax, double ay)Multiply each coordinate of this vector by the given pair of doublestatic PicVectorscale(PicVector src, PicVector dest, double scale)Return a scaled copy of the given vector.PicVectorsetCoordinates(java.awt.geom.Line2D line)Set the coordinates of this vector from the given Line2D objectPicVectorsetCoordinates(java.awt.geom.Point2D pt1, java.awt.geom.Point2D pt2)Set the coordinates of this vector from the two given points.PicVectorsubtract(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
-
-
-
-
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(java.lang.Number x, java.lang.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(java.lang.String str) throws java.lang.NumberFormatExceptionConstruct a point by parsing a String similar to that given by thetoString()method, ie(x,y).- Throws:
java.lang.NumberFormatException- Since:
- jpicedt 1.3.3
-
PicVector
public PicVector(java.awt.geom.Point2D pt1, java.awt.geom.Point2D pt2)Construct a new PicVector from the two given points
-
PicVector
public PicVector(java.awt.geom.Point2D pt)
Construct a new PicVector pointing from (0,0) to the given point
-
PicVector
public PicVector(java.awt.geom.Line2D line)
Construct a new PicVector from the two end-points of the given Line2D object.
-
-
Method Detail
-
setCoordinates
public PicVector setCoordinates(java.awt.geom.Point2D pt1, java.awt.geom.Point2D pt2)
Set the coordinates of this vector from the two given points.- Returns:
- this for convenience
-
setCoordinates
public PicVector setCoordinates(java.awt.geom.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-coorday- 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(java.lang.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.
-
-