math.geom2d
Class Point2D

java.lang.Object
  extended by java.awt.geom.Point2D
      extended by java.awt.geom.Point2D.Double
          extended by math.geom2d.Point2D
All Implemented Interfaces:
java.awt.Shape, java.io.Serializable, java.lang.Cloneable, Shape2D

public class Point2D
extends java.awt.geom.Point2D.Double
implements Shape2D

A point in the plane defined by its 2 cartesian coordinates x and y. The class provides static methods to compute distance between two points.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.geom.Point2D
java.awt.geom.Point2D.Double, java.awt.geom.Point2D.Float
 
Field Summary
static Point2D INFINITY_POINT
          The point located at the infinity.
 
Fields inherited from class java.awt.geom.Point2D.Double
x, y
 
Fields inherited from interface math.geom2d.Shape2D
ACCURACY, defaultClipWindow, EMPTY_SET
 
Constructor Summary
Point2D()
          construct a new Point2D at position (0,0).
Point2D(double x, double y)
          constructor with given position.
Point2D(java.awt.geom.Point2D point)
          Constructor from a java awt.geom Point2D, included for compatibility.
Point2D(java.awt.geom.Point2D point1, double x, double y)
          Constructor from a java awt.geom Point2D, and two double.
Point2D(java.awt.geom.Point2D point1, java.awt.geom.Point2D point2)
          Constructor from two java awt.geom Point2D, summing their coordinates.
 
Method Summary
static Point2D centroid(java.util.Collection<? extends Point2D> points)
          Computes the centroid, or center of mass, of a collection of points.
static Point2D centroid(java.awt.geom.Point2D[] points)
          Computes the centroid, or center of mass, of an array of points.
static Point2D centroid(java.awt.geom.Point2D pt1, java.awt.geom.Point2D pt2, java.awt.geom.Point2D pt3)
          Compute the centroid of three points.
 Shape2D clip(Box2D box)
          Returns either the point itself, or the shape EMPTY_SET, depending on whether the point lies inside the specified box.
 boolean contains(double x, double y)
          return true if the two points are equal.
 boolean contains(double x, double y, double w, double h)
          Always return false.
 boolean contains(java.awt.geom.Point2D p)
          return true if the two points are equal.
 boolean contains(java.awt.geom.Rectangle2D r)
          Always return false.
static Point2D createPolar(double rho, double theta)
          create a new point from polar coordinates rho and theta.
static Point2D createPolar(double x0, double y0, double rho, double theta)
          create a new point from polar coordinates rho and theta, from the position (x0,y0).
static Point2D createPolar(Point2D point, double rho, double theta)
          create a new point from polar coordinates rho and theta, from the given point.
