How to Fill Orthogonal Polygons with Grid Points in CAD and Geometry

Problem:

There is a closed polygon perimeter. All vertexes are in a right angle (orthogonal) .
How to create a grid inside the polygon if it has 8 vertexes?

Solution:

A simple orthogonal polygon—a polygon where:

  • All interior angles are either 90° or 270° (i.e., right angles or reflex right angles).
  • It’s closed and has 8 vertices.
  • You want to fill it with a uniform grid of points, for example for sprinkler layout, meshing, or tiling.

This problem sits at the intersection of computational geometry, grid rasterization, and polygon point-inclusion tests.


✅ Problem Setup

You are given:

  • A list of 8 ordered vertices: [(x1, y1), (x2, y2), ..., (x8, y8)]
  • All angles are orthogonal (90° or 270°), so the edges are axis-aligned (only horizontal or vertical).
  • The polygon may be non-convex (like an L-shape or staircase).

Your goal:

  • Place points at regular intervals (spacing s) inside the polygon.

✅ Step-by-Step Mathematical Approach

1. Bounding Box

Find the smallest rectangle that contains the polygon:

minX = min(x_i)
maxX = max(x_i)
minY = min(y_i)
maxY = max(y_i)

2. Grid Scanning

Scan all grid points in the bounding box:

For x in range(minX, maxX, spacing):
    For y in range(minY, maxY, spacing):
        If point (x, y) is inside the polygon:
            Add it to the grid

3. Point-in-Polygon Test

Use a ray casting or winding number algorithm:

Ray casting (for any polygon):

For a point (px, py), cast a ray to the right and count how many edges it crosses:

  • If odd, point is inside
  • If even, point is outside

For orthogonal polygons, this is faster because edges are axis-aligned.

Optimized scanline algorithm:

For each row y (a horizontal scanline), find x-intersections with polygon edges.

  • Sort intersection points in pairs.
  • Fill grid points between x1 and x2, x3 and x4, etc.

📘 Recommended Books

Here are books that discuss these methods:

1. Computational Geometry: Algorithms and Applications

  • Authors: Mark de Berg, Otfried Cheong, Marc van Kreveld, Mark Overmars
  • Topics Covered:
    • Polygon triangulation
    • Point-in-polygon tests
    • Scanline and plane sweep algorithms
    • Grid-based spatial partitioning
  • Use: Chapters on polygon algorithms and rasterization are very relevant.

2. Geometry and Topology for Mesh Generation

  • Author: Herbert Edelsbrunner
  • Focus: Tiling, grid generation, domain filling
  • Useful if you’re working toward mesh/grid generation inside polygons.

3. Graphics Gems series

  • Especially Graphics Gems I & II
  • Has optimized point-in-polygon algorithms for axis-aligned shapes.

✅ Optional: Python Example of Grid Filling (Mathematical Illustration)

from shapely.geometry import Point, Polygon

# Define orthogonal polygon
corners = [(0,0), (6,0), (6,2), (4,2), (4,4), (2,4), (2,2), (0,2)]
poly = Polygon(corners)

spacing = 1
points_inside = []

minx, miny, maxx, maxy = poly.bounds

x = minx
while x <= maxx:
    y = miny
    while y <= maxy:
        pt = Point(x, y)
        if poly.contains(pt):
            points_inside.append((x, y))
        y += spacing
    x += spacing

✅ Summary of the Math:

StepConceptMath
Bounding boxmin/max(x/y)Simple min/max
Gridx, y stepped by spacingLoop from min to max
Inclusion testRay casting / scanlineEven-odd rule, integer crossings
Grid fillRasterizationPlace points at (x,y)

Similar Posts

  • Nine Algorithms That Changed the World

    Nine Algorithms That Changed the World In the realm of computer science, algorithms reign supreme. They are the step-by-step procedures that enable computers to solve problems and make decisions.1 Some algorithms have had such a profound impact on the field that they have become essential tools for programmers and researchers alike. In this article, we…

  • AutoCAD/MS Access Frontends with SQL Backend Integration

    AutoCAD/MS Access Frontends with SQL Backend Integration Problem: Each Sub-Department at the Utilities Department of the University of Colorado at Boulder have specific requirements for spatial and spatial data and often, there is an overlap of information crucial to these sub-departments; operations, maintenance, management, etc. Equipment data is stored and maintained in an SQL database…

  • MS Access Developer

    Help with design, development or repair of your Microsoft Access database. Some things about me: – 15 years of experience as an independent consultant for Access development projects – Many references. – Masters degree in Biostatistics. – Have taught business development at the Boulder Small Business Development Center. I can wrap my mind around just…

  • Legend AutoLisp

    (defun C:LEGEND () (prompt “\nBuilding legend list…\n”) ;Set variable to get the first element of table. (setq Frst T) (setq Counter 0) (setq CountBlk 0) ;Get all block names. (while (setq Tbdata (tblnext “BLOCK” Frst)) (setq Bname (dxf 2 Tbdata)) ;print all block names. (if (/= Bname nil) ;Discard dimension blocks. (if (/= “*” (substr…

  • mcrouti3 lisp

    ; If an error (such as CTRL-C) occurs ; while this command is active… (defun at_err (st) (if (and (/= st “Function cancelled”) (/= st “quit / exit abort”)) (princ (strcat “\nError: ” st)) );end if ;Restore modified modes (setvar “regenmode” 1) (setvar “cmdecho” 1) (if (= (type rtfile) ‘FILE) (close rtfile) );end if (setq…