Class Polygon

java.lang.Object
eu.svjatoslav.sixth.e3d.geometry.Polygon

public class Polygon extends Object
Utility class for polygon operations, primarily point-in-polygon testing.

Provides static methods for geometric computations on triangles and other polygons.

See Also:
  • Constructor Details

    • Polygon

      public Polygon()
      Creates a new Polygon utility instance.
  • Method Details

    • pointWithinPolygon

      public static boolean pointWithinPolygon(Point2D point, Point2D p1, Point2D p2, Point2D p3)
      Tests whether a point lies inside a triangle using the ray-casting algorithm.

      Casts a horizontal ray from the test point and counts intersections with the triangle edges. If the number of intersections is odd, the point is inside.

      Parameters:
      point - the point to test
      p1 - the first vertex of the triangle
      p2 - the second vertex of the triangle
      p3 - the third vertex of the triangle
      Returns:
      true if the point is inside the triangle