org.geotoolkit.display.shape
Class ShapeUtilities

Object
  extended by Static
      extended by ShapeUtilities

public final class ShapeUtilities
extends Static

Static methods operating on shapes from the java.awt.geom package.

Since:
1.1
Version:
3.20
Author:
Martin Desruisseaux (MPO, IRD, Geomatys)
Module:
referencing/geotk-referencing (download)    View source code for this class

Method Summary
static Point2D.Double circleCentre(double x1, double y1, double x2, double y2, double x3, double y3)
          Same as fitCircle(Point2D, Point2D, Point2D) but using only primitive type arguments.
static Point2D.Double colinearPoint(double x1, double y1, double x2, double y2, double x, double y, double distance)
          Same as colinearPoint(Line2D, Point2D, double) but using only primitive type arguments.
static Point2D.Double colinearPoint(Line2D line, Point2D point, double distance)
          Returns a point on the given line segment located at the given distance from that line.
static Line2D.Double cubicCurveExtremum(double x1, double y1, double dy1, double x2, double y2, double dy2)
          Same as cubicCurveExtremum(Point2D, double, Point2D, double) but using only primitive type arguments.
static Line2D.Double cubicCurveExtremum(Point2D P1, double dy1, Point2D P2, double dy2)
          Finds the extremum of the unique cubic curve which fit the two given points and derivatives.
static Ellipse2D.Double fitCircle(Point2D P1, Point2D P2, Point2D P3)
          Returns a circle passing by the 3 given points.
static QuadCurve2D.Double fitParabol(double x0, double y0, double x1, double y1, double x2, double y2, boolean horizontal)
          Same as fitParabol(Point2D, Point2D, Point2D, boolean) but using only primitive type arguments.
static QuadCurve2D.Double fitParabol(Point2D P0, Point2D P1, Point2D P2, boolean horizontal)
          Returns a quadratic curve passing by the 3 given points.
static double getFlatness(Shape shape)
          Returns a suggested value for the flatness argument in Shape.getPathIterator(AffineTransform,double) for the specified shape.
static Point2D.Double intersectionPoint(double ax1, double ay1, double ax2, double ay2, double bx1, double by1, double bx2, double by2)
          Same as intersectionPoint(Line2D, Line2D) but using only primitive type arguments.
static Point2D.Double intersectionPoint(Line2D a, Line2D b)
          Returns the intersection point between two line segments.
static Point2D.Double nearestColinearPoint(double x1, double y1, double x2, double y2, double x, double y)
          Same as nearestColinearPoint(Line2D, Point2D) but using only primitive type arguments.
static Point2D.Double nearestColinearPoint(Line2D segment, Point2D point)
          Returns the point on the given line segment which is closest to the given point.
static Point2D.Double parabolicControlPoint(double x0, double y0, double x1, double y1, double x2, double y2, boolean horizontal)
          Same as parabolicControlPoint(Point2D, Point2D, Point2D, boolean) but using only primitive type arguments.
static Point2D parabolicControlPoint(double x0, double y0, double x1, double y1, double x2, double y2, boolean horizontal, Point2D dest)
          Deprecated. The dest argument has been removed for consistency with other methods in this class.
static Point2D.Double parabolicControlPoint(Point2D P0, Point2D P1, Point2D P2, boolean horizontal)
          Returns the control point of a quadratic curve passing by the 3 given points.
static Shape toPrimitive(Shape path)
          Attempts to replace an arbitrary shape by one of the standard Java2D constructs.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

intersectionPoint

public static Point2D.Double intersectionPoint(Line2D a,
                                               Line2D b)
Returns the intersection point between two line segments. The lines do not continue to infinity; if the intersection do not occurs between the ending points P1 and P2 of the two line segments, then this method returns null.

Parameters:
a - The first line segment.
b - The second line segment.
Returns:
The intersection point, or null if none.

intersectionPoint

public static Point2D.Double intersectionPoint(double ax1,
                                               double ay1,
                                               double ax2,
                                               double ay2,
                                               double bx1,
                                               double by1,
                                               double bx2,
                                               double by2)
Same as intersectionPoint(Line2D, Line2D) but using only primitive type arguments.

Parameters:
ax1 - x value of the first point on the first line.
ay1 - y value of the first point on the first line.
ax2 - x value of the last point on the first line.
ay2 - y value of the last point on the first line.
bx1 - x value of the first point on the second line.
by1 - y value of the first point on the second line.
bx2 - x value of the last point on the second line.
by2 - y value of the last point on the second line.
Returns:
The intersection point, or null if none.

nearestColinearPoint

public static Point2D.Double nearestColinearPoint(Line2D segment,
                                                  Point2D point)
Returns the point on the given line segment which is closest to the given point. Let result be the returned point. This method guarantees (except for rounding errors) that:

