math.geom2d
Class Point2D

Package class diagram package 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:
Serializable, Cloneable, Iterable<Point2D>, CirculinearShape2D, PointShape2D, Shape2D

public class Point2D
extends Point2D.Double
implements PointShape2D, Cloneable, CirculinearShape2D

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.

Important note: in a future release, Point2D will not extend java.awt.geom.Point2D.Double any more.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.geom.Point2D
Point2D.Double, Point2D.Float
 
Field Summary
static Point2D INFINITY_POINT
          Deprecated. it is recommended to use exceptions instead (0.7.0)
 
Fields inherited from class java.awt.geom.Point2D.Double
x, y
 
Fields inherited from interface math.geom2d.Shape2D
ACCURACY
 
Constructor Summary
Point2D()
          Constructs a new Point2D at position (0,0).
Point2D(double x, double y)
          Constructs a new Point2D at the given given position.
Point2D(Point2D point)
          Constructs a new Point2D by copying coordinates of given java point.
Point2D(Point2D point1, double x, double y)
          Deprecated. use Point2D.createPolar() instead (0.7.0)
Point2D(Point2D point1, Point2D point2)
          Deprecated. since 0.7.0
 
Method Summary
static int ccw(Point2D p0, Point2D p1, Point2D p2)
          Computes the orientation of the 3 points: returns +1 is the path P0->P1->P2 turns Counter-Clockwise, -1 if the path turns Clockwise, and 0 if the point P2 is located on the line segment [P0 P1].
static Point2D centroid(Collection<? extends Point2D> points)
          Computes the centroid, or center of mass, of a collection of points.
static Point2D centroid(Point2D[] points)
          Computes the centroid, or center of mass, of an array of points.
static Point2D centroid(Point2D[] points, double[] weights)
          Computes the weighted centroid, or center of mass, of an array of points.
static Point2D centroid(Point2D pt1, Point2D pt2, Point2D pt3)
          Compute the centroid of three points.
 PointSet2D clip(Box2D box)
          Returns a PointSet2D, containing 0 or 1 point, depending on whether the point lies inside the specified box.
 Point2D clone()
          Creates a new Point2D object with same coordinates.
 boolean contains(double x, double y)
          Returns true if the two points are equal.
 boolean contains(Point2D p)
          Returns true if the two points are equal.
static Point2D create(double x, double y)
          Static factory for creating a new point in cartesian coordinates.
static Point2D create(Point2D point)
          Static factory for creating a new point from an existing instance of java point.
static Point2D createPolar(double rho, double theta)
          Creates a new point from polar coordinates rho and theta.
static Point2D createPolar(double x0, double y0, double rho, double theta)
          Creates a new point from polar coordinates rho and theta, from the position (x0,y0).
static Point2D createPolar(Point2D point, double rho, double theta)
          Creates a new point from polar coordinates rho and theta, from the given point.
 void draw(Graphics2D g2)
          Draws the point on the specified Graphics2D, using default radius equal to 1.
 void draw(Graphics2D g2, double r)
          Draws the point on the specified Graphics2D, by filling a disc with a given radius.
 boolean equals(Object obj)
          Two points are considered equal if their Euclidean distance is less than Shape2D.ACCURACY.
 Point2D.Double getAsDouble()
          Converts point to a double version.
 Point2D.Float getAsFloat()
          Converts point to a float version.
 Point getAsInt()
          Converts point to an integer version.
 Box2D getBoundingBox()
          Returns a bounding box with zero width and zero height, whose coordinates limits are point coordinates.
 CirculinearDomain2D getBuffer(double dist)
          Computes the buffer of the shape, formed by the set of points located at a distance from the shape that is lower or equal to d.
 double getDistance(double x, double y)
          Computes the distance between current point and point with coordinate (x,y).
static double getDistance(double x1, double y1, double x2, double y2)
          Computes the Euclidean distance between two points, given by their coordinates.
 double getDistance(Point2D point)
          Computes the distance between this and the point point.
static double getDistance(Point2D p1, Point2D p2)
          Computes the Euclidean distance between two points.
 int getPointNumber()
          Returns the number of points in the set.
 Collection<Point2D> getPoints()
          Returns the points in the shape as a collection.
 boolean isBounded()
          Returns true if the point is bounded.
static boolean isColinear(Point2D p1, Point2D p2, Point2D p3)
          Tests if the three points are colinear.
 boolean isEmpty()
          Returns true if the shape does not contain any point.
 Iterator<Point2D> iterator()
           
