Class ConvexPolygon2D

java.lang.Object
org.episteme.core.mathematics.geometry.boundaries.ConvexPolygon2D
All Implemented Interfaces:
Serializable, Boundary<Point2D>, Boundary2D

public class ConvexPolygon2D extends Object implements Boundary2D
A convex polygon in 2D space.

This is the simplest form of 2D boundary - a convex polygon defined by its vertices in counter-clockwise order.

Since:
1.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
See Also:
  • Constructor Details

    • ConvexPolygon2D

      public ConvexPolygon2D(List<Point2D> vertices)
      Creates a convex polygon from vertices. Vertices should be in counter-clockwise order.
      Parameters:
      vertices - the polygon vertices
    • ConvexPolygon2D

      public ConvexPolygon2D(Point2D... vertices)
      Creates a convex polygon from vertex array.
      Parameters:
      vertices - the vertices
  • Method Details

    • fromPoints

      public static ConvexPolygon2D fromPoints(List<Point2D> points)
      Creates a convex polygon from a set of points by computing their convex hull.
      Parameters:
      points - the input points
      Returns:
      the convex polygon
    • regular

      public static ConvexPolygon2D regular(Point2D center, Real radius, int sides)
      Creates a regular polygon.
      Parameters:
      center - the center point
      radius - distance from center to vertices
      sides - number of sides (minimum 3)
      Returns:
      regular polygon
    • triangle

      public static ConvexPolygon2D triangle(Point2D a, Point2D b, Point2D c)
      Creates a triangle.
    • rectangle

      public static ConvexPolygon2D rectangle(Point2D min, Point2D max)
      Creates a rectangle.
    • getVertices

      public List<Point2D> getVertices()
      Description copied from interface: Boundary2D
      Returns the vertices of this boundary in order.
      Specified by:
      getVertices in interface Boundary2D
      Returns:
      list of vertices
    • getVertexCount

      public int getVertexCount()
      Description copied from interface: Boundary2D
      Returns the number of vertices.
      Specified by:
      getVertexCount in interface Boundary2D
      Returns:
      vertex count
    • getVertex

      public Point2D getVertex(int index)
      Description copied from interface: Boundary2D
      Returns a specific vertex.
      Specified by:
      getVertex in interface Boundary2D
      Parameters:
      index - the vertex index
      Returns:
      the vertex
    • getArea

      public Real getArea()
      Description copied from interface: Boundary2D
      Returns the area of this 2D boundary.
      Specified by:
      getArea in interface Boundary2D
      Returns:
      the area
    • getPerimeter

      public Real getPerimeter()
      Description copied from interface: Boundary2D
      Returns the perimeter of this 2D boundary.
      Specified by:
      getPerimeter in interface Boundary2D
      Returns:
      the perimeter
    • isConvex

      public boolean isConvex()
      Description copied from interface: Boundary2D
      Checks if this boundary is convex.
      Specified by:
      isConvex in interface Boundary2D
      Returns:
      true if convex
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Boundary
      Checks if this boundary is empty.
      Specified by:
      isEmpty in interface Boundary<Point2D>
      Returns:
      true if the boundary has no extent
    • getCentroid

      public Point2D getCentroid()
      Description copied from interface: Boundary
      Returns the centroid of this boundary.
      Specified by:
      getCentroid in interface Boundary<Point2D>
      Returns:
      the geometric center
    • getBoundingBox

      public BoundingBox<Point2D> getBoundingBox()
      Description copied from interface: Boundary
      Returns the bounding box of this boundary.
      Specified by:
      getBoundingBox in interface Boundary<Point2D>
      Returns:
      an axis-aligned bounding box
    • contains

      public boolean contains(Point2D point)
      Description copied from interface: Boundary
      Checks if a point is contained within this boundary.
      Specified by:
      contains in interface Boundary<Point2D>
      Parameters:
      point - the point to test
      Returns:
      true if point is inside or on the boundary
    • intersects

      public boolean intersects(Boundary<Point2D> other)
      Description copied from interface: Boundary
      Checks if this boundary intersects with another.
      Specified by:
      intersects in interface Boundary<Point2D>
      Parameters:
      other - the other boundary
      Returns:
      true if boundaries intersect
    • union

      public Boundary<Point2D> union(Boundary<Point2D> other)
      Description copied from interface: Boundary
      Computes the union of this boundary with another.
      Specified by:
      union in interface Boundary<Point2D>
      Parameters:
      other - the other boundary
      Returns:
      the union boundary
    • intersection

      public Boundary<Point2D> intersection(Boundary<Point2D> other)
      Description copied from interface: Boundary
      Computes the intersection of this boundary with another.
      Specified by:
      intersection in interface Boundary<Point2D>
      Parameters:
      other - the other boundary
      Returns:
      the intersection boundary
    • convexHull

      public Boundary<Point2D> convexHull()
      Description copied from interface: Boundary
      Computes the convex hull of this boundary.
      Specified by:
      convexHull in interface Boundary<Point2D>
      Returns:
      the convex hull
    • translate

      public Boundary<Point2D> translate(Point2D offset)
      Description copied from interface: Boundary
      Creates a copy of this boundary translated by a vector.
      Specified by:
      translate in interface Boundary<Point2D>
      Parameters:
      offset - the translation vector (as point)
      Returns:
      translated boundary
    • scale

      public Boundary<Point2D> scale(Real factor)
      Description copied from interface: Boundary
      Creates a scaled copy of this boundary.
      Specified by:
      scale in interface Boundary<Point2D>
      Parameters:
      factor - the scaling factor
      Returns:
      scaled boundary
    • rotate

      public Boundary2D rotate(Real angleRadians)
      Description copied from interface: Boundary2D
      Rotates the boundary around the centroid.
      Specified by:
      rotate in interface Boundary2D
      Parameters:
      angleRadians - rotation angle in radians
      Returns:
      rotated boundary
    • rotateAround

      public Boundary2D rotateAround(Real angleRadians, Point2D pivot)
      Description copied from interface: Boundary2D
      Rotates around a specific pivot point.
      Specified by:
      rotateAround in interface Boundary2D
      Parameters:
      angleRadians - rotation angle
      pivot - the pivot point
      Returns:
      rotated boundary
    • extrude

      public Boundary3D extrude(Real height)
      Description copied from interface: Boundary2D
      Creates an extruded 3D boundary from this 2D boundary.
      Specified by:
      extrude in interface Boundary2D
      Parameters:
      height - the extrusion height
      Returns:
      a 3D boundary
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object