How to directly modify vertices of ofPath?

Hi, I wonder if it is possible to directly modify vertices of ofPath.

I think it is possible to do this with ofPolyline but if I try to modify the vertices of ofPath, it shows the error.

Is there a way to directly modify the vertices(not Commands) of ofPath?
Thanks!

getOutline returns an ofPolyline. This should not be easily done with something like

for (auto &vert : path.getOutline().getVertices()){
    vert.x += ofRandom(-1,1);
    vert.y += ofRandom(-1,1);
}

btw,
Working with lines is also covered on this chapter of the ofBook
http://openframeworks.cc/ofBook/chapters/lines.html

Hey @edapx Thanks for the reply.

So do you mean it is not possible to modify ofPath’s internal vertices?

mmmm.

ofPath uses ofPolyline internally. If you call path.setMode(POLYLINE), you should be able to modify the vertices as I;ve said before because I think that the vertices of your path are the vertices inside the ofPolyline.
In any case, if you are using an IDE as xcode or visual studio code you should be able to put a debugger and check if the positon of the vertices was modified

Hey thanks. could you please post the code that modifies the ofPath’s internal vertices?

Based on my original code, which part should I change to make it work without the error?

this might be helpful:

essentially an ofPath is a series of commands. you can manipulate those comamnds. I believe when you call get tessellation or get outline on an ofPath you are getting a rendering of those commands into triangle mesh or polylines but that you can’t alter the ofPath that way.

1 Like

As zach says an ofPath is composed by default by commands not by points. you can alter the commands using getCommands(), the to in each command is the most similar to the vertices in a polyline, although in cases like bezier, curve or circle that’s not exactly the case since to is only the last point of the bezier or curve segment or the center of a circle arc.

using POLYLINE mode as davide explains you can set the path to not use commnads and instead directly decompose them into polylines as you add them, in that case though you can’t really access the generated vertices for altering them since that could mess up some calculations in certain cases if you added more commands later on

1 Like