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…

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

  • 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

  • TrainingTracking101

    The Importance of Training Tracking in Modern Organizations In today’s fast-paced business environment, continuous learning and development are crucial for maintaining a competitive edge. Training tracking systems have become an essential tool for organizations aiming to ensure their workforce remains skilled and compliant with industry standards. This article explores the significance of training tracking and…

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