Crossings Node

john's Avatar

john

15 Dec, 2024 04:12 AM

My new crossings node finds points where linear paths join or cross.

It's actually pretty simple and easy to use, but there are some subtleties that require explanation.

By "linear paths" I mean paths with no curves, only lines or splines composed of line segments. By "join" I mean two segments that touch on their endpoints, like the corners of a polygon; those points are already present in the supplied paths. By "cross" I mean a segment that intersects with another segment at a new point.

Crossings are something which any three-year-old can easily see and point to, but which are hard for Nodebox to find. If you spin copies of a triangle with a copy node you will create a beautiful star pattern with lots of crossing points, but if you turn on the points indicator in the render pane you will notice that none of those crossings appear as points. Nodebox is completely unaware of them - which makes it hard to place decorations at each crossing.

This is the problem solved by the crossings node. See attached demo and screenshot.

The colliding a and B in the lower right shows a simple example. Crossings takes a list of paths or geometries, in this case two text paths. Because both of these paths contain curves, I first passed them through my resamp_curv node. If you look closely you will see that the curved sections of two letter have been replaced with tiny straight line segments; you can make them even smoother by increasing the number of points in resamp_curv.

If you feed in curved paths without resampling them, the crossings node will not break, but some of the crossing points may be slightly off. You can see this by zooming way into the letter a and watching the dots carefully as you bypass its resamp_curv node.

THE INCLUDE PARAMETER

Crossings take two parameters: Include and Output. Include has four possible settings:

  • ALL Breaks and Endpoints
  • Breaks At Least One Segment
  • Breaks Both Crossing Segments
  • End-to-End Only

The dots in the colliding letters use the "Breaks At Least One Segment" setting to show only the new, previously undetected points. If it had been set to the ALL setting you would also see all the joints in both letters where different line segments join end to end.

You can better understand the difference between these four options by looking at the four pentagon pairs at the left side of the diagram. In each case a red and blue pentagon are horizontally offset:

  • The first case shows 11 crossing points: the five existing corners of each pentagon plus one new break point that occurs near the top.
  • The second case shows the 3 points which break at least one segment. The point at the top is new to both pentagons. The two points at the bottom are places where the endpoint of one pentagon crosses somewhere in the bottom side of the other pentagon. Although these two bottom breaks are new to one pentagon or the other, they also happen to be pre-existing corners, so Nodebox can "see" them.
  • The third case shows only the single point that breaks both pentagons. It occurs in the middle of the northeast side of the red pentagon and the northwest side of the blue pentagon, so Nodebox would be unaware of it.
  • The fourth case shows only the 10 corners of the pentagon where segments join end to end; it does not show the new break near the top.

THE OUTPUT PARAMETER

Crossings second parameter, output, has two possible settings: points and table. Points simply returns the crossing points, only one point for each crossing even if multiple segments cross at the same point. Table returns details about each crossing. It has the following columns:

  • order. The point numbers associated with the output of the points option. In cases where multiple crossings occur at the same point, there will be multiple rows with the same order value.
  • point. The actual exact crossing point which you can lookup and use.
  • string. A rounded string representation of the crossing point which can be used to compare points and easily remove duplicates.
  • segmentA. The first segment involved in a crossing, which includes not just properties like position and length, but also the stroke color and thickness of the original path of which that segment is a part. These properties can be useful for further computations.
  • segmentB. The second segment involved in each crossing pair.
  • type. The type of crossing. There are four possible types:
    • E-E an end-to-end crossing or "joint"
    • E-B the endpoint of segment A touching a breakpoint in segment B
    • B-E a breakpoint in segment A touching an endpoint in segment B
    • BB a new point which simultaneously breaks both segments

On the far right edge of the demo nodes you will find crossings13 which is set to output a table instead of points; if you render the draw_table5 node below that you can see the table output for each of the four possible include settings. Just change the include option in crossings13 to see how each option translates to a different table. You can even see the segments represented as colored lines (with thickness and length distorted to fit into each table row).

The table for the first option with all 11 points actually has 13 rows since points 3 and 5 occur twice. Point 3 is both a corner where two endpoints of the red pentagon meet and a breakpoint where that corner intersects somewhere in the middle of the bottom side of the blue pentagon. The same thing happens in reverse for point 5.

These table entries may seem confusing at first, but provide a wealth of information that you can use to do things that would otherwise be impossible. To see an example of this, look at the colored star mandala in the upper right.

THE STAR

This star is simply a triangle copied and rotated ten times. Then ten copies are assigned four colors supplied by my sanzo_colors node. In addition to the 30 corners of those 10 triangles, the rotations form 270 new points that Nodebox cannot see by itself.

For this diagram I color each of those points with a color based on the two colors of the edges forming each crossing using my inter_color node which essentially takes an average of the two hues. In addition to the four original colors, there are six different possible intermediate colors, shown in the matrix at the center of the star (which is also made using the crossings node).

For both the star and the color matrix, it would not be possible to determine the dot colors with the points alone. Points in Nodebox do not have a color property. So in order to pick a color I have to look up the corresponding segment pairs for each crossing using the table output.

If you look closely, you can see that I have also added colored arrows emanating from each crossing point in the direction of movement along the two edges involved in each crossing. This also uses information from the table output. Peer inside the arrows subnetwork to see how I did it.

Congratulations to anyone who actually read this detailed explanation. Now it's playtime. Just overlap a few shapes, feed them into the crossings node, and use the points output to draw dots (or whatever) at each point they cross. I think you can use this node at first without fully understanding all the subtleties. But if you need to do something tricky, something previously impossible in Nodebox, then you can come back to this demo and explanation.

Enjoy! This node will be included in version 3.5 of my library, coming soon.

  1. 1 Posted by lastvector on 16 Dec, 2024 08:59 AM

    lastvector's Avatar

    Great, thank you

    This looks very interesting to me because
    we can use these points to position shapes.
    Which offers a lot of possibilities :)

    gottfried

Reply to this discussion

Internal reply

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

Attaching KB article:

»

Already uploaded files

  • crossings_node_screenshot.png 1.15 MB
  • crossings_node_demo.ndbx.zip 234 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

26 Jan, 2025 02:09 AM
24 Jan, 2025 07:50 AM
22 Jan, 2025 11:42 PM
21 Jan, 2025 09:43 AM
21 Jan, 2025 09:41 AM

 

21 Jan, 2025 09:36 AM
21 Jan, 2025 02:00 AM
16 Jan, 2025 08:30 PM
15 Jan, 2025 06:37 AM
04 Jan, 2025 04:09 AM
03 Jan, 2025 05:32 PM