polygon
    
    
    
      polygon,
      a MATLAB code which
      computes properties of an arbitrary polygon in the plane, defined
      by a sequence of vertices, including interior angles, area, centroid,
      containment of a point, convexity, counter clockwise ordering, diameter,
      distance to a point, inradius, lattice area, nearest point in set, 
      outradius, uniform sampling, and triangulation.
    
    
      Licensing:
    
    
      The information on this web page is distributed under the MIT license.
    
    
      Languages:
    
    
      polygon is available in
      a C version and
      a C++ version and
      a Fortran77 version and
      a Fortran90 version and
      a MATLAB version and
      an Octave version and
      a Python version.
    
    
      Related Programs:
    
    
      
      polygon_test
    
    
      
      ellipse,
      a MATLAB code which 
      carries out geometric calculations for ellipses and ellipsoids, including
      area, distance to a point, eccentricity, perimeter, points along the 
      perimeter, random sampling, conversion between standard and quadratic forms.
    
    
      
      polygon_average,
      a MATLAB code which
      demonstrates a process of repeatedly averaging and normalizing the
      vertices of a polygon, illustrating a property of the power method.
    
    
      
      polygon_distance,
      a MATLAB code which
      computes the expected value of the distance
      between a pair of points randomly selected from a polygon in 2D.
    
    
      
      polygon_grid,
      a MATLAB code which
      generates a grid of points
      over the interior of a polygon in 2D.
    
    
      
      polygon_integrals,
      a MATLAB code which
      returns the exact value of the integral of any monomial
      over the interior of a polygon in 2D.
    
    
      
      polygon_monte_carlo,
      a MATLAB code which
      applies a Monte Carlo method to estimate the integral of a function
      over the interior of a polygon in 2d.
    
    
      
      polygon_triangulate,
      a MATLAB code which
      triangulates a (possibly nonconvex) polygon,
      based on a C function by Joseph Orourke.
    
    
      
      quadrilateral,
      a MATLAB code which
      carries out geometric calculations on quadrilaterals, including
      angles, area, distances, nearest point, point containment, perimeter,
      and random generation.
    
    
      
      tetrahedron,
      a MATLAB code which
      carries out geometric calculations involving a general tetrahedron,
      including solid and facial angles, face areas,
      point containment, distances to a point, circumsphere and insphere,
      measures of shape quality, centroid, barycentric coordinates,
      edges and edge lengths, random sampling, and volumes.
    
    
      Source code:
    
    
      
        - 
          
          angle_half.m,
          returns a ray defining half the angle between two rays;
        
 
        - 
          
          angle_rad.m,
          returns the angle between two rays;
        
 
        - 
          boolean_to_string.m,
          returns "True" or "False", given a boolean value.
        
 
        - 
          
          i4_wrap.m,
          forces an integer to lie in a given range;
        
 
        - 
          
          polygon_angles.m,
          computes the angles of a polygon;
        
 
        - 
          
          polygon_area.m,
          computes the area of a polygon;
        
 
        - 
          
          polygon_area_2.m,
          computes the area of a polygon;
        
 
        - 
          
          polygon_area_3.m,
          computes the area of a polygon;
        
 
        - 
          
          polygon_area_3d.m,
          computes the area of a polygon in 3D;
        
 
        - 
          
          polygon_area_3d_2.m,
          computes the area of a polygon in 3D;
        
 
        - 
          
          polygon_area_lattice.m,
          finds the area of a lattice polygon;
        
 
        - 
          
          polygon_centroid.m,
          computes the centroid of a polygon;
        
 
        - 
          
          polygon_centroid_2.m,
          computes the centroid of a polygon;
        
 
        - 
          
          polygon_centroid_3d.m,
          computes the centroid of a polygon in 3D;
        
 
        - 
          
          polygon_contains_point.m,
          finds if a point is inside a polygon;
        
 
        - 
          
          polygon_convex_contains_point.m,
          finds if a point is inside a convex polygon;
        
 
        - 
          
          polygon_contains_point_3.m,
          finds if a point is inside a simple polygon;
        
 
        - 
          
          polygon_data_inrad.m,
          uses the inradius to compute other data for a regular polygon;
        
 
        - 
          
          polygon_data_outrad.m,
          uses the outradius to compute other data for a regular polygon;
        
 
        - 
          
          polygon_data_side.m,
          uses the side length to compute other data for a regular polygon;
        
 
        - 
          
          polygon_diameter.m,
          computes the diameter of a polygon;
        
 
        - 
          
          polygon_expand.m,
          "expands" a polygon;
        
 
        - 
          
          polygon_integral_1.m,
          integrates the function 1 over a polygon;
        
 
        - 
          
          polygon_integral_x.m,
          integrates the function x over a polygon;
        
 
        - 
          
          polygon_integral_xx.m,
          integrates the function x^2 over a polygon;
        
 
        - 
          
          polygon_integral_xy.m,
          integrates the function x*y over a polygon;
        
 
        - 
          
          polygon_integral_y.m,
          integrates the function y over a polygon;
        
 
        - 
          
          polygon_integral_yy.m,
          integrates the function y*y over a polygon;
        
 
        - 
          
          polygon_is_convex.m,
          determines the convexity of a polygon;
        
 
        - 
          
          polygon_monomial_integral.m,
          evaluates the integral of any monomial over a polygon.
        
 
        - 
          
          polygon_normal_3d.m,
          finds the normal vector for a (planar) polygon in 3D;
        
 
        - 
          polygon_perimeter.m
          determines the length of the perimeter of a polygon.
        
 
        - 
          polygon_perimeter_quad.m
          estimates the integral of a scalar function along the perimeter of a polygon.
        
 
        - 
          
          polygon_point_dist.m,
          finds the distance to a polygon;
        
 
        - 
          
          polygon_point_near.m,
          finds the nearest point on a polygon;
        
 
        - 
          polygon_sample.m
          returns sample points from a polygon.
        
 
        - 
          
          polygon_solid_angle_3d.m,
          determines the solid angle subtended by a polygon with respect
          to a unit sphere around a given point in 3D;
        
 
        - 
          polygon_triangulate.m
          triangulates a polygon.
        
 
        - 
          r8vec_cross_product_3d.m,
          computes the cross product of two R8VEC's in 3D;
        
 
        - 
          
          r8vec_scalar_triple_product.m,
          computes the scalar triple product;
        
 
        - 
          
          segment_point_dist.m,
          computes the distance between a point and a line segment;
        
 
        - 
          
          triangle_area.m,
          returns the area of a triangle;
        
 
        - 
          
          triangle_area_3d.m,
          returns the area of a triangle in 3D;
        
 
        - 
          
          triangle_area_vector_3d.m,
          returns the area vector of a triangle in 3D;
        
 
        - 
          
          triangle_barycentric.m
          finds the barycentric coordinates of a point.
        
 
        - 
          
          triangle_contains_point_1.m
          finds if a point is inside a triangle.
        
 
      
    
    
    
      Last revised on 02 January 2025.