Good_Center Node

john's Avatar


21 Mar, 2023 11:00 AM

Attached is a demo of a new node: Good_center. Good_center finds a reasonable center point guaranteed to be inside a shape (unlike centroid, which can fall outside a shape).

The attached screenshot shows 9 random shapes. For each, the blue dot shows the position of that shape's centroid and the red star shows the position returned by good_center.

As you can see, good_center always falls inside its shape, no matter how strange. It works for shapes with multiple contours including holes (like the letter A) and disjoint contours (like separate islands in a nation). It lands well into the interior of its shape, often at or near the spot most people would identify as its visual center.

Good_center helps determine the placement of labels in my new place_label node. You can see it in action in the screenshots I posted of the world map in the place_label documentation and the five-way Venn diagram in the overlaps documentation:

Good_center uses a heuristic algorithm that almost always lands in a reasonable "center" spot without consuming too much processing time. It stars with a grid of 100 spots spread across the bounding box of the shape, deletes those not inside the shape, then measures the distance from each spot to 50 edges of the resampled shape to find the find the minimum distance to an edge. It repeats this for all spots and then takes the spot with the largest minimum distance from an edge (the "farthest inside"). It then starts at this center and repeats the process at half scale to zero in on an even better spot.

Limiting the number of candidate spots and the resampling resolution reduces the processing time at some loss of precision. But after extensive testing on many different kinds of shapes, I found this was a good tradeoff. This node generally produces reasonable center spots; increasing the resolution significantly slowed the performance while producing almost no noticeable improvement in most cases. In short, the centers produced by this algorithm are "good enough".

In addition to labeling, good_center is useful any time you want to place a smaller shape inside an arbitrary larger shape without crossing outside the boundary. Compare with another new node, true_center, which does find a perfect center point but only works for regular polygons and stars.

Good_center will be included in the next rev of my Cartan Node Library.



Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Already uploaded files

  • Good_Center_Screenshot.png 455 KB
  • 23.1 KB

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

29 May, 2024 05:47 AM
29 May, 2024 05:15 AM
29 May, 2024 05:12 AM
28 May, 2024 07:37 PM
25 May, 2024 11:52 AM


24 May, 2024 07:39 AM
16 May, 2024 02:11 AM
14 May, 2024 01:29 AM
12 May, 2024 07:46 PM
05 May, 2024 04:38 PM
03 May, 2024 06:50 AM