#### Topic: The interesting and vital task with the useful result

So useful that is quite possible, someone already solved it and laid out as function in any library. It is given:  a picture of the arbitrary form on a canvas with the sizes *Y. We consider that coordinates of the left upper corner of a canvas 0,0. The task: to Find the maximum sides of a rectangle with the given ratio of the sides k, completely being in a picture. [Length of the horizontal side of a rectangle] / [length of the vertical side of a rectangle] =k. Function should return an array from three numbers: 1-2) r [0], r [1] - coordinates of the upper left corner of a rectangle on a canvas. 3) r [2] - length of the horizontal side of a rectangle.

#### Re: The interesting and vital task with the useful result

Hello, qwp, you wrote: qwp> so useful that is quite possible, someone already solved it and laid out as function in any library. qwp> it is given:  a picture of the arbitrary form on a canvas with the sizes *Y. We consider that coordinates of the left upper corner of a canvas 0,0. qwp> the Task: to Find the maximum sides of a rectangle with the given ratio of the sides k, completely being in a picture. qwp> [length of the horizontal side of a rectangle] / [length of the vertical side of a rectangle] =k. qwp> Function should return an array from three numbers: qwp> 1-2) r [0], r [1] - coordinates of the upper left corner of a rectangle on a canvas. qwp> 3) r [2] - length of the horizontal side of a rectangle. What is understood as a rectangle? Pixels of identical color? Any specific color? Other?

#### Re: The interesting and vital task with the useful result

Hello, the Corkcrew, you wrote: Hello, qwp, you wrote: What is understood as a rectangle? Pixels of identical color? Any specific color? Other? I suppose, it is a question what to display a certain object (picture) as much as possible "open" on the screen/in a window, without distortion of proportions.

#### Re: The interesting and vital task with the useful result

Hello, qwp, you wrote: qwp> It is given:  a picture of the arbitrary form on a canvas with the sizes *Y. We consider that coordinates of the left upper corner of a canvas 0,0. qwp> the Task: to Find the maximum sides of a rectangle with the given ratio of the sides k, completely being in a picture. qwp> [length of the horizontal side of a rectangle] / [length of the vertical side of a rectangle] =k. I.e. the canvas which has been painted over by white color is set. On it any figure is drawn by black color. It is necessary to find the maximum rectangle which can be inscribed in a black figure. Thus the relation of the sides of a rectangle equally k. There is a decision for O (N^3), where N - width/length of a canvas. It is necessary is better?

#### Re: The interesting and vital task with the useful result

Hello, samius, you wrote: S> I Suppose, it is a question what to display a certain object (picture) as much as possible "open" on the screen/in a window, without distortion of proportions. So.

#### Re: The interesting and vital task with the useful result

Hello, the Corkcrew, you wrote: I.e. the canvas which has been painted over by white color is set. No, the task all the same the vital. Color of a canvas can be any. For example, the blue sky. On it any figure is drawn by black color. Basically, it is possible to make separate function which will understand what the point concerns: to a canvas or to a picture. And then white/black approaches. But such function should work not worse a human eye. After all the person, looking at the arbitrary picture, can understand with a high probability, where a picture, and where a canvas. There is a decision for O (N^3), where N - width/length of a canvas. It is necessary is better? And why cubed?

#### Re: The interesting and vital task with the useful result

Hello, qwp, you wrote: S> I Suppose, it is a question what to display a certain object (picture) as much as possible "open" on the screen/in a window, without distortion of proportions.> so. Wdt, Hgt - the sizes of picture ClientWidth, ClientHeight - the sizes of window X0, Y0 - output coordinates in a window if ClientWidth * Hgt> = ClientHeight * Wdt then begin//a window wide, weeding on each side Y0: = 0; X0: = (ClientWidth - Wdt * ClientHeight div Hgt) div 2; end else begin//a window narrow, weeding on top and from below X0: = 0; Y0: = (ClientHeight - ClientWidth * Hgt div Wdt) div 2; end;