static double cross(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
          Deprecated. 
static double dot(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
          Deprecated. 
 boolean equals(java.lang.Object obj)
          Two points are consided equal if their euclidean distance is less than Shape2D.ACCURACY.
 java.awt.geom.Point2D.Double getAsDouble()
          Convert point to an double version.
 java.awt.geom.Point2D.Float getAsFloat()
          Convert point to a float version.
 java.awt.Point getAsInt()
          Convert point to an integer version.
 Box2D getBoundingBox()
          Returns the bounding box of the shape.
 java.awt.Rectangle getBounds()
          Return bounding box of the shape.
 java.awt.geom.Rectangle2D getBounds2D()
          Return more precise bounds for the shape.
 Shape2D getClippedShape(Box2D box)
          Returns either the point itself, or the shape EMPTY_SET, depending on whether the point lies inside the specified box.
 double getDistance(double x, double y)
          Compute the distance between current point and point with coordinate (x,y).
static double getDistance(double x1, double y1, double x2, double y2)
           
 double getDistance(java.awt.geom.Point2D point)
          Compute the distance between this and the point point.
static double getDistance(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
           
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform t)
          Return null
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform t, double flatness)
          return a circle enclosing the point, which radius is the specified flatness.
 Shape2D getTransformedShape(AffineTransform2D trans)
           
 boolean intersects(double x, double y, double w, double h)
          Tests if the Point2D intersects the interior of a specified rectangular area.
 boolean intersects(java.awt.geom.Rectangle2D r)
          Tests if the Point2D intersects the interior of a specified rectangle2D.
 boolean isBounded()
          Returns true if the point is bounded.
static boolean isColinear(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, java.awt.geom.Point2D p3)
          test if the three points are colinear.
static Point2D midPoint(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
           
 Point2D minus(java.awt.geom.Point2D p)
           
 Point2D plus(java.awt.geom.Point2D p)
           
 void setPolarLocation(double rho, double theta)
          Set location specified as polar coordinate : distance from origin + angle with horizontal.
 void setPolarLocation(java.awt.geom.Point2D point, double rho, double theta)
          Set location at distance 'rho' from given point, and making an angle 'theta' with horizontal.
 Point2D transform(AffineTransform2D trans)
          transform the shape by an affine transform.
 
Methods inherited from class java.awt.geom.Point2D.Double
getX, getY, setLocation, toString
 
Methods inherited from class java.awt.geom.Point2D
clone, distance, distance, distance, distanceSq, distanceSq, distanceSq, hashCode, setLocation
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

INFINITY_POINT

public static final Point2D INFINITY_POINT
The point located at the infinity. This point is virtual, it is contained in every inifinite shape, such as straight lines, hyperbolas and parabolas.

Constructor Detail

Point2D

public Point2D()
construct a new Point2D at position (0,0).


Point2D

public Point2D(double x,
               double y)
constructor with given position.


Point2D

public Point2D(java.awt.geom.Point2D point)
Constructor from a java awt.geom Point2D, included for compatibility.


Point2D

public Point2D(java.awt.geom.Point2D point1,
               java.awt.geom.Point2D point2)
Constructor from two java awt.geom Point2D, summing their coordinates.


Point2D

public Point2D(java.awt.geom.Point2D point1,
               double x,
               double y)
Constructor from a java awt.geom Point2D, and two double. The (x,y) coordinates are added to the coordinates of given point.

Method Detail

createPolar

public static final Point2D createPolar(double rho,
                                        double theta)
create a new point from polar coordinates rho and theta.


createPolar

public static final Point2D createPolar(Point2D point,
                                        double rho,
                                        double theta)
create a new point from polar coordinates rho and theta, from the given point.


createPolar

public static final Point2D createPolar(double x0,
                                        double y0,
                                        double rho,
                                        double theta)
create a new point from polar coordinates rho and theta, from the position (x0,y0).


dot

@Deprecated
public static final double dot(java.awt.geom.Point2D p1,
                                          java.awt.geom.Point2D p2)
Deprecated. 

get the dot product of the two points, defined by :

x1*y2 + x2*y1

Dot product is zero if the vectors defined by the 2 points are orthogonal. It is positive if vectors are in the same direction, and negative if they are in opposite direction.


cross

@Deprecated
public static final double cross(java.awt.geom.Point2D p1,
                                            java.awt.geom.Point2D p2)
Deprecated. 

get the cross product of the two points, defined by :

x1*y2 - x2*y1

cross product is zero for colinear vector. It is positive if angle between vector 1 and vector 2 is comprised between 0 and PI, and negative otherwise.


getDistance

public static final double getDistance(double x1,
                                       double y1,
                                       double x2,
                                       double y2)

getDistance

public static final double getDistance(java.awt.geom.Point2D p1,
                                       java.awt.geom.Point2D p2)

isColinear

public static final boolean isColinear(java.awt.geom.Point2D p1,
                                       java.awt.geom.Point2D p2,
                                       java.awt.geom.Point2D p3)
test if the three points are colinear.

Returns:
true if three points lie on the same line.

midPoint

public static final Point2D midPoint(java.awt.geom.Point2D p1,
                                     java.awt.geom.Point2D p2)

centroid

public static final Point2D centroid(java.awt.geom.Point2D[] points)
Computes the centroid, or center of mass, of an array of points.

Parameters:
points - an array of points
Returns:
the centroid of the points

centroid

public static final Point2D centroid(java.util.Collection<? extends Point2D> points)
Computes the centroid, or center of mass, of a collection of points.

Parameters:
points - a collection of points
Returns:
the centroid of the points

centroid

public static final Point2D centroid(java.awt.geom.Point2D pt1,
                                     java.awt.geom.Point2D pt2,
                                     java.awt.geom.Point2D pt3)
Compute the centroid of three points.

Parameters:
pt1 - the first point
pt2 - the second point
pt3 - the third point
Returns:
the centroid of the 3 points

getDistance

public double getDistance(java.awt.geom.Point2D point)
Compute the distance between this and the point point.

Specified by:
getDistance in interface Shape2D

getDistance

public double getDistance(double x,
                          double y)
Compute the distance between current point and point with coordinate (x,y). Uses the Math.hypot() function for better robustness than simple square root.

Specified by:
getDistance in interface Shape2D

getAsInt

public java.awt.Point getAsInt()
Convert point to an integer version. Coordinates are rounded to the nearest integer.

Returns:
an instance of java.awt.Point

getAsDouble

public java.awt.geom.Point2D.Double getAsDouble()
Convert point to an double version.


getAsFloat

public java.awt.geom.Point2D.Float getAsFloat()
Convert point to a float version. Coordinates are rounded to the nearest float.


setPolarLocation

public void setPolarLocation(double rho,
                             double theta)
Set location specified as polar coordinate : distance from origin + angle with horizontal.


setPolarLocation

public void setPolarLocation(java.awt.geom.Point2D point,
                             double rho,
                             double theta)
Set location at distance 'rho' from given point, and making an angle 'theta' with horizontal.


isBounded

public boolean isBounded()
Returns true if the point is bounded. A point is unbounded if at least one of its coordinates is infinite or NaN.

Specified by:
isBounded in interface Shape2D
Returns:
true if both coordinates of the point are finite

contains

public boolean contains(double x,
                        double y)
return true if the two points are equal.

Specified by:
contains in interface java.awt.Shape

contains

public boolean contains(java.awt.geom.Point2D p)
return true if the two points are equal.

Specified by:
contains in interface java.awt.Shape

contains

public boolean contains(double x,
                        double y,
                        double w,
                        double h)
Always return false.

Specified by:
contains in interface java.awt.Shape

contains

public boolean contains(java.awt.geom.Rectangle2D r)
Always return false.

Specified by:
contains in interface java.awt.Shape

equals

public boolean equals(java.lang.Object obj)
Two points are consided equal if their euclidean distance is less than Shape2D.ACCURACY.

Overrides:
equals in class java.awt.geom.Point2D

plus

public Point2D plus(java.awt.geom.Point2D p)

minus

public Point2D minus(java.awt.geom.Point2D p)

getBounds

public java.awt.Rectangle getBounds()
Return bounding box of the shape.

Specified by:
getBounds in interface java.awt.Shape

getBounds2D

public java.awt.geom.Rectangle2D getBounds2D()
Return more precise bounds for the shape.

Specified by:
getBounds2D in interface java.awt.Shape

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform t)
Return null

Specified by:
getPathIterator in interface java.awt.Shape

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform t,
                                                  double flatness)