Parameters:
segment - The line on which to search for a point.
point - A point close to the given line.
Returns:
The nearest point on the given line.
See Also:
colinearPoint(Line2D, Point2D, double)

nearestColinearPoint

public static Point2D.Double nearestColinearPoint(double x1,
                                                  double y1,
                                                  double x2,
                                                  double y2,
                                                  double x,
                                                  double y)
Same as nearestColinearPoint(Line2D, Point2D) but using only primitive type arguments.

Parameters:
x1 - x value of the first point on the line.
y1 - y value of the first point on the line.
x2 - x value of the last point on the line.
y2 - y value of the last point on the line.
x - x value of a point close to the given line.
y - y value of a point close to the given line.
Returns:
The nearest point on the given line.
See Also:
colinearPoint(double,double , double,double , double,double , double)

colinearPoint

public static Point2D.Double colinearPoint(Line2D line,
                                           Point2D point,
                                           double distance)
Returns a point on the given line segment located at the given distance from that line. Let result be the returned point. If result is not null, then this method guarantees (except for rounding error) that:

If no result point meets those conditions, then this method returns null. If two result points meet those conditions, then this method returns the point which is the closest to line.getP1().

Parameters:
line - The line on which to search for a point.
point - A point close to the given line.
distance - The distance between the given point and the point to be returned.
Returns:
A point on the given line located at the given distance from the given point.
See Also:
nearestColinearPoint(Line2D, Point2D)

colinearPoint

public static Point2D.Double colinearPoint(double x1,
                                           double y1,
                                           double x2,
                                           double y2,
                                           double x,
                                           double y,
                                           double distance)
Same as colinearPoint(Line2D, Point2D, double) but using only primitive type arguments.

Parameters:
x1 - x value of the first point on the line.
y1 - y value of the first point on the line.
x2 - x value of the last point on the line.
y2 - y value of the last point on the line.
x - x value of a point close to the given line.
y - y value of a point close to the given line.
distance - The distance between the given point and the point to be returned.
Returns:
A point on the given line located at the given distance from the given point.
See Also:
nearestColinearPoint(double,double , double,double , double,double)

fitParabol

public static QuadCurve2D.Double fitParabol(Point2D P0,
                                            Point2D P1,
                                            Point2D P2,
                                            boolean horizontal)
Returns a quadratic curve passing by the 3 given points. There is an infinity of quadratic curves passing by 3 points. We can express the curve we are looking for as a parabolic equation of the form y=ax²+bx+c but where the x axis is not necessarily horizontal. The orientation of the x axis in the above equation is determined by the horizontal parameter:

Note that if P0.y == P2.y, then both horizontal values produce the same result.

Parameters:
P0 - The starting point of the quadratic curve.
P1 - A point by which the quadratic curve must pass by.
P2 - The ending point of the quadratic curve.
horizontal - If true, the x axis is considered horizontal while computing the y=ax²+bx+c equation terms. If false, it is considered parallel to the line joining the P0 and P2 points.
Returns:
A quadratic curve passing by the given points. The curve starts at P0 and ends at P2. If two points are too close or if the three points are colinear, then this method returns null.

fitParabol

public static QuadCurve2D.Double fitParabol(double x0,
                                            double y0,
                                            double x1,
                                            double y1,
                                            double x2,
                                            double y2,
                                            boolean horizontal)
Same as fitParabol(Point2D, Point2D, Point2D, boolean) but using only primitive type arguments.

Parameters:
x0 - x value of the starting point.
y0 - y value of the starting point.
x1 - x value of a passing point.
y1 - y value of a passing point.
x2 - x value of the ending point.
y2 - y value of the ending point.
horizontal - If true, the x axis is considered horizontal while computing the y=ax²+bx+c equation terms. If false, it is considered parallel to the line joining the P0 and P2 points.
Returns:
A quadratic curve passing by the given points. The curve starts at (x0,y0) and ends at (x2,y2). If two points are too close or if the three points are colinear, then this method returns null.

parabolicControlPoint

public static Point2D.Double parabolicControlPoint(Point2D P0,
                                                   Point2D P1,
                                                   Point2D P2,
                                                   boolean horizontal)
Returns the control point of a quadratic curve passing by the 3 given points. There is an infinity of quadratic curves passing by 3 points. We can express the curve we are looking for as a parabolic equation of the form y=ax²+bx+c but where the x axis is not necessarily horizontal. The orientation of the x axis in the above equation is determined by the horizontal parameter:

Note that if P0.y == P2.y, then both horizontal values produce the same result.

Parameters:
P0 - The starting point of the quadratic curve.
P1 - A point by which the quadratic curve must pass by.
P2 - The ending point of the quadratic curve.
horizontal - If true, the x axis is considered horizontal while computing the y=ax²+bx+c equation terms. If false, it is considered parallel to the line joining the P0 and P2 points.
Returns:
The control point of a quadratic curve passing by the given points. The curve starts at P0 and ends at P2. If two points are too close or if the three points are colinear, then this method returns null.
Since:
3.20

