Moving a single point of a path

Jussi Jokinen's Avatar

Jussi Jokinen

23 Oct, 2022 10:09 AM

Hi,

In my recent project I needed to modify one point of a path (move one point of a rectangle). My solution was to create a node for just that – move a point of a given index and then reassemble the path again and re-apply the fill and stroke attributes. See the file attached. The question: was this solution too complex? Is there a cleaner, easier way of doing this seemingly simple operation?

  1. Support Staff 1 Posted by john on 24 Oct, 2022 01:56 AM

    john's Avatar

    Jussi,

    Your implementation is fine and I don't think it can be made much simpler. You have to reduce the path to points in order to replace one of those points, and once you reconnect, you have to recolor, and because of the Nodebox bug with strokeColor when strokeWidth is 0, you have to test for that.

    One small improvement. For the third slice node to recover the points after the replaced point, instead of counting the points and doing that math, you can just take the inverse of your first slice node (check the invert box) and drop the first point. That saves you a few nodes.

    For the point I replaced your null node with a point node so that you can set that point directly in movePoint without having to create a separate point node.

    See screenshot and attached zip file.

    For a more general purpose solution, see the push_pull node in my Cartan Node Library. It can handle curved shapes as well as polygons, and instead of replacing a point it creates a force from a given direction that pushes or pulls a subset of the shape's points. You can adjust how many points you wish to affect. It also has a handy "Show Controls" option that lets you see what you are doing.

    Nice work!

    John

  2. 2 Posted by Jussi Jokinen on 24 Oct, 2022 11:32 AM

    Jussi Jokinen's Avatar

    Thanks again John, good points! I have explored your excellent push_pull -node but using it didn't occur to me in this case since I only needed to move one point a few notches down.

Reply to this discussion

Internal reply

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

Attaching KB article:

»

Already uploaded files

  • Screenshot_2022-10-23_at_13.06.25.png 571 KB
  • movepoint.ndbx.zip 1.59 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

22 Nov, 2022 03:21 PM
22 Nov, 2022 10:40 AM
22 Nov, 2022 09:55 AM
20 Nov, 2022 12:06 PM
08 Nov, 2022 10:44 PM

 

05 Nov, 2022 08:40 AM
03 Nov, 2022 09:38 PM
24 Oct, 2022 11:32 AM
06 Oct, 2022 09:07 AM
05 Oct, 2022 02:22 AM
30 Sep, 2022 11:36 PM