• Squares under a curve.

    From Malcolm McLean@21:1/5 to All on Tue Sep 14 06:30:24 2021
    I've got a long thin image which consists of a frieze of identical square cells. I've also got a wall of varying height, described by a complex function. I want to distort the image so as to retain the aspect ratio of the cells, whist stretching it to
    the height of the wall.
    Sometime the function might go to zero or close to zero, so there also needs to be a cut off point to avoid a large accumulation of very small cells.

    My current attempt is to take a lot of wall height samples. Then I start at the left of the wall, and sum the samples, marking off squares when the sum goes lower than delta x squared.. (There's quite a bit of complication because of linear interpolation
    of the last sample in the square).

    The problem with this is that you obtain a "remainder" at the end of this process. So the rightmost cell is incorrect. The height maxima are are
    quite likely to be at the wall endpoints, so this is the worst place to have an artifact.

    Is there another approach?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Julio Di Egidio@21:1/5 to Malcolm McLean on Tue Sep 14 08:47:18 2021
    On Tuesday, 14 September 2021 at 15:30:26 UTC+2, Malcolm McLean wrote:

    I've got a long thin image which consists of a frieze of identical square cells.

    So, if I get you right, your image is rectangular with dimensions -say- WxH (e.g. W could be 1024 and H would be 64, for 16 squares in total).

    I've also got a wall of varying height, described by a complex function.

    Which I read that your wall has horizontal base and vertical sides, just the top is curvilinear and describe by some function h(x) for x ranging over the base of the wall.

    Correct that far?

    I want to distort the image so as to retain the aspect ratio of the cells, whist stretching it to the height of the wall.

    Here you should be specific: "distorted" how exactly? In the scenario depicted above, just the upper side of the squares (and of the whole image) must become curvilinear, the other sides have to remain straight, so there is no way to actually preserve
    the aspect ratio. And, in that scenario, a simple approach would to enlarge and deform the whole image in order to make it match the wall shape, i.e. disregarding the single squares and just stretching in height along the image in order to match the
    height of the wall at every point... So, what do you really have in mind?

    Sometime the function might go to zero or close to zero, so there also needs to be a cut off point to avoid a large accumulation of very small cells.

    My current attempt is to take a lot of wall height samples.
    <snip>

    There should be some closed form solution, no need for brute force or similar, but you'll have to clarify your "geometric" requirements above.

    Julio

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Julio Di Egidio@21:1/5 to Julio Di Egidio on Tue Sep 14 08:54:28 2021
    On Tuesday, 14 September 2021 at 17:47:20 UTC+2, Julio Di Egidio wrote:

    your image is rectangular with dimensions -say- WxH (e.g. W could be 1024 and H would be 64, for 16 squares in total)

    I've eaten a piece of text there, should read:

    ...your image is rectangular with dimensions -say- WxH, whence the single squares would have dimensions HxH (as the height of the squares must match the height of the whole image: e.g. W could be 1024 and H could be 64, for 16 squares in total)...

    Julio

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Julio Di Egidio@21:1/5 to Julio Di Egidio on Tue Sep 14 08:57:32 2021
    On Tuesday, 14 September 2021 at 17:47:20 UTC+2, Julio Di Egidio wrote:
    On Tuesday, 14 September 2021 at 15:30:26 UTC+2, Malcolm McLean wrote:

    I've got a long thin image which consists of a frieze of identical square cells.
    So, if I get you right, your image is rectangular with dimensions -say- WxH (e.g. W could be 1024 and H would be 64, for 16 squares in total).
    I've also got a wall of varying height, described by a complex function.
    Which I read that your wall has horizontal base and vertical sides, just the top is curvilinear and describe by some function h(x) for x ranging over the base of the wall.

    Correct that far?
    I want to distort the image so as to retain the aspect ratio of the cells, whist stretching it to the height of the wall.
    Here you should be specific: "distorted" how exactly? In the scenario depicted above, just the upper side of the squares (and of the whole image) must become curvilinear, the other sides have to remain straight, so there is no way to actually preserve
    the aspect ratio. And, in that scenario, a simple approach would to enlarge and deform the whole image in order to make it match the wall shape, i.e. disregarding the single squares and just stretching in height along the image in order to match the
    height of the wall at every point... So, what do you really have in mind?

    Moreover, concretely, there is no such thing as an image that is not rectangular, so it's really not clear (to me at least) what you are trying to do.

    Julio

    Sometime the function might go to zero or close to zero, so there also needs to be a cut off point to avoid a large accumulation of very small cells.

    My current attempt is to take a lot of wall height samples.
    <snip>

    There should be some closed form solution, no need for brute force or similar, but you'll have to clarify your "geometric" requirements above.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Malcolm McLean@21:1/5 to ju...@diegidio.name on Tue Sep 14 10:56:05 2021
    On Tuesday, 14 September 2021 at 16:47:20 UTC+1, ju...@diegidio.name wrote:
    On Tuesday, 14 September 2021 at 15:30:26 UTC+2, Malcolm McLean wrote:

    I've got a long thin image which consists of a frieze of identical square cells.
    So, if I get you right, your image is rectangular with dimensions -say- WxH (e.g. W could be 1024 and H would be 64, for 16 squares in total).

    The image is a frieze, made by placing cells side by side. I can add as many cells as I want (within reason) to make the image
    as long as I want.

    I've also got a wall of varying height, described by a complex function.
    Which I read that your wall has horizontal base and vertical sides, just the top is curvilinear and describe by some function h(x) for x ranging over the base of the wall.

    Correct that far?

    That's right. The sides are vertical (or zero), the base is horizontal, and the top is curvilinear. The base is also expected to be quite a bit longer
    than the maximum height.

    I want to distort the image so as to retain the aspect ratio of the cells, whist stretching it to the height of the wall.
    Here you should be specific: "distorted" how exactly? In the scenario depicted above, just the upper side of the squares (and of the whole image) must become curvilinear, the other sides have to remain straight, so there is no way to actually preserve
    the aspect ratio. And, in that scenario, a simple approach would to enlarge and deform the whole image in order to make it match the wall shape, i.e. disregarding the single squares and just stretching in height along the image in order to match the
    height of the wall at every point... So, what do you really have in mind?

    Say the "curve" wall is 32 pixels high for 512 pixels, then jumps to 64 pixels for the remaining 512 pixels. (This is allowed but it
    wouldn't be typical, normally the wall top is a smooth curve).
    Now the problem is easy to solve. The base cell is 64x64, so scale it by 0.5 for 16 32x32 squares, then scale by 1.0 for 8 64x64 squares.
    None of the image is distorted, all the cells are to scale.

    However we seldom have that easy situation. Another relatively easy situation would be a wall which is a straight slope, from 0 pixels
    at the left to 64 pixels at the right. So we fit a minimum 1x1 at the extreme left (no point trying to work out sub-pixel geometry as
    the end user can't see it). Then we fit a series of gradually increasing cells. Instead of being square, they are quads with two right angles.
    Strictly the geometry has to be distorted internally both in the y direction and in the x direction to fit that quad. Maybe I can get away
    without distorting in the x direction.

    Sometime the function might go to zero or close to zero, so there also needs to be a cut off point to avoid a large accumulation of very small cells.

    My current attempt is to take a lot of wall height samples.
    <snip>

    There should be some closed form solution, no need for brute force or similar, but you'll have to clarify your "geometric" requirements above.

    The objective is to produce something visually acceptable, not geometrically perfect. So an approximate solution might be good enough.
    It's also got quite severe runtime constraints, though it will be running on the new M1 chip from Apple which is a very good number
    cruncher.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)