Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Math problem
#9
(05-04-2023, 11:45 AM)Ofnuts Wrote:
(05-04-2023, 11:05 AM)rich2005 Wrote:
(05-04-2023, 10:51 AM)Ofnuts Wrote: The number of complete celles is the integer division of the window width, minus the offset, by a "cell". Then you have to figure out what it on the left and what is on the right (wich depends on offset and space).

Well, that is what I did, except took the case where the offset = zero. Are you saying that is not equal to the general case as well ?

No because you have edge cases (literally and figuratively) where a good part of the grid is outside the window, which increases the size of the visible spaces. For instance, for a 5+2 pattern and a width of 23:
Code:
offset  0, total  17 ([5, 5, 5, 2])
offset  1, total  16 ([5, 5, 5, 1])
offset  2, total  15 ([5, 5, 5])     # 4 full lines showing
offset  3, total  16 ([1, 5, 5, 5])
offset  4, total  17 ([2, 5, 5, 5])
offset  5, total  17 ([3, 5, 5, 4])
offset  6, total  17 ([4, 5, 5, 3])

And this is a very practical problem, I need this to know in advance the size of a layer where I keep only the spaces.

@rich2005 - consider the case where the window is the width of two lines plus the enclosed space. When the window starts at the left of the left-hand line and ends at the right of the right-hand one it will contain just one column of spaces. Now slide the window to the right by the width of a line and it will include the one complete column of spaces plus another part of a column of spaces that is the width of a line.

@Ofnuts
I think that the following (untested/uncompiled) code might give the desired result (note that I coded it without the PC on and my offset is from a different point to that used in the diagrams above - short-term memory loss? :-) but the principal is the same):

Code:
gint window_width = ?;
gint line_width = ?;
gint space_width = ?;
gint offset = ?;     /* offset of left of window from the LHS of the preceding line (or where the line
                       would be if it is off the left-hand side of the image) */
gint num_repeats;
gint repeat_width = line_width + space_width;
gint window_spaces;
gint window_samples_to_process = window_width;

if (offset <= line_width)
 window_paces = space_width;
else
 window_spaces = space_width - (repeat_width - offset);

window_samples_to_process -= repeat_width - offset;

num_repeats = window_samples_to_process / repeat_width;

window_spaces += space_width * num_repeats;

window_samples_to_process -= repeat_width * num_repeats;

if (window_samples_to_process > line_width)
 window_spaces += window_samples_to_process - line_width;

The code makes the following assumptions:

1. That the window is >= 1 line/space repeat width
2. The window is completely over the patterned area (not off the left or right-hand side of the image)
3. The offset is always positive
4. The offset is less than one line/space repeat

Of course if the window width is always an integer multiple of the line/space width the calculation becomes much easier:

window_spaces = (window_width / (line_width + space_width)) * space_width

regardless of the position of the window.
Reply


Messages In This Thread
Math problem - by Ofnuts - 05-02-2023, 08:45 AM
RE: Math problem - by PixLab - 05-03-2023, 08:47 AM
RE: Math problem - by rich2005 - 05-03-2023, 10:17 AM
RE: Math problem - by Ofnuts - 05-04-2023, 10:51 AM
RE: Math problem - by rich2005 - 05-04-2023, 11:05 AM
RE: Math problem - by Ofnuts - 05-04-2023, 11:45 AM
RE: Math problem - by programmer_ceds - 05-04-2023, 05:33 PM
RE: Math problem - by rich2005 - 05-04-2023, 12:27 PM
RE: Math problem - by Ofnuts - 05-04-2023, 12:58 PM
RE: Math problem - by Ottia Tuota - 05-04-2023, 05:34 PM
RE: Math problem - by Ofnuts - 05-05-2023, 04:50 PM
RE: Math problem - by Ottia Tuota - 05-05-2023, 07:12 PM
RE: Math problem - by Ofnuts - 05-05-2023, 08:04 PM
RE: Math problem - by programmer_ceds - 05-05-2023, 09:53 PM
RE: Math problem - by Ofnuts - 05-05-2023, 10:54 PM
RE: Math problem - by Ottia Tuota - 05-06-2023, 08:23 AM
RE: Math problem - by programmer_ceds - 05-06-2023, 10:22 AM
RE: Math problem - by Ottia Tuota - 05-06-2023, 07:52 PM
RE: Math problem - by Ofnuts - 05-06-2023, 09:05 PM

Forum Jump: