It seems a so simple task, but I have many doubts on how to approch the problem.

All I need is, starting from a 2-colored bitmap showing a plane and a fulfilled circle, to find the starting x,y, width and height of the minimal square which inscribe that circle.

Dear Experts, any idea on the algorithm that may solve this problem?

All I need is, starting from a 2-colored bitmap showing a plane and a fulfilled circle, to find the starting x,y, width and height of the minimal square which inscribe that circle.

Dear Experts, any idea on the algorithm that may solve this problem?

uppermost:

for each row, progressing from top to bottom, run through the pixels you hit a shaded pixel on the row. Take the coordinate of the centremost shaded pixel on that row to find the uppermost point of the circle.

bottom:

as for uppermost except scan rows from bottom to top

leftmost:

for each column, starting from the left, cycle through the pixels in it, stopping when you hit a shaded one. Again use the coordinate of the centremost shaded pixel as the leftmost point of the circle.

rightmost:

as fo leftmost, but start from the right

This one is on us!

(Get your first solution completely free - no credit card required)

UNLOCK SOLUTION
Given a point inside and a point outside, you can binary search between them to find an edge.

A point inside a large circle can be found in an average of sizeofimage/sizeofcircle probes.

Scanning in steps in a Golden Ratio can give fairly even coverage at increasing resolutiom.

If circe is filled with the other color you can use "binary search" - I think ozo call it "Golder Ratio". You divide you scan on the middle and check where is the filled/unfilled area. When you find it you can divide you interval by 2 and find it again. After some iteration steps you can find the "switch" point exactly.

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.