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

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