Skip to main content

Visual-Center

Aliases: polyLabel, pole-of-inaccessibility, largest inscribed circle

Python 3.10 >=

pip install visual-center

Calculates the pole of inaccessibility of a polygon with optimizations based off of 'A new algorithm for finding a visual center of a polygon'

This is a port of Polylabel

If this package doesn't suit your needs, there is an alternative port here: Twista/python-polylabel

This package was created with a personal goal of learning more about quadtrees. I wasn't planning on duplicating a port for the public. But now that we're here, I'm packaging this up for pip. Maybe others will find it useful.

What is a 'Visual Center'?

The visual center is the point in a polygon that is furthest from the polygon's edge. For basic shapes, the centroid is usually this point, but for more complex shapes this isn't always the case.

For example, the centroid (Blue dot) of this polygon lands outside of it. The visual center (Red dot) is the point that is furthest from the polygon's edge.

Picture of a C shape polygon. Centroid lands outside of the polygon

Usage

import visual_center

polygon = [
    [0, 0],
    [0, 100],
    [100, 100],
    [100, 0]
]

pole, distance = visual_center.find_pole(polygon)
  • Pole is a tuple of the x and y coordinates of the visual center (Named after the pole-of-inaccessibility)
  • Distance is the distance from the visual center to the polygon's edge

Examples (Red dot is the pole. Red circle is the distance):

With a hole

This is especially useful for polygons with holes.

import visual_center

polygon = [
    [0, 0],
    [0, 100],
    [100, 100],
    [100, 0]
]

holes = [
    [[50, 10], [50, 90], [90, 90], [90, 10]],
    [[10, 10], [10, 30], [40, 30], [40, 10]]
]

pole, distance = visual_center.find_pole(polygon, holes)

First param is the outer shell polygon. Second param is a list of holes.

Example with holes:

How does it work?

I highly suggest reading the original article: 'A new algorithm for finding a visual center of a polygon'

tl;dr: Uses quadtree partitioning to recursively subdivide the polygon into smaller cells, probing the centers of these cells as candidates and discarding cells that cannot possibly contain a better solution.

Here's some fun visualizations of the algorithm in action: Picture of a C shape polygon. Centroid lands outside of the polygon

Release files for visual-center 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for visual-center 0.1.2
File Interpreter ABI Platform
visual_center-0.1.2-py3-none-any.whl Python 3 none any Details

Release files / visual_center-0.1.2-py3-none-any.whl

Download URL visual_center-0.1.2-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
84fe1d81c909685a8146e3131d9f3b81edf0a6a22d56780bcfa18d55deac16e5
BLAKE2b-256 checksum
How to use checksums
b0fe6970c1019204c2e0fc0a6a53527814c5a9b926a281f2d639123c28b17970
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release history Release notifications | RSS feed

This release

0.1.2 This release

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page