# Highlight Squares

davidcox shared this question 10 years ago

I would like to be able to highlight each of the squares on the coordinate grid that the diagonal passes through on the attached applet. Any help in doing so would be appreciated.

https://ggbm.at/551903

1

Hi,

In the annex one possible solution.

Question: for what you need it?

Raymond

Annex: GG40

supplement GG40

A more mathematical solution (but slow)

https://ggbm.at/551917

1

The applet is for a problem that I'm interested in.

Given a rectangle with dimensions n x m, how may squares will the diagonal pass through?

Thank you. That applet is exactly what I needed.

1

Here is another implementation of this problem (sure this is not the best way to do it) in order to highlight the squares.

I defined two sliders m and n.

In spreadsheet I define A2:A20 and B1:L1 with numbers from 1 to 19 (m and n values), and cell B2 with the first desired polygon (as list formed only with the polygon as unique element; if you don't do as a list you get more not desired cells in the spreadsheet containing vertex coordinates, and that is not desired in this situation):

'={Polygon[(\$A2, B\$1), (\$A2, B\$1) + (1, 0), (\$A2, B\$1) + (1, 1), (\$A2, B\$1) + (0, 1)]}'.

After that, I wrote for element stored in B2 the following dynamic color code: If[(y(Vertex[Element[B2, 1], 2]) / x(Vertex[Element[B2, 1], 2]) ≤ n / m) ∧ (n / m ≤ y(Vertex[Element[B2, 1], 4]) / x(Vertex[Element[B2, 1], 4])), 1, 0].

Then I copied cell B2 to range B2:L19 (this copies the cell definition and the dynamic color code too!!).

I'm sure this is not the best solution to the question you asked for, but one week ago I learned here about coping dynamic color code and scripting code from one cell to a big range of cells (was told to me by kondr in this forum) and I find this technic very usefull in many situations.

Cheers

https://ggbm.at/551915

1

hello

an old work for course in

la plaza

saludos

1

Hi,

Or..

If the tiles have a variable size.

Raymond

Annex GG40

https://ggbm.at/551925

1

@rami

You're amazing. Thanks. These applets will surely help with future constructions.

1

Very clever solution, Raymond. I took the liberty of tweaking your diagonal1 so that the rectangle can be moved to arbitrary position.

cheers,

JohnG

https://ggbm.at/551941