True Center Node

john's Avatar

john

21 Feb, 2023 02:24 AM

Attached is a new node: true_center. It calculates the true center of regular polygons, stars, and fancy stars.

The centroid node is used to determine the geometric center of a shape in Nodebox. It is based on the the bounds of the shape. But for certain shapes, including regular polygons (generated by the polygon node), stars (generated by the stars node), and fancy stars (generated by my new fancy_star node), with an odd number of sides or tips, the centroid will not return the true center of the shape.

This becomes a problem if you need to rotate the shape or place it precisely. The fewer the sides or tips, the more pronounced the problem is, with triangles being the worst case.

True_center solves this problem. Feed it any regular polygon, star, or fancy star and it will return the ship's true center (the center point where all the corners or tips project from).

See attached screenshot and demo. Hook the output of a fancy_star node, polygon node, or star node to the null node at the top, turn on your origin markers, and render the combine node at the bottom. Since these shapes are all drawn at the origin, their true center (indicated by the red dot), should always be at the origin. As you change the settings and number of sides or tips you will notice that the true center stays fixed. But the centroid, indicated by the smaller black dot, will drift whenever there is arn odd number of sides or tips.

Rotating the shape (around its true center) will not affect the red dot, but will cause the centroid to shift. You can see this easily in the demo by simply hitting the play button.

True_center only works with polygons and stars. In order to find reasonable center points inside arbitrarily weird shapes, see another new node, good_center:

http://support.nodebox.net/discussions/show-your-work/565-good_cent...

True_center is a life-saver when doing precise work like the Islamic tiles I am working on at the moment. It will be included in the next release of my Cartan Node Library and is free to use with no restrictions.

Enjoy!

John

Reply to this discussion

Internal reply

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

Attaching KB article:

»

Already uploaded files

  • true_center_screenshot.png 355 KB
  • true_center_demo.ndbx.zip 15.4 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

Generic

? 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

10 Sep, 2024 03:41 AM
09 Sep, 2024 02:15 PM
07 Sep, 2024 05:16 AM
05 Sep, 2024 02:21 AM
04 Sep, 2024 05:01 AM

 

03 Sep, 2024 10:07 AM
02 Sep, 2024 05:56 AM
31 Aug, 2024 11:07 PM
27 Aug, 2024 12:08 AM
26 Aug, 2024 01:02 PM
26 Aug, 2024 07:18 AM