Finding the Centroid of Multiple Polylines and Translating

Hi,

Kind of a n00b question. I have a series of strokes I am reading into a vector of polylines. I would like to find the centroid of the blob (all the polylines together), and translate it to the center of the screen. This is a 2D app, and I am only rendering white strokes onto the screen (so no fills). Is there a clean way to do this, is polyline the right container?

Thanks in advance.

Simple thing I can think of is: adding all the polylines (appending all the unique points of each line) into one ofPolyline and calling getCentroid2D()?

Oh right. So I did try that but it draws a line between the strokes. The strokes arent necessarily connected together in all cases.

Probably not the most elegant way, but could you use the combined line for the calculation of the centroid, and use the vector for drawing all individual lines?

I did it a clunky way since there are not that many points and strokes.

Add all the vertices to another polyline, get the boundingbox, then get the center of the bounding box.

polyline.getBoundingBox().getCenter();

Seems to be working. :man_shrugging:t4: