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

  • Training Tracking 101 . Allena Software

    Founder and developer of Training Tracking 101. A software company that creates affordable, easy to learn and implement database desktop solutions. As an entrepreneur I; research, designed, wrote programming code and performed testing and debugging of applications using programming languages and technologies. Designed and created graphics and content for software products, support, website and marketing…

  • 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…

  • Programming

    AutoCAD Fast Lisp Scripts – library of AutoCAD shortcuts and scripts to speed up CAD drafting Legend Lisp – Create a legend of AutoCAD Entities AutoLisp Modes and Tables FLC Simulation in C and C++ Language MS Access Developer

  • Tblin AutoLisp Modes

    (defun c:tblin (/) ;Initialize counters. (setq Row 0) (setq Col 0) ;Change these variables to adjust row and columns. (setq OffCol 2) (setq OffRow 0.2) (setq ColMax 9) (setq eof 0) (setq Filename (FileToRead)) (setq FileHandler (open Filename “r”)) (while (= eof 0) (progn (while (< Col (* OffCol ColMax)) (progn (setq TextIn (read-line FileHandler))…

  • Block AutoLISP Shortcuts

    ;;; SHORCUTS BY V. MENDEZ ;SHOWS THE BLOCK NAME OF AN ENTITY (DEFUN C:BB(/ bb name) (SETQ bb(entget(car(entsel)))) (SETQ name (cdr(assoc 2 bb))) (SETQ name (strcat “Block Name… ” name)) (ALERT name) (princ) ) ;SHOWS THE LAYER NAME OF AN ENTITY (DEFUN C:CC(/ bb name) (SETQ bb(entget(car(entsel)))) (SETQ name (cdr(assoc 8 bb))) (SETQ name (strcat…

  • 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…