Class Shapes2D


  • public final class Shapes2D
    extends Static
    Utility methods working on Java2D shapes. The transform(…) methods in this class work in the same way than the methods of the same signature in Envelopes, except that they work on Rectangle2D objects instead than Envelope. In particular, the same treatment for curvatures and poles is applied.
    Since:
    0.8

    Defined in the sis-referencing module

    • Method Detail

      • intersectionPoint

        public static Point2D intersectionPoint​(Line2D a,
                                                Line2D b)
        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 returns null.
        Parameters:
        a - the first line segment.
        b - the second line segment.
        Returns:
        the intersection point, or null if none.
      • nearestColinearPoint

        public static Point2D 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:
        • result is a point on the line segment. It is located between the P1 and P2 ending points of that line segment.
        • The distance between the result point and the given point is the shortest distance among the set of points meeting the previous condition. This distance can be obtained with point​.distance(result).
        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:
        colinear­Point(Line2D, Point2D, double)
      • colinearPoint

        public static Point2D 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:
        • result is a point on the line segment. It is located between the P1 and P2 ending points of that line segment.
        • The distance between the result and the given point is exactly equal to distance.
        If no result point meets those conditions, then this method returns null. If two result points met those conditions, then this method returns the point which is the closest to line​.get­P1().
        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:
        nearest­Colinear­Point(Line2D, Point2D)
      • circle

        public static Ellipse2D circle​(Point2D P1,
                                       Point2D P2,
                                       Point2D P3)
        Returns a circle passing by the 3 given points.
        Parameters:
        P1 - the first point.
        P2 - the second point.
        P3 - the third point.
        Returns:
        a circle passing by the given points.
      • transform

        public static Rectangle2D transform​(CoordinateOperation operation,
                                            Rectangle2D envelope,
                                            Rectangle2D destination)
                                     throws TransformException
        Transforms a rectangular envelope using the given coordinate operation. The transformation is only approximated: the returned envelope may be bigger than the smallest possible bounding box, but should not be smaller in most cases.

        This method can handle the case where the rectangle contains the North or South pole, or when it cross the ±180° longitude.

        Parameters:
        operation - the operation to use. Source and target dimension must be 2.
        envelope - the rectangle to transform (may be null).
        destination - the destination rectangle (may be envelope). If null, a new rectangle will be created and returned.
        Returns:
        destination, or a new rectangle if destination was non-null and envelope was null.
        Throws:
        Transform­Exception - if a transform failed.
        See Also:
        transform(Math­Transform2D, Rectangle2D, Rectangle2D), Envelopes​.transform(Coordinate­Operation, Envelope)