static Point2D midPoint(Point2D p1, Point2D p2)
           
 Point2D minus(Point2D p)
           
 Point2D plus(Point2D p)
           
 Point2D rotate(double theta)
          Rotates the point by a given angle around the origin.
 Point2D rotate(Point2D center, double theta)
          Rotates the point by a given angle around an arbitrary center.
 Point2D scale(double k)
          Returns the new point scaled by the same amount in each direction.
 Point2D scale(double kx, double ky)
          Returns the new point scaled by amount given in each direction.
 void setPolarLocation(double rho, double theta)
          Deprecated. use Point2D.createPolar() instead (0.7.0)
 void setPolarLocation(Point2D point, double rho, double theta)
          Deprecated. use Point2D.createPolar() instead (0.7.0)
 String toString()
           
 Point2D transform(AffineTransform2D trans)
          Returns the transformed point.
 Point2D transform(CircleInversion2D inv)
          Transforms the shape by a circle inversion.
 Point2D translate(double tx, double ty)
          Returns the new point translated by amount given in each direction.
 
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, hashCode, setLocation
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

INFINITY_POINT

@Deprecated
public static final Point2D INFINITY_POINT
Deprecated. it is recommended to use exceptions instead (0.7.0)
The point located at the infinity. This point is virtual, it is contained in every infinite shape, such as straight lines, hyperbolas and parabolas.

Constructor Detail

Point2D

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


Point2D

public Point2D(double x,
               double y)
Constructs a new Point2D at the given given position. Please consider using the static factory method instead (0.8.1).


Point2D

public Point2D(Point2D point)
Constructs a new Point2D by copying coordinates of given java point. Please consider using the static factory method instead (0.8.1)


Point2D

@Deprecated
public Point2D(Point2D point1,
                          Point2D point2)
Deprecated. since 0.7.0

Constructs a new Point2D from two java awt.geom Point2D, summing their coordinates.


Point2D

@Deprecated
public Point2D(Point2D point1,
                          double x,
                          double y)
Deprecated. use Point2D.createPolar() instead (0.7.0)

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

Method Detail

create

public static final Point2D create(double x,
                                   double y)
Static factory for creating a new point in cartesian coordinates.

Since:
0.8.1

create

public static final Point2D create(Point2D point)
Static factory for creating a new point from an existing instance of java point.

Since:
0.8.1

createPolar

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


createPolar

public static final Point2D createPolar(Point2D point,
                                        double rho,
                                        double theta)
Creates 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)
Creates a new point from polar coordinates rho and theta, from the position (x0,y0).


getDistance

public static final double getDistance(double x1,
                                       double y1,
                                       double x2,
                                       double y2)
Computes the Euclidean distance between two points, given by their coordinates. Uses robust computation (via Math.hypot() method).

Returns:
the Euclidean distance between p1 and p2.

getDistance

public static final double getDistance(Point2D p1,
                                       Point2D p2)
Computes the Euclidean distance between two points. Uses robust computation (via Math.hypot() method).

Parameters:
p1 - the first point
p2 - the second point
Returns:
the Euclidean distance between p1 and p2.

isColinear

public static final boolean isColinear(Point2D p1,
                                       Point2D p2,
                                       Point2D p3)
Tests if the three points are colinear.

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

ccw

public static final int ccw(Point2D p0,
                            Point2D p1,
                            Point2D p2)
Computes the orientation of the 3 points: returns +1 is the path P0->P1->P2 turns Counter-Clockwise, -1 if the path turns Clockwise, and 0 if the point P2 is located on the line segment [P0 P1]. Algorithm taken from Sedgewick.

Parameters:
p0 - the initial point
p1 - the middle point
p2 - the last point
Returns:
+1, 0 or -1, depending on the relative position of the points

midPoint

public static final Point2D midPoint(Point2D p1,
                                     Point2D p2)

centroid