return a circle enclosing the point, which radius is the specified flatness.

Specified by:
getPathIterator in interface java.awt.Shape

intersects

public boolean intersects(double x,
                          double y,
                          double w,
                          double h)
Tests if the Point2D intersects the interior of a specified rectangular area.

Specified by:
intersects in interface java.awt.Shape

intersects

public boolean intersects(java.awt.geom.Rectangle2D r)
Tests if the Point2D intersects the interior of a specified rectangle2D.

Specified by:
intersects in interface java.awt.Shape

getClippedShape

public Shape2D getClippedShape(Box2D box)
Returns either the point itself, or the shape EMPTY_SET, depending on whether the point lies inside the specified box.


clip

public Shape2D clip(Box2D box)
Returns either the point itself, or the shape EMPTY_SET, depending on whether the point lies inside the specified box.

Specified by:
clip in interface Shape2D
Parameters:
box - the clipping box
Returns:
the clipped shape

getBoundingBox

public Box2D getBoundingBox()
Description copied from interface: Shape2D
Returns the bounding box of the shape.

Specified by:
getBoundingBox in interface Shape2D
Returns:
the bounding box of the shape.

getTransformedShape

public Shape2D getTransformedShape(AffineTransform2D trans)

transform

public Point2D transform(AffineTransform2D trans)
Description copied from interface: Shape2D
transform the shape by an affine transform. Subclasses may override the type of returned shape.

Specified by:
transform in interface Shape2D
Parameters:
trans - an affine transform
Returns:
the transformed shape