How to get inscribed rectangle in canvas

In android canvas, I defined a clipping area with many shapes (rectangle and 2 circles). I want to get an inscribed rectangle defined by the clipping environment.

Canvas has a method called getClipBounds() that gives me the described rectangle, how do I get the inscribed rectangle instead?

enter image description here

Edit: here is some information on how the original form is produced:

  • First add a clip for the big circle using Region.Op.INTERSECT
  • Then add a clip for the vertical rectangle with Region.Op.INTERSECT
  • Then add a clip for the smaller circle with Region.Op.DIFFERENCE
+4
source share
1 answer

This can be determined mathematically if you know the radius and center of both circles.

Find the two intersection points of the circles with the getClipBounds () rectangle. - The second highest intersection point between the red circle and the rectangle getClipBounds () contains the top y coordinate of the rectangle. -An additional intersection point between the white circle and the rectangle getClipBounds () contains the lower y coordinate of the rectangle. -X borders are already defined by the getClipBounds () rectangle.

You can build your three figures from there.

+1
source

Source: https://habr.com/ru/post/1444004/


All Articles