drawing individual triangles from a list of points?

ppape's Avatar

ppape

20 Sep, 2021 07:51 AM

Hello,

I'm trying to draw irregular triangles along a freehand line by breaking the line into points and drawing a vertical line at every other point.

Now i would like to have triangles drawn, the end points of which are on the outside of the vertical line and on the line at the two neighboring points, but I can't convert the list of points into individual triangle objects. (tried to slice the list with a range as starting ponts, but that created just a copy of the points list.)

Since I want to color the triangles differently later (as shown in the litte illustration), i need individual objects. Is there a way to do this in Nodebox that I don't see? I can not use the ›shape on path‹ node, because the shapes do overlap or get space in between.

Thanks for any help with this.
p.

  1. Support Staff 1 Posted by john on 20 Sep, 2021 09:35 AM

    john's Avatar

    Hi Phillip,

    The easiest way to do this is to make a subnetwork. See attached Nodebox file and screenshot.

    I made a subnetwork that takes three inputs: the tick lines, the points before each tick line, and the points after each tick line. By feeding these into a subnetwork one at a time it makes it easy to pull out the top of the line, make a triangle out of that, and pull out the bottom of the line, and make a second triangle out of that. You can peer inside the triangle subnetwork to see how I did it.

    To get one list of before points and one list of after points, I just took the list of black dot points and dropped the last point for the before list and dropped the first point for the after list.

    This method assumes that there is always one point before the first tick line, and one point after the last tick line. Because of your shift node your network was actually drawing an extra tick mark at the front; I removed this using a drop_last node (from my node library).

    When playing with this, I noticed that the Freehand node occasionally created an invalid point (with NaN points for Not a Number). So I added a few more nodes to test for this and remove any bogus points.

    I assigned the colors from your example for the triangles, but of course you can modify that with whatever colors you want.

    Give this a spin and let me know if it solves your problem, and if you have any more questions.

    This looks like a fun project! Thanks for sharing it!

    John

  2. 2 Posted by ppape on 22 Sep, 2021 09:06 AM

    ppape's Avatar

    Thank you John, that's exactly what I tried to achieve. Now trying to understand how you did it I get stuck with the problem of – as you write – ›feeding these into a subnetwork ONE AT A TIME‹. Thats where I get stuck all the time. If I try to do something like that, all the points from a list get connected in one shape.

  3. Support Staff 3 Posted by john on 22 Sep, 2021 10:19 AM

    john's Avatar

    Phillip,

    The main function of subnetworks is to let you control whether items are input one at a time or all at once. But the method of choosing one or the other is not obvious.

    When you make a subnetwork and publish one or more ports, select that subnetwork and click Metadata (above the settings pane). This will summon the metadata dialog. Select a port on the left to see its settings on the right.

    For the Range setting you have two choices: Value will force the port to accept items one at a time; List will force the port to accept items all at once (each time the subnetwork fires).

    This is a subtle distinction that took me quite awhile to get used to. But once I understood it whole new worlds opened up.

    By the way, you can also inspect the Range setting for ports on standard nodes. If you do this you will see that some are set to value and others to list. You can't change this behavior (changing the value will only cause errors), but you can wrap the node inside a subnetwork, publish the ports you need, and THEN change the port behaviors.

    An example of this is the humble combine node. If you inspect it you will see that all seven ports are set to list. This means that if you feed two lists into a combine node it will give you all the elements of list A and then all the elements of list B.

    But what if you want to interweave the lists to produce A1, B1, A2, B2, A3... etc.? Just select the custom node, say "Group into Network", open the subnetwork, and publish the first two ports (list1 and list2). Then close the subnetwork, open the Metadata dialog, and change the Range values of both list1 and list2 from List to Value. Voila! You now have an interweave subnetwork.

    Try playing around with this the next time you run into this issue. If you still have questions send me another misbehaving network and I will try to straighten it out for you.

    Happy Nodeboxing!

    John

  4. 4 Posted by ppape on 22 Sep, 2021 02:21 PM

    ppape's Avatar

    This really opened up my eyes and a whole new way of working with Nodebox. Thank you so much for your helpful answers!

Reply to this discussion

Internal reply

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

Attaching KB article:

»

Already uploaded files

  • triangles_on_path.ndbx.zip 2.87 KB
  • Bildschirmfoto_2021-09-20_um_09.30.35.png 103 KB
  • Bildschirmfoto_2021-09-20_um_09.37.49.png 63.7 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

 

06 Sep, 2021 07:06 PM
20 Aug, 2021 03:27 PM
18 Aug, 2021 11:31 AM
18 Aug, 2021 09:42 AM
30 Jul, 2021 11:35 PM
29 Jul, 2021 10:11 PM