Inscribe Node
The attached inscribe node inscribes one shape into the center of another.
By "inscribe" I mean that the shape is placed at the center of the container shape and then scaled up until some part of it makes contact with some part of the container shape.
If you use inscribe to put a circle inside a regular polygon, or vice versa, you will get the standard inscribed figure seen in a geometry textbook. But if you put less symmetrical shapes into less symmetrical containers, like text paths into random concave polygons, the inscribed shape may not perfectly fill its container. This is because the inscribed shape is always placed at the center of the container shape, even if some other placement would allow a snugger fit. If the center of the container lies outside the container, as it does with the letter C, the inscribed shape will land outside the container and grow until it hits some part of it.
(A perfectly snug inscribed shape would be nice, but would be very difficult to compute given the almost limitless variety of possible shapes and all the myriad ways they could possibly fit together.)
One subtle point. For most shapes, inscribe uses the standard centroid to determine the center of both shapes passed to it. But in the case of triangles, regular polygons, and stars, it uses my "true_center" node to find the correct geometric center.
Inscribe takes three parameters:
- shape. The interior shape
- container. The containing shape (for best results use a simple shape, not a group)
- margin. Increase from zero to add extra space between the interior shape and the container
The margin is a percentage of the scale value used to size the interior shape (not a fixed number of pixels), so will stay consistent if the container is scaled up or down. The maximum margin is 100% (which would reduce the interior shape to nothing). If you enter a negative margin, the interior shape will grow beyond the bounds of its container.
The inscribe node is similar to the Nodebox fit_to node, but often produces better results. Fit_to scales a shape up until it his the bounding box of a container shape, not the container shape itself. When you use the fit_to node, your shape often winds up as big as its container and pokes outside in various places. Inscribe, in contrast, always fits its shape entirely inside its container (unless the container's center is outside the container as noted above).
You can see the comparison of inscribe to fit_to in the demo (see screenshot).
The first nine figures on the left show a heart (in white) inscribed inside various container shapes (in red). The faint blue shapes show the result of using a fit_to node to place that heart into those same container shapes. As you can see, the blue shapes press against the blue bounding boxes.
The next nine figures on the left show the reverse: various white shapes inscribed into red hearts.
On the right is a textpath label inscribed into seven different rotations of a heart-shaped container, with the margin set to 20%. As you can see, the size of the label varies depending on how the overall shape of the label interacts with the shape of the rotated heart.
The demo also contains another set of nodes that let you play with two shapes at a time. Render the combine7 node to see a red interior shape inscribed inside a blue exterior shape. Change the values of the INTERIOR and EXTERIOR numbers, from 0 to 8, to try any combination of the nine shapes in the demo. You can also try adjusting any of those shapes (changing rotation, dimension, number of sides, etc.) or replace the interior or exterior with any other shape you care to make.
Inscribe has to make a thousand measurements to find the correct size for each inscribed shape. Despite this, it is reasonably fast, taking about 150 milliseconds. It does OK with a few dozen shape pairs, but would be to slow to handle hundred or thousands.
Inscribe will be included in the next version of my Cartan Node Library - which will be published SOON. Comments always welcome.
John
- inscribe_demo_screenshot.png 733 KB
- inscribe.ndbx.zip 105 KB
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