Moving a single point of a path
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?
- Screenshot_2022-10-23_at_13.06.25.png 571 KB
- movepoint.ndbx.zip 1.59 KB
|?||Show this help|
|ESC||Blurs the current field|
|r||Focus the comment reply box|
|^ + ↩||Submit the comment|
You can use
Command ⌘ instead of
Control ^ on Mac
Support Staff 1 Posted by john on 24 Oct, 2022 01:56 AM
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.
2 Posted by Jussi Jokinen on 24 Oct, 2022 11:32 AM
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.