Class ShapeUtilities
java.lang.Object
org.apache.sis.util.Static
org.apache.sis.internal.referencing.j2d.ShapeUtilities
Static methods operating on shapes from the
java.awt.geom
package.- Since:
- 0.5
- Version:
- 1.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final double
Threshold value for determining whether two points are the same, or whether two lines are colinear. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Point2D.Double
circleCentre
(double x1, double y1, double x2, double y2, double x3, double y3) Returns the center of a circle passing by the 3 given points.static Point2D.Double
colinearPoint
(double x1, double y1, double x2, double y2, double x, double y, double distance) Returns a point on the givenline
segment located at the givendistance
from that line.static QuadCurve2D.Double
fitParabol
(double x1, double y1, double px, double py, double x2, double y2, boolean horizontal) Returns a quadratic curve passing by the 3 given points.static Point2D.Double
intersectionPoint
(double ax1, double ay1, double ax2, double ay2, double bx1, double by1, double bx2, double by2) Returns the intersection point between two line segments.static Point2D.Double
nearestColinearPoint
(double x1, double y1, double x2, double y2, double x, double y) Returns the point on the givenline
segment which is closest to the givenpoint
.static Point2D.Double
parabolicControlPoint
(double x1, double y1, double px, double py, double x2, double y2, 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.
-
Field Details
-
EPS
private static final double EPSThreshold value for determining whether two points are the same, or whether two lines are colinear.- See Also:
-
-
Constructor Details
-
ShapeUtilities
private ShapeUtilities()Do not allow instantiation of this class.
-
-
Method Details
-
intersectionPoint
public static Point2D.Double intersectionPoint(double ax1, double ay1, double ax2, double ay2, double bx1, double by1, double bx2, double by2) Returns the intersection point between two line segments. The lines do not continue to infinity; if the intersection does not occur between the ending points P1 and P2 of the two line segments, then this method returnsnull
.- 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. - See Also:
-
nearestColinearPoint
public static Point2D.Double nearestColinearPoint(double x1, double y1, double x2, double y2, double x, double y) Returns the point on the givenline
segment which is closest to the givenpoint
. Letresult
be the returned point. This method guarantees (except for rounding errors) that:result
is a point on theline
segment. It is located between the P1 and P2 ending points of that line segment.- The distance between the
result
point and the givenpoint
is the shortest distance among the set of points meeting the previous condition. This distance can be obtained withpoint.distance(result)
.
- 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
public static Point2D.Double colinearPoint(double x1, double y1, double x2, double y2, double x, double y, double distance) Returns a point on the givenline
segment located at the givendistance
from that line. Letresult
be the returned point. Ifresult
is not null, then this method guarantees (except for rounding error) that:result
is a point on theline
segment. It is located between the P1 and P2 ending points of that line segment.- The distance between the
result
and the givenpoint
is exactly equal todistance
.
null
. If two result points met those conditions, then this method returns the point which is the closest toline.getP1()
.- 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:
-
fitParabol
public static QuadCurve2D.Double fitParabol(double x1, double y1, double px, double py, double x2, double y2, 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 formy=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 thehorizontal
parameter:- A value of
true
means that the x axis must be horizontal. The quadratic curve will then looks like an ordinary parabolic curve as we see in mathematic school book. - A value of
false
means that the x axis must be parallel to the line segment joining theP0
andP2
ending points.
P0.y == P2.y
, then bothhorizontal
values produce the same result.- Parameters:
x1
- x value of the starting point.y1
- y value of the starting point.px
- x value of a passing point.py
- y value of a passing point.x2
- x value of the ending point.y2
- y value of the ending point.horizontal
- iftrue
, the x axis is considered horizontal while computing they=ax²+bx+c
equation terms. Iffalse
, it is considered parallel to the line joining theP0
andP2
points.- Returns:
- a quadratic curve passing by the given points. The curve starts at
P0
and ends atP2
. If two points are too close or if the three points are colinear, then this method returnsnull
.
- A value of
-
parabolicControlPoint
public static Point2D.Double parabolicControlPoint(double x1, double y1, double px, double py, double x2, double y2, 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 formy = ax²+bx+c
, but the x axis is not necessarily horizontal. The x axis orientation in the above equation is determined by thehorizontal
parameter:- A value of
true
means that the x axis must be horizontal. The quadratic curve will then look like an ordinary parabolic curve as we see in mathematic school book. - A value of
false
means that the x axis must be parallel to the line segment joining theP0
andP2
ending points.
P0.y == P2.y
, then bothhorizontal
values produce the same result.- Parameters:
x1
- x value of the starting point.y1
- y value of the starting point.px
- x value of a passing point.py
- y value of a passing point.x2
- x value of the ending point.y2
- y value of the ending point.horizontal
- iftrue
, the x axis is considered horizontal while computing they = ax²+bx+c
equation terms. Iffalse
, it is considered parallel to the line joining theP0
andP2
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 returnsnull
.
- A value of
-
circleCentre
public static Point2D.Double circleCentre(double x1, double y1, double x2, double y2, double x3, double y3) Returns the center of 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:
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:
- the center of a circle passing by the given points.
- See Also:
-
toPrimitive
Attempts to replace an arbitrary shape by one of the standard Java2D constructs. For example if the givenpath
is aPath2D
containing only a single line or a quadratic curve, then this method replaces it by aLine2D
orQuadCurve2D
object respectively.- Parameters:
path
- the shape to replace by a simpler Java2D construct. This is generally an instance ofPath2D
, but not necessarily.- Returns:
- a simpler Java construct, or
path
if no better construct is proposed.
-