Package geometries

Class Polygon

java.lang.Object
geometries.Geometry
geometries.Polygon
All Implemented Interfaces:
Intersectible
Direct Known Subclasses:
Triangle

public class Polygon
extends Geometry
This class represents a polygon in three dimensional space. A polygon is a plane figure that is described by a finite number of straight line segments connected to form a polygonal circuit.
  • Field Summary

    Fields inherited from class geometries.Geometry

    material
  • Constructor Summary

    Constructors
    Constructor Description
    Polygon​(Material material, Point... vertices)
    This constructor accepts a list of the vertices of the polygon.
  • Method Summary

    Modifier and Type Method Description
    geometries.Boundary boundary()
    Get the Boundary of this intersectible.
    java.util.List<Intersection> intersect​(LineSegment line)
    Calculates all the intersections between a given LineSegment and this object.
    NormalizedVector normal​(Point p)
    Calculates the normal to the Polygon.

    Methods inherited from class geometries.Geometry

    intersection

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Polygon

      public Polygon​(Material material, Point... vertices)
      This constructor accepts a list of the vertices of the polygon.
      Parameters:
      material - The Material the polygon is made from.
      vertices - A list of the vertices of the polygon, in order.
      Throws:
      java.lang.IllegalArgumentException - if there are less than three significant vertices, any of the vertices are not on the same plane as the rest, the vertices are out of order and thus form a non-convex polygon, consecutive vertices are repeated, or the last point is equal to the first point.
  • Method Details

    • normal

      public NormalizedVector normal​(Point p)
      Calculates the normal to the Polygon. The given Point is disregarded.
      Specified by:
      normal in class Geometry
      Parameters:
      p - The point at which to calculate the normal.
      Returns:
      A vector perpendicular to the Polygon.
    • intersect

      public java.util.List<Intersection> intersect​(LineSegment line)
      Description copied from interface: Intersectible
      Calculates all the intersections between a given LineSegment and this object.
      Parameters:
      line - The LineSegment to check for intersections.
      Returns:
      A list of all the intersections with the given LineSegment.
    • boundary

      public geometries.Boundary boundary()
      Description copied from interface: Intersectible
      Get the Boundary of this intersectible.
      Returns:
      The bounding box of this intersectible.