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

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

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

  • FLC Simulation

    A computer simulation application that applies statistical mechanics to predict pre-synthesis of Liquid Crystal properties from chemical structure is needed. As well as the creation of calculation, videoand data manipulation tools and a user interface. read more …

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

  • vsnap lisp

    (DEFUN C:VSNAP (/) ; Sept. 25,97. By V.Mendez ; This function centers an object between two parallel lines. (SETVAR “CMDECHO” 0) (SETQ SelObj (ENTSEL “\nSelect Object : “)) (SETQ BPoint (GETPOINT “\nBase Point : “)) (COMMAND “OSNAP” “NONE”) (COMMAND “OSNAP” “NEA”) (SETQ Point1 (GETPOINT “\nFirst Point [nearest] : “)) (COMMAND “OSNAP” “PER”) (SETQ Point2 (GETPOINT…