Find the center of a shape (path) on a canvas (Android Studio)

Viewed 2228

Is it possible to find the center of a shape on a canvas in Android studio? I've logged the touch points and can't seem to figure it out. It does however appear that the canvas (0,0) point is the top left, but the paths/shapes on the canvas see the center point as (0,0).

For an example of what I'm talking about check out the attached image, I'm trying to find where the green dot is.

Thanks in advance for any help.

IMG

2 Answers

No Need for Mathematical Calculations

RectF bounds = new RectF();
mPath.computeBounds(bounds, false);
float centerX = rectF.centerX();
float centerY = rectF.centerY();
Related