public static final Point2D centroid(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(Point2D[] points,
                                     double[] weights)
Computes the weighted centroid, or center of mass, of an array of points.

Parameters:
points - an array of points
weights - an array of weights the same size as points
Returns:
the centroid of the points

centroid

public static final Point2D centroid(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(Point2D pt1,
                                     Point2D pt2,
                                     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

plus

public Point2D plus(Point2D p)

minus

public Point2D minus(Point2D p)

translate

public Point2D translate(double tx,
                         double ty)
Returns the new point translated by amount given in each direction.

Parameters:
tx - the translation in x direction
ty - the translation in y direction
Returns:
the translated point

scale

public Point2D scale(double kx,
                     double ky)
Returns the new point scaled by amount given in each direction.

Parameters:
kx - the scale factor in x direction
ky - the scale factor in y direction
Returns:
the scaled point

scale

public Point2D scale(double k)
Returns the new point scaled by the same amount in each direction.

Parameters:
k - the scale factor
Returns:
the scaled point

rotate

public Point2D rotate(double theta)
Rotates the point by a given angle around the origin.

Parameters:
theta - the angle of rotation
Returns:
the rotated point.

rotate

public Point2D rotate(Point2D center,
                      double theta)
Rotates the point by a given angle around an arbitrary center.

Parameters:
center - the center of the rotation
theta - the angle of rotation
Returns:
the rotated point.

getAsInt

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

Returns:
an instance of java.awt.Point

getAsDouble

public Point2D.Double getAsDouble()
Converts point to a double version.


getAsFloat

public Point2D.Float getAsFloat()
Converts point to a float version. Coordinates are rounded to the nearest float.


setPolarLocation

@Deprecated
public void setPolarLocation(double rho,
                                        double theta)
Deprecated. use Point2D.createPolar() instead (0.7.0)

Sets location specified as polar coordinate : distance from origin + angle with horizontal.


setPolarLocation

@Deprecated
public void setPolarLocation(Point2D point,
                                        double rho,
                                        double theta)
Deprecated. use Point2D.createPolar() instead (0.7.0)

Sets location at distance 'rho' from given point, and making an angle 'theta' with horizontal.


getBuffer

public CirculinearDomain2D getBuffer(double dist)
Description copied from interface: CirculinearShape2D
Computes the buffer of the shape, formed by the set of points located at a distance from the shape that is lower or equal to d.

Specified by:
getBuffer in interface CirculinearShape2D
Parameters:
dist - the maximal distance between a point of the buffer and the shape
Returns:
the buffer of the shape

transform

public Point2D transform(CircleInversion2D inv)
Description copied from interface: CirculinearShape2D
Transforms the shape by a circle inversion. The result is still an instance a CirculinearShape2D.

Specified by:
transform in interface CirculinearShape2D
Parameters:
inv - the circle inversion
Returns:
the transformed shape

getDistance

public double getDistance(Point2D point)
Computes the distance between this and the point point.

Specified by:
getDistance in interface Shape2D

getDistance

public double getDistance(double x,
                          double y)
Computes 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

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

isEmpty

public boolean isEmpty()
Description copied from interface: Shape2D
Returns true if the shape does not contain any point. This is the case for example for PointSet2D without any point.

Specified by:
isEmpty in interface Shape2D
Returns:
true if the shape does not contain any point.

contains

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

Specified by:
contains in interface Shape2D

contains

public boolean contains(Point2D p)
Returns true if the two points are equal.

Specified by:
contains in interface Shape2D

clip

public PointSet2D clip(Box2D box)
Returns a PointSet2D, containing 0 or 1 point, depending on whether the point lies inside the specified box.

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

getBoundingBox

public Box2D getBoundingBox()
Returns a bounding box with zero width and zero height, whose coordinates limits are point coordinates.

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

transform

public Point2D transform(AffineTransform2D trans)
Returns the transformed point.

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

draw

public void draw(Graphics2D g2)
Draws the point on the specified Graphics2D, using default radius equal to 1.

Specified by:
draw in interface Shape2D
Parameters:
g2 - the graphics to draw the point

draw

public void draw(Graphics2D g2,
                 double r)
Draws the point on the specified Graphics2D, by filling a disc with a given radius.

Parameters:
g2 - the graphics to draw the point

getPointNumber

public int getPointNumber()
Description copied from interface: PointShape2D
Returns the number of points in the set.

Specified by:
getPointNumber in interface PointShape2D
Returns:
the number of points

getPoints

public Collection<Point2D> getPoints()
Description copied from interface: PointShape2D
Returns the points in the shape as a collection.

Specified by:
getPoints in interface PointShape2D
Returns:
the collection of points

iterator

public Iterator<Point2D> iterator()
Specified by:
iterator in interface Iterable<Point2D>

toString

public String toString()
Overrides:
toString in class Point2D.Double

equals

public boolean equals(Object obj)
Two points are considered equal if their Euclidean distance is less than Shape2D.ACCURACY.

Overrides:
equals in class Point2D

clone

public Point2D clone()
Creates a new Point2D object with same coordinates.

Overrides:
clone in class Point2D


Copyright © 2013 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.