parabolicControlPoint

public static Point2D.Double parabolicControlPoint(double x0,
                                                   double y0,
                                                   double x1,
                                                   double y1,
                                                   double x2,
                                                   double y2,
                                                   boolean horizontal)
Same as parabolicControlPoint(Point2D, Point2D, Point2D, boolean) but using only primitive type arguments.

Parameters:
x0 - x value of the starting point.
y0 - y value of the starting point.
x1 - x value of a passing point.
y1 - y value of a passing point.
x2 - x value of the ending point.
y2 - y value of the ending point.
horizontal - If true, the x axis is considered horizontal while computing the y=ax²+bx+c equation terms. If false, it is considered parallel to the line joining the P0 and P2 points.
Returns:
The control point of a quadratic curve passing by the given points. The curve starts at (x0,y0) and ends at (x2,y2). If two points are too close or if the three points are colinear, then this method returns null.

parabolicControlPoint

@Deprecated
public static Point2D parabolicControlPoint(double x0,
                                                       double y0,
                                                       double x1,
                                                       double y1,
                                                       double x2,
                                                       double y2,
                                                       boolean horizontal,
                                                       Point2D dest)
Deprecated. The dest argument has been removed for consistency with other methods in this class.


fitCircle

public static Ellipse2D.Double fitCircle(Point2D P1,
                                         Point2D P2,
                                         Point2D P3)
Returns a circle passing by the 3 given points. The distance between the returned point and any of the given points will be constant; it is the circle radius.

Parameters:
P1 - The first point.
P2 - The second point.
P3 - The third point.
Returns:
A circle passing by the given points.

circleCentre

public static Point2D.Double circleCentre(double x1,
                                          double y1,
                                          double x2,
                                          double y2,
                                          double x3,
                                          double y3)
Same as fitCircle(Point2D, Point2D, Point2D) but using only primitive type arguments.

Parameters:
x1 - x value of the first point.
y1 - y value of the first point.
x2 - x value of the second point.
y2 - y value of the second point.
x3 - x value of the third point.
y3 - y value of the third point.
Returns:
A circle passing by the given points.

cubicCurveExtremum

public static Line2D.Double cubicCurveExtremum(Point2D P1,
                                               double dy1,
                                               Point2D P2,
                                               double dy2)
Finds the extremum of the unique cubic curve which fit the two given points and derivatives. First, this method finds the A, B, C and D coefficients for the following equation:

y = A + Bx + Cx2 + Dx3

Next, this method finds the extremum by finding the (x,y) values that satisfy the following equation (which is the derivative of the above equation):

B + 2Cx + 3Dx2 = 0

A cubic curve can have two extremum, which are returned in a Line2D construct in no particular order. The length of the returned line is the distance separating the two extremum (often a useful information for determining if a quadratic equation would be a sufficient approximation).

The line returned by this method may contains NaN values if the given geometry is actually a line segment (dy1 = dy2 = slope from P1 to P2).

Parameters:
P1 - The first point.
dy1 - The ∂x/∂y value at the first point.
P2 - The second point.
dy2 - The ∂x/∂y value at the second point.
Returns:
The two points located on the extremum of the fitted cubic curve.
Since:
3.20

cubicCurveExtremum

public static Line2D.Double cubicCurveExtremum(double x1,
                                               double y1,
                                               double dy1,
                                               double x2,
                                               double y2,
                                               double dy2)
Same as cubicCurveExtremum(Point2D, double, Point2D, double) but using only primitive type arguments.

Parameters:
x1 - The x ordinate of the first point.
y1 - The y ordinate of the first point.
dy1 - The ∂x/∂y value at the first point.
x2 - The x ordinate of the second point.
y2 - The y ordinate of the second point.
dy2 - The ∂x/∂y value at the second point.
Returns:
The two points located on the extremum of the fitted cubic curve.
Since:
3.20

toPrimitive

public static Shape toPrimitive(Shape path)
Attempts to replace an arbitrary shape by one of the standard Java2D constructs. For example if the given path is a Path2D containing only a single line or a quadratic curve, then this method replaces it by a Line2D or QuadCurve2D object respectively.

Parameters:
path - The shape to replace by a simpler Java2D construct. This is generally an instance of Path2D, but doesn't have to.
Returns:
A simpler Java construct, or path if no better construct is proposed.

getFlatness

public static double getFlatness(Shape shape)
Returns a suggested value for the flatness argument in Shape.getPathIterator(AffineTransform,double) for the specified shape.

Parameters:
shape - The shape for which to compute a flatness factor.
Returns:
The suggested flatness factor.


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.