Class Shapes


  • public class Shapes
    extends java.lang.Object
    Functions useful for working with shapes in the (X, Y) plane.
    Since:
    18 Sep 2018
    Author:
    Mark Taylor
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean isInside​(double x, double y, double... xys)
      Indicates whether a given test point is inside a polygon defined by specified list of vertices.
      static double polyLine​(double x, double... xys)
      Function of x defined by straight line segments between a specified list of vertices.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • polyLine

        public static double polyLine​(double x,
                                      double... xys)
        Function of x defined by straight line segments between a specified list of vertices. The vertices are specified as a sequence of Xi, Yi pairs, for which the Xi values must be monotonic. The line segment at each end of the specified point sequence is considered to be extended to infinity. If only two points are specified, this is the equation of a straight line between those points. As a special case, if only one point is specified, the line is considered to be a horizontal line (equal to the sole specified Yi coordinate for all x).

        By reversing the Xi and Yi values, this function can equally be used to represent a function X(y) rather than Y(x).

        If the number of coordinates is odd, or the Xi values are not monotonic, behaviour is undefined.

        Parameters:
        x - X value at which function is to be evaluated
        xys - 2N arguments (x1, y1, x2, y2, ..., xN, yN) giving vertices of an N-point line with monotonically increasing or decreasing X values
        Returns:
        Y coordinate of poly-line for specified x
        Examples:
        polyLine(5, 0,0, 2,2) = 5
      • isInside

        public static boolean isInside​(double x,
                                       double y,
                                       double... xys)
        Indicates whether a given test point is inside a polygon defined by specified list of vertices. The vertices are specified as a sequence of Xi, Yi pairs.

        If the number of coordinates is odd, the behaviour is not defined.

        Parameters:
        x - X coordinate of test point
        y - Y coordinate of test point
        xys - 2N arguments (x1, y1, x2, y2, ..., xN, yN) giving vertices of an N-sided polygon
        Returns:
        true iff test point is inside, or on the border of, the polygon
        Examples:
        isInside(0.5,0.5, 0,0, 0,1, 1,1, 1,0) = true, isInside(0,0, array(10,20, 20,20, 20,10)) = false