You have a rectangle and it is diagonal. How many squares will be crossed by the diagonal (I guess assuming the side length of the rectangle are nice whole numbers)
I've seen an implementation in Geogebra to shade in the squares that are crossed by the diagonal of a rectangle. I'd really be happy to see how to do this using Mathematica, it would help me learn a lot. But it's beyond me right now.
Here is my "start"....
Manipulate[ Module[{length, width},
length = Round[p[[1]]];
width = Round[p[[2]]];
Graphics[{
{GrayLevel[0.8],
Line /@ Table[{{i, 0}, {i, 20}}, {i, 0, 20}],
Line /@ Table[{{0, i}, {20, i}}, {i, 0, 20}]},
(*rectangle to mark off area*)
{Line[{{0, 0}, {Round[p[[1]]],
0} , Round[p], {0, Round[p[[2]]]}, {0, 0}}]},
(*point to control rectangle*)
{Blue, AbsolutePointSize[8],
Point[Round[p]]},
(*diagonal*)
Line[{{0, 0}, Round[p]}]
},
PlotRange -> {{-0.1, 20.1}, {-0.1, 20.1}},
ImageSize -> {800, 640}]],
{{p, {1, 1}}, {0, 0}, {20, 20}, Locator, Appearance -> None}
]

Any help would be appreciated.




