Visible Point

Author

Eric W. Weisstein
March 1, 2009

This notebook downloaded from http://mathworld.wolfram.com/notebooks/ComputationalGeometry/VisiblePoint.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/VisiblePoint.html.

©2009 Wolfram Research, Inc. except for portions noted otherwise

Code

VisibleQ[x_List]:=CoprimeQ@@x

GCDList[{x_,y_}]:=GCD[x,y]
GCDList[{x_,y_,z_}]:=GCD[x,y,z]

VisiblePoints[n_,opts_]:=Module[{x,y,pts={PointSize[.02]}},
  Do[
    If[VisibleQ[{x,y}],pts=Append[pts,Point[{x,y}]]],
    {x,-n,n},{y,-n,n}
  ];
  Show[Graphics[pts],opts,AspectRatio->Automatic]
]

VisiblePointsLines[n_,opts___]:=Module[{x,y,pts={PointSize[.02]}},
  Do[
    If[VisibleQ[{x,y}],pts=Append[pts,{Point[{x,y}],Line[{{0,0},{x,y}}]}]],
    {x,-n,n},{y,-n,n}
  ];
  Show[Graphics[pts],opts,AspectRatio->Automatic]
]

VisiblePoints3D[n_,opts___]:=Module[{x,y,z,pts={PointSize[.02]}},
  Do[
    If[VisibleQ[{x,y,z}],pts=Append[pts,Point[{x,y,z}]]],
    {x,-n,n},{y,-n,n},{z,-n,n}
  ];
  Show[Graphics3D[pts],opts,AspectRatio->Automatic]
]

VisiblePointsLines3D[n_,opts___]:=Module[{x,y,z,pts={PointSize[.02]}},
  Do[
    If[VisibleQ[{x,y,z}],
    	pts=Append[pts,{Point[{x,y,z}],Line[{{0,0,0},{x,y,z}}]}]],
    {x,-n,n},{y,-n,n},{z,-n,n}
  ];
  Show[Graphics3D[pts],opts,AspectRatio->Automatic]
]

Points from Origin

2-D

Show[GraphicsArray[
  {VisiblePoints[5,DisplayFunction->Identity],
  VisiblePointsLines[5,DisplayFunction->Identity]}],DisplayFunction->$DisplayFunction]

3-D

Show[GraphicsArray[
  {VisiblePoints3D[2,DisplayFunction->Identity],
  VisiblePointsLines3D[2,DisplayFunction->Identity]}],
  DisplayFunction->$DisplayFunction]

LiveGraphics3D`

<<Utilities`LiveGraphics3D`

WriteLiveForm["visible1.m", VisiblePoints3D[2]]

WriteLiveForm["visible2.m",VisiblePointsLines3D[2]]

Squares

Search

VisibleSquareQ[n_,x_]:=Module[{i,j},CoprimeQ@@@(Or@@Flatten[{Table[x+{i,j n},{i,0,n},{j,0,1}],Table[x+{i n,j},{i,0,1},{j,n-1}]},2])]

VisibleFilledSquareQ[n_,x_]:=Module[{i,j},CoprimeQ@@@(Or@@Flatten[Table[x+{i,j},{i,0,n},{j,0,n}],1])]

FirstInvisibleSquare[n_,f_:VisibleSquareQ]:=Module[{x=3,y=2,test=Function[{x,y},f[n,{x,y}]]},
Monitor[While[test[x,y],y++;If[y==x,y=2;x++]],{x,y}];
{x,y}
]

InvisibleSquares[n_,nmax_:1,f_:VisibleSquareQ]:=InvisibleSquares[n,nmax,{3,Infinity},f]/;!ListQ[f]
InvisibleSquares[n_,nmax_:1,{x0_,xmax_},f_:VisibleSquareQ]:=Module[{x=x0,y=2,test=Function[{x,y},f[n,{x,y}]],cnt=0,l={}},
Monitor[While[cnt<nmax&&x<xmax,
If[!test[x,y],AppendTo[l,{x,y}];cnt++];
y++;
If[y>=x,y=2;x++]
],
{x,y,cnt}];
l
]

1×1

FirstInvisibleSquare[1]//Timing

(l=InvisibleSquares[1,1000])//Timing

l1={{20,14},{35,14},{35,20},{54,44},{65,39},{69,45},{77,21},{84,34},{84,50},{95,75},{98,21},{98,77},{99,44},{99,54},{104,39},{104,65},{104,90},{110,74},{114,45},{114,69},{119,34},{119,84},{132,56},{132,76},{135,50},{135,84},{147,111},{153,33},{153,119},{159,105},{161,69},{170,75},{170,95},{170,152},{174,14},{174,20},{175,55},{185,74},{185,110},{186,33},{186,153},{188,140},{189,14},{189,35},{189,56},{189,132},{189,174},{195,20},{195,35},{195,90},{195,104},{195,174},{195,189},{200,134},{204,164},{209,76},{209,132},{215,129},{216,62},{221,51},{224,20},{224,35},{224,174},{224,189},{230,14},{230,35},{230,44},{230,54},{230,55},{230,69},{230,161},{230,174},{230,175},{230,195},{230,224},{231,87},{231,203},{234,140},{245,14},{245,20},{245,189},{245,195},{245,224},{245,230},{246,38},{249,165},{252,230},{258,111},{258,147},{260,116},{260,144},{264,105},{264,159},{265,105},{272,51},{272,119},{272,153},{272,221},{275,44},{275,99},{275,230},{279,62},{279,155},{279,216},{285,38},{285,39},{285,54},{285,65},{285,99},{285,209},{285,230},{285,246},{285,275},{290,194},{296,110},{299,207},{315,237},{318,87},{318,231},{323,152},{323,170},{324,39},{324,104},{324,285},{329,140},{329,188},{335,134},{335,200},{339,225},{340,154},{340,186},{344,129},{344,215},{350,65},{350,90},{350,104},{350,285},{350,324},{351,143},{354,284},{356,266},{363,21},{363,77},{363,143},{363,351},{365,219},{369,164},{369,204},{370,105},{370,265},{371,105},{374,50},{374,54},{374,84},{374,99},{374,230},{374,275},{375,140},{375,234},{377,116},{377,260},{380,254},{384,14},{384,20},{384,21},{384,44},{384,98},{384,99},{384,189},{384,195},{384,224},{384,230},{384,285},{384,363},{384,374},{390,68},{395,315},{399,14},{399,35},{399,75},{399,95},{399,174},{399,195},{399,224},{399,245},{399,384},{405,20},{405,35},{405,144},{405,174},{405,189},{405,230},{405,245},{405,260},{405,384},{405,399},{407,110},{407,296},{414,165},{414,249},{425,50},{425,135},{425,374},{426,182},{429,44},{429,54},{429,65},{429,104},{429,129},{429,275},{429,285},{429,324},{429,374},{429,384},{434,20},{434,35},{434,155},{434,174},{434,189},{434,203},{434,230},{434,231},{434,245},{434,279},{434,384},{434,399},{440,14},{440,35},{440,77},{440,98},{440,174},{440,195},{440,224},{440,245},{440,363},{440,384},{440,405},{440,434},{441,90},{441,119},{441,153},{441,195},{441,350},{450,164},{455,14},{455,20},{455,39},{455,104},{455,189},{455,195},{455,224},{455,230},{455,285},{455,350},{455,399},{455,405},{455,429},{455,434},{455,440},{455,441},{459,68},{459,84},{459,135},{459,374},{459,390},{459,425},{464,144},{464,260},{464,434},{469,335},{470,314},{473,429},{474,75},{474,170},{474,399},{475,399},{475,455},{476,105},{476,371},{483,77},{483,98},{483,230},{483,252},{483,363},{483,384},{485,194},{485,290},{494,39},{494,65},{494,95},{494,143},{494,170},{494,209},{494,285},{494,324},{494,350},{494,351},{494,399},{494,429},{494,455},{494,474},{495,154},{495,155},{495,279},{495,340},{495,341},{504,404},{506,143},{506,207},{506,299},{506,363},{506,494},{510,146},{510,364},{515,309},{517,329},{519,345},{524,392},{527,186},{527,340},{530,294},{531,413},{532,246},{532,286},{534,320},{539,21},{539,55},{539,98},{539,175},{539,363},{539,440},{539,483},{545,435},{549,305},{551,57},{552,237},{552,315},{558,129},{558,429},{560,21},{560,44},{560,54},{560,77},{560,84},{560,119},{560,135},{560,272},{560,275},{560,285},{560,374},{560,384},{560,425},{560,440},{560,441},{560,483},{560,539},{564,225},{564,339},{567,497},{574,160},{575,45},{575,69},{584,219},{584,364},{584,365},{594,14},{594,20},{594,50},{594,55},{594,135},{594,153},{594,189},{594,195},{594,224},{594,230},{594,272},{594,374},{594,399},{594,405},{594,434},{594,440},{594,441},{594,459},{594,539},{594,560},{602,468},{605,44},{605,99},{605,230},{605,285},{605,374},{605,429},{605,505},{605,560},{608,56},{608,57},{608,132},{608,551},{609,14},{609,35},{609,144},{609,174},{609,182},{609,195},{609,224},{609,245},{609,384},{609,405},{609,426},{609,434},{609,455},{609,464},{609,594},{610,234},{615,20},{615,35},{615,54},{615,99},{615,164},{615,174},{615,189},{615,230},{615,245},{615,275},{615,287},{615,384},{615,399},{615,429},{615,440},{615,450},{615,455},{615,560},{615,594},{615,605},{615,609},{620,45},{620,92},{620,114},{620,575},{623,266},{623,356},{635,254},{635,380},{636,104},{636,195},{636,350},{636,441},{637,77},{637,377},{639,284},{639,354},{644,20},{644,35},{644,69},{644,114},{644,174},{644,189},{644,230},{644,245},{644,300},{644,344},{644,384},{644,399},{644,440},{644,455},{644,575},{644,594},{644,609},{644,620},{645,50},{645,84},{645,85},{645,95},{645,170},{645,171},{645,399},{645,425},{645,459},{645,474},{645,560},{645,594},{648,176},{650,14},{650,35},{650,90},{650,154},{650,155},{650,174},{650,195},{650,224},{650,245},{650,350},{650,384},{650,402},{650,405},{650,434},{650,455},{650,495},{650,594},{650,615},{650,636},{650,644},{651,489},{654,524},{657,146},{657,510},{664,580},{665,14},{665,20},{665,56},{665,75},{665,170},{665,189},{665,195},{665,224},{665,230},{665,259},{665,399},{665,405},{665,434},{665,440},{665,494},{665,608},{665,609},{665,615},{665,644},{665,645},{665,650},{671,549},{675,39},{675,65},{675,324},{675,350},{675,429},{675,455},{684,410},{692,518},{695,555},{696,492},{699,465},{704,54},{704,99},{704,230},{704,275},{704,384},{704,429},{704,516},{704,560},{704,605},{710,315},{710,395},{713,92},{713,620},{714,39},{714,44},{714,77},{714,90},{714,99},{714,104},{714,175},{714,220},{714,230},{714,285},{714,350},{714,351},{714,363},{714,374},{714,429},{714,494},{714,506},{714,539},{714,560},{714,594},{714,615},{714,637},{714,675},{714,704},{720,308},{725,260},{725,319},{725,405},{725,464},{725,609},{730,85},{730,645},{731,645},{735,69},{735,114},{735,160},{735,161},{735,574},{735,575},{735,620},{740,65},{740,75},{740,95},{740,104},{740,285},{740,324},{740,455},{740,474},{740,480},{740,494},{740,645},{740,665},{740,675},{740,702},{740,714},{741,90},{741,104},{741,132},{741,189},{741,441},{741,455},{741,608},{741,636},{741,650},{741,665},{741,689},{747,165},{747,663},{749,321},{759,44},{759,45},{759,54},{759,114},{759,209},{759,275},{759,285},{759,374},{759,384},{759,437},{759,575},{759,605},{759,615},{759,644},{759,704},{759,714},{759,735},{767,117},{774,279},{774,434},{774,495},{774,650},{776,678},{779,246},{779,532},{780,142},{780,638},{782,492},{782,666},{783,203},{783,231},{784,314},{785,314},{785,470},{789,525},{792,182},{800,444},{803,219},{804,14},{804,20},{804,45},{804,69},{804,189},{804,195},{804,224},{804,230},{804,335},{804,399},{804,405},{804,434},{804,440},{804,469},{804,609},{804,615},{804,620},{804,644},{804,650},{804,735},{804,759},{805,90},{805,91},{805,154},{805,195},{805,299},{805,650},{805,713},{805,714},{815,489},{816,171},{816,645},{819,14},{819,35},{819,65},{819,104},{819,174},{819,195},{819,224},{819,245},{819,285},{819,286},{819,287},{819,324},{819,384},{819,405},{819,434},{819,455},{819,494},{819,532},{819,533},{819,594},{819,615},{819,644},{819,665},{819,675},{819,714},{819,804},{819,805},{824,308},{824,309},{824,515},{825,20},{825,21},{825,35},{825,77},{825,174},{825,175},{825,176},{825,189},{825,230},{825,245},{825,294},{825,384},{825,399},{825,440},{825,455},{825,483},{825,530},{825,539},{825,594},{825,609},{825,648},{825,649},{825,650},{825,665},{825,804},{825,819},{830,554},{832,272},{833,153},{833,272},{833,441},{833,560},{834,500},{836,341},{836,495},{836,588},{845,39},{845,104},{845,234},{845,285},{845,350},{845,429},{845,494},{845,610},{845,675},{845,740},{845,819},{846,21},{846,98},{846,329},{846,363},{846,440},{846,483},{846,517},{846,560},{846,825},{850,184},{854,20},{854,35},{854,132},{854,174},{854,189},{854,230},{854,245},{854,304},{854,305},{854,384},{854,399},{854,440},{854,455},{854,549},{854,594},{854,608},{854,609},{854,650},{854,665},{854,804},{854,819},{855,320},{855,534},{860,14},{860,35},{860,164},{860,174},{860,195},{860,204},{860,224},{860,245},{860,300},{860,384},{860,405},{860,434},{860,455},{860,594},{860,615},{860,644},{860,665},{860,804},{860,825},{860,854},{864,345},{864,519},{867,119},{867,272},{867,441},{867,527},{867,594},{867,833},{869,395},{874,160},{874,399},{874,475},{874,574},{874,854},{875,14},{875,20},{875,189},{875,195},{875,224},{875,230},{875,364},{875,399},{875,405},{875,434},{875,440},{875,510},{875,609},{875,615},{875,644},{875,650},{875,819},{875,825},{875,854},{875,860},{879,585},{884,39},{884,50},{884,65},{884,84},{884,117},{884,324},{884,350},{884,425},{884,429},{884,455},{884,459},{884,560},{884,594},{884,714},{884,740},{884,767},{884,819},{884,845},{890,44},{890,54},{890,275},{890,285},{890,374},{890,384},{890,605},{890,615},{890,704},{890,714},{896,90},{896,91},{896,104},{896,161},{896,230},{896,441},{896,455},{896,636},{896,650},{896,735},{896,804},{896,805},{899,434},{899,464},{900,424},{900,476},{902,77},{902,98},{902,287},{902,363},{902,384},{902,429},{902,473},{902,539},{902,560},{902,615},{902,825},{902,846},{902,860},{903,791},{909,404},{909,504},{909,707},{912,165},{912,747},{917,392},{917,524},{920,614},{923,142},{923,780},{924,74},{924,110},{924,259},{924,665},{930,56},{930,189},{930,455},{930,475},{930,588},{930,608},{930,741},{930,854},{930,874},{935,33},{935,44},{935,50},{935,65},{935,99},{935,135},{935,153},{935,220},{935,230},{935,285},{935,374},{935,429},{935,459},{935,560},{935,615},{935,645},{935,704},{935,714},{935,759},{935,884},{935,890},{942,368},{944,294},{944,413},{944,530},{944,531},{945,54},{945,55},{945,77},{945,98},{945,99},{945,129},{945,215},{945,230},{945,275},{945,300},{945,363},{945,384},{945,429},{945,539},{945,560},{945,605},{945,644},{945,714},{945,759},{945,825},{945,846},{945,890},{945,935},{948,584},{949,364},{949,584},{954,764},{959,273},{959,685},{962,428},{965,385},{965,579},{968,33},{968,186},{968,209},{968,494}};

Reverse[SortBy[{#[[1]],#[[2]]/#[[1]]//N}&/@Tally[Sort[l[[All,-1]]]],Last]]

Graphics[Point[l],Frame->True,FrameLabel->{x,y}]

pts=Flatten[Table[{x,y},{x,0,23},{y,0,x}],1];

v=GatherBy[pts,VisibleQ];

g1=Graphics[{{PointSize[.02],Red,Point[v[[1]]]},{Blue,PointSize[.015],Point[v[[2]]]}},Frame->True,Prolog->{Green,Rectangle[{20,14}]},FrameLabel->{x,y}]

2×2

FirstInvisibleSquare[2]//Timing

(l=InvisibleSquares[2,10])//Timing

(l=InvisibleSquares[2,100])//Timing

(l=InvisibleSquares[2,1000])//Timing

l2={{54,20},{174,98},{550,114},{574,368},{588,494},{608,474},{678,194},{740,258},{740,264},{790,224},{798,374},{804,740},{874,740},{944,648},{986,322},{986,376},{994,398},{1034,1000},{1064,1000},{1104,440},{1104,986},{1158,608},{1208,754},{1274,1000},{1308,544},{1308,644},{1308,1034},{1308,1274},{1406,406},{1420,1274},{1462,152},{1462,644},{1462,1274},{1494,50},{1494,1220},{1550,484},{1580,34},{1580,804},{1610,714},{1624,440},{1638,594},{1650,1014},{1664,220},{1664,1000},{1664,1182},{1694,370},{1700,390},{1700,574},{1728,518},{1728,644},{1728,1064},{1728,1664},{1736,384},{1748,1494},{1804,1748},{1898,844},{1910,1194},{1924,110},{1924,350},{1924,740},{1970,144},{1988,34},{1988,804},{1988,1392},{1988,1924},{2000,874},{2000,1624},{2000,1854},{2000,1884},{2014,370},{2022,68},{2044,818},{2108,1444},{2108,2014},{2114,160},{2134,98},{2148,614},{2154,860},{2210,174},{2210,636},{2210,1342},{2210,2022},{2210,2134},{2240,664},{2254,20},{2254,328},{2254,1310},{2254,2000},{2260,644},{2260,2014},{2278,1376},{2288,54},{2288,1104},{2288,1624},{2288,2254},{2294,258},{2294,1270},{2294,1518},{2330,54},{2330,264},{2330,1924},{2330,2254},{2352,362},{2354,340},{2354,2298},{2364,20},{2364,350},{2364,2288},{2364,2330},{2378,286},{2378,492},{2406,1160},{2408,174},{2408,2134},{2420,538},{2464,230},{2464,440},{2464,1088},{2478,2144},{2484,98},{2484,2210},{2484,2408},{2540,154},{2540,2254},{2584,968},{2596,530},{2618,2134},{2624,532},{2666,1246},{2678,2014},{2684,1308},{2694,1010},{2700,146},{2714,160},{2714,1448},{2714,2230},{2716,440},{2716,1406},{2750,2364},{2754,38},{2754,1748},{2754,2378},{2754,2430},{2794,1220},{2794,2408},{2820,2294},{2820,2702},{2828,504},{2828,874},{2890,2714},{2924,832},{2924,1308},{2924,2260},{2924,2364},{2928,404},{3006,1550},{3008,234},{3008,2584},{3014,318},{3014,1000},{3014,1780},{3024,968},{3050,2484},{3058,1748},{3068,1474},{3068,1494},{3068,2664},{3068,2794},{3080,804},{3080,1264},{3080,2210},{3080,2782},{3094,1238},{3114,740},{3114,2828},{3128,574},{3128,594},{3128,1104},{3128,2464},{3144,1088},{3144,1598},{3144,2738},{3170,1104},{3170,1524},{3170,1624},{3178,440},{3178,680},{3184,1790},{3204,1280},{3248,874},{3248,3114},{3266,3058},{3288,44},{3288,440},{3288,1274},{3288,3014},{3296,1750},{3310,1034},{3310,1274},{3310,2924},{3340,2054},{3344,1000},{3344,1308},{3344,1728},{3344,2260},{3344,2628},{3344,3310},{3378,434},{3380,474},{3380,2716},{3380,2944},{3404,3288},{3408,1946},{3470,804},{3470,1924},{3476,2584},{3478,140},{3484,1598},{3484,2378},{3484,2820},{3514,608},{3514,1700},{3514,2050},{3514,3380},{3534,740},{3534,1580},{3534,1988},{3534,3470},{3584,1000},{3584,1308},{3584,3310},{3596,216},{3604,1580},{3604,1988},{3618,374},{3618,1034},{3618,1274},{3618,3344},{3618,3584},{3624,230},{3684,968},{3684,2618},{3728,1164},{3730,1064},{3730,1118},{3730,1664},{3730,2624},{3772,1034},{3794,90},{3794,636},{3794,1000},{3794,1728},{3794,3730},{3806,186},{3834,440},{3834,2288},{3834,3170},{3838,2792},{3874,3470},{3904,1890},{3912,3248},{3914,1690},{3914,2298},{3936,2540},{3938,1924},{3938,2364},{3954,1160},{3954,2000},{3954,2828},{3968,154},{3970,2354},{3970,3914},{4010,1104},{4010,2464},{4010,3834},{4028,474},{4046,76},{4046,2430},{4080,350},{4080,2014},{4088,1504},{4088,1854},{4144,1658},{4146,1274},{4214,730},{4214,1308},{4214,1518},{4214,2260},{4234,2000},{4234,2408},{4234,4088},{4254,1700},{4254,3128},{4254,3818},{4292,2754},{4300,44},{4300,644},{4300,2684},{4300,2924},{4328,2704},{4334,2980},{4344,158},{4344,3320},{4354,440},{4354,1070},{4354,2288},{4354,3170},{4354,3618},{4354,4080},{4394,1000},{4394,1728},{4394,3730},{4444,98},{4444,1918},{4444,2210},{4444,2408},{4458,1064},{4458,1664},{4458,3794},{4458,4394},{4464,188},{4464,340},{4464,608},{4464,1220},{4464,1748},{4464,3380},{4464,4123},{4470,1052},{4520,174},{4520,1804},{4520,2134},{4520,2464},{4520,2484},{4520,3144},{4520,4444},{4520,4464},{4540,3344},{4542,4046},{4564,20},{4564,2288},{4564,2330},{4598,54},{4598,474},{4598,2254},{4598,2364},{4598,3288},{4598,3514},{4598,3794},{4598,4234},{4598,4464},{4598,4564},{4632,902},{4634,1728},{4634,2260},{4634,2988},{4640,54},{4640,1054},{4640,1924},{4640,2254},{4640,2364},{4640,2584},{4640,3024},{4640,3794},{4640,4146},{4640,4564},{4654,38},{4654,740},{4654,1442},{4654,1988},{4654,3470},{4668,1274},{4668,2114},{4668,2714},{4674,20},{4674,440},{4674,2288},{4674,2330},{4674,3058},{4674,3128},{4674,4010},{4674,4598},{4674,4640},{4718,174},{4718,804},{4718,1924},{4718,2134},{4718,2484},{4718,3534},{4718,4444},{4718,4654},{4730,76},{4730,664},{4730,874},{4730,2014},{4730,2430},{4730,3114},{4730,3912},{4794,98},{4794,2210},{4794,2408},{4794,3178},{4794,4520},{4794,4718},{4814,580},{4814,1420},{4814,4066},{4814,4668},{4818,2684},{4864,740},{4864,3248},{4864,4730},{4878,644},{4878,1064},{4878,2378},{4878,2924},{4878,4214},{4886,3618},{4898,2944},{4900,986},{4900,1274},{4900,3913},{4928,804},{4928,2914},{4928,3604},{4928,4344},{4928,4402},{4940,244},{4958,3684},{4958,4254},{4964,220},{4964,948},{4982,2596},{4990,1104},{4990,2114},{4990,2294},{4990,2714},{4990,4214},{5014,68},{5018,1104},{5018,1624},{5018,3262},{5018,3834},{5018,4354},{5024,1098},{5026,1826},{5030,84},{5030,3144},{5030,3484},{5074,530},{5074,1160},{5088,1454},{5120,2274},{5124,2540},{5134,50},{5134,3170},{5136,1868},{5150,34},{5150,1494},{5150,3534},{5150,3604},{5150,4444},{5194,2078},{5200,1484},{5220,3632},{5224,1958},{5238,494},{5290,1034},{5290,1274},{5290,2275},{5290,3014},{5290,3404},{5290,4444},{5300,494},{5300,2584},{5300,2914},{5300,3684},{5304,2120},{5320,3128},{5334,2000},{5334,3058},{5368,2210},{5368,3794},{5368,4718},{5368,4940},{5394,2678},{5394,3818},{5394,4730},{5404,188},{5404,1700},{5404,3128},{5408,2404},{5450,1884},{5450,3160},{5474,258},{5474,850},{5494,2210},{5494,2828},{5494,5024},{5510,1494},{5510,2794},{5510,3210},{5558,34},{5558,3534},{5558,3604},{5558,4794},{5564,1000},{5564,2716},{5564,3288},{5564,4718},{5564,5290},{5588,2254},{5588,5290},{5588,5334},{5620,1034},{5620,1274},{5620,3344},{5620,3584},{5620,3794},{5624,550},{5624,3588},{5642,220},{5642,1078},{5642,2022},{5642,2430},{5642,4066},{5642,5394},{5654,230},{5654,1000},{5654,1308},{5654,1798},{5654,1924},{5654,3310},{5654,3618},{5654,4080},{5654,4234},{5654,5620},{5660,474},{5680,644},{5680,1064},{5680,3404},{5680,5564},{5704,650},{5704,1580},{5704,2000},{5704,2828},{5704,4928},{5718,644},{5718,1442},{5718,1748},{5718,2924},{5718,3344},{5718,4634},{5780,1504},{5780,3114},{5780,5494},{5784,1220},{5784,2650},{5784,3068},{5784,5510},{5796,2924},{5796,3782},{5796,5082},{5828,3750},{5828,4464},{5830,644},{5830,2210},{5830,2924},{5830,4214},{5830,4928},{5830,5642},{5840,1494},{5840,4444},{5844,110},{5858,2464},{5858,3624},{5874,1598},{5888,804},{5894,468},{5894,1000},{5894,1308},{5894,3310},{5894,3618},{5894,4630},{5894,5620},{5900,1104},{5900,1624},{5900,3834},{5900,4354},{5908,4976},{5928,1034},{5928,1274},{5928,1804},{5928,3344},{5928,3584},{5928,4354},{5928,5654},{5928,5894},{5984,1240},{5984,2254},{5984,2408},{5984,4878},{5984,4960},{5984,5620},{6026,1440},{6026,3288},{6034,440},{6034,3128},{6034,4010},{6060,174},{6060,986},{6060,1406},{6060,4444},{6060,4640},{6068,2254},{6068,3514},{6068,4254},{6068,4624},{6070,934},{6094,1748},{6094,5510},{6094,5840},{6104,2484},{6104,3310},{6104,3478},{6104,5718},{6110,4774},{6118,4640},{6136,2924},{6140,184},{6148,86},{6148,5564},{6174,1350},{6200,104},{6200,804},{6200,1924},{6200,3534},{6200,3604},{6200,4654},{6204,4088},{6214,350},{6214,3938},{6214,4640},{6214,5368},{6224,4278},{6230,132},{6230,2664},{6230,3484},{6244,2498},{6250,644},{6250,1034},{6250,3344},{6250,4634},{6254,1218},{6264,740},{6264,1988},{6264,3470},{6264,3938},{6264,4718},{6264,6200},{6278,364},{6278,2364},{6288,4634},{6292,2378},{6292,3596},{6292,6200},{6302,4530},{6306,5642},{6312,3422},{6318,710},{6320,2464},{6320,3624},{6320,5074},{6344,1158},{6344,1728},{6344,2170},{6344,5680},{6354,680},{6354,2540},{6354,3968},{6354,6068},{6356,832},{6356,1924},{6356,4080},{6364,5660},{6390,1274},{6390,3806},{6398,5844},{6408,1274},{6408,1664},{6408,4964},{6446,2716},{6446,3288},{6446,3750},{6446,3808},{6460,284},{6460,1064},{6460,1664},{6460,2702},{6460,3248},{6460,3794},{6460,4394},{6460,5252},{6460,6104},{6464,6160},{6478,4028},{6494,1308},{6494,2260},{6494,4878},{6494,5538},{6494,5830},{6494,6408},{6524,636},{6524,1000},{6524,1728},{6524,3730},{6524,4458},{6524,6460},{6530,574},{6530,4254},{6530,5404},{6530,6034},{6544,3680},{6554,318},{6558,1874},{6564,200},{6564,440},{6564,2288},{6564,3170},{6564,5018},{6564,5858},{6564,5900},{6572,5362},{6578,1374},{6578,1462},{6578,1494},{6578,2584},{6578,2664},{6578,2820},{6578,3024},{6578,5134},{6578,6390},{6578,6460},{6642,2210},{6642,3794},{6654,350},{6654,3938},{6654,4640},{6664,2540},{6664,2750},{6664,3968},{6664,6278},{6670,1904},{6680,1494},{6680,5134},{6698,984},{6698,1104},{6698,1274},{6698,2464},{6698,3144},{6698,4674},{6698,6034},{6698,6204},{6714,68},{6714,1970},{6714,4898},{6754,98},{6754,2210},{6754,2408},{6754,4520},{6754,4718},{6756,464},{6764,968},{6764,2260},{6784,1748},{6798,4184},{6816,4010},{6830,174},{6830,874},{6830,2134},{6830,2484},{6830,3954},{6830,4444},{6830,4794},{6830,5704},{6830,6754},{6844,4958},{6850,494},{6850,1664},{6850,4964},{6852,1034},{6874,20},{6874,2288},{6874,2330},{6874,4598},{6874,4640},{6894,3878},{6908,54},{6908,784},{6908,2254},{6908,2364},{6908,2914},{6908,4564},{6908,4674},{6908,6874},{6918,1034},{6918,2684},{6918,2924},{6918,5474},{6944,160},{6944,3702},{6944,4668},{6944,4990},{6950,54},{6950,2254},{6950,2364},{6950,4564},{6950,4674},{6950,6874},{6954,1220},{6954,2678},{6954,4920},{6968,1884},{6984,20},{6984,2288},{6984,2330},{6984,4598},{6984,4640},{6984,6908},{6984,6950},{6992,740},{6992,2716},{6992,3288},{6992,5110},{6992,6186},{7004,6850},{7006,2882},{7006,5486},{7028,174},{7028,2134},{7028,2484},{7028,3058},{7028,4402},{7028,4444},{7028,4794},{7028,5718},{7028,6754},{7074,1130},{7084,440},{7084,1220},{7084,1742},{7084,2000},{7084,2288},{7084,3068},{7084,3170},{7084,5018},{7084,5510},{7084,5900},{7084,6320},{7084,6968},{7104,56},{7104,98},{7104,230},{7104,740},{7104,1274},{7104,1580},{7104,1988},{7104,2210},{7104,2408},{7104,3248},{7104,3596},{7104,4520},{7104,4718},{7104,4730},{7104,5150},{7104,5290},{7104,5558},{7104,6830},{7104,7028},{7124,1000},{7124,1728},{7124,3730},{7124,3912},{7124,4458},{7124,6460},{7168,1070},{7174,390},{7174,1580},{7174,1988},{7174,5082},{7174,5150},{7174,5558},{7174,6068},{7188,1064},{7188,1664},{7188,2156},{7188,3794},{7188,4394},{7188,5054},{7188,6524},{7188,7124},{7190,5734},{7190,6664},{7190,7104},{7208,5694},{7220,114},{7238,874},{7238,1014},{7238,2584},{7238,3114},{7238,3684},{7238,4864},{7238,7104},{7258,1462},{7258,5642},{7294,2918},{7302,1742},{7304,1000},{7304,3288},{7304,5290},{7314,530},{7314,1580},{7314,2882},{7314,4928},{7314,5300},{7314,6230},{7328,5724},{7334,1728},{7334,2260},{7334,5718},{7334,6250},{7336,230},{7336,4598},{7336,4640},{7336,6026},{7358,1494},{7358,2794},{7358,5784},{7358,7084},{7364,888},{7364,1420},{7364,4668},{7370,208},{7370,474},{7370,1066},{7370,1272},{7370,2716},{7370,2754},{7370,3514},{7370,4464},{7370,4654},{7370,6060},{7370,6498},{7370,7124},{7384,740},{7384,1988},{7384,3470},{7384,4640},{7384,4718},{7384,6200},{7384,7028},{7398,6944},{7404,2960},{7412,3178},{7412,4674},{7424,1362},{7424,2290},{7428,644},{7428,2924},{7428,6764},{7448,804},{7448,1924},{7448,2754},{7448,3534},{7448,4654},{7448,6264},{7448,7384},{7474,1220},{7474,4920},{7474,5150},{7474,6968},{7474,6992},{7502,3772},{7504,608},{7504,2210},{7504,3380},{7504,4598},{7504,6230},{7504,6950},{7504,7370},{7510,1274},{7510,2294},{7510,4814},{7510,5474},{7510,5624},{7510,7364},{7512,1364},{7524,4928},{7524,6200},{7524,7028},{7544,160}};

GraphicsGrid[{{
Graphics[{Red,AbsolutePointSize[1.5],Point[l1]},Frame->True,FrameLabel->{x,y},PlotLabel->n==1],
Graphics[{Red,AbsolutePointSize[1.5],Point[l2]},Frame->True,FrameLabel->{x,y},PlotLabel->n==2]
}},ImageSize->400]

pts=Flatten[Table[{x,y},{x,0,60},{y,0,x}],1];

v=GatherBy[pts,VisibleQ];

g2=Graphics[{{Red,PointSize[.025],Point[v[[1]]]},{Blue,PointSize[.015],Point[v[[2]]]}},Frame->True,Prolog->{Green,Rectangle[{54,20},{56,22}]},FrameLabel->{x,y},PlotRange->{{50,60},{15,25}},PlotRangeClipping->True]

Combined

GraphicsGrid[{{g1,g2}},ImageSize->400]

2×2 filled 1308

FirstInvisibleSquare[2,VisibleFilledSquareQ]//Timing

pts=Flatten[Table[{x,y},{x,1300,1315},{y,1270,1280}],1];

ByteCount[pts]

v=GatherBy[pts,VisibleQ];

Graphics[{Red,AbsolutePointSize[2],Point[v[[1]]],AbsolutePointSize[3],Blue,Point[v[[2]]]},Frame->True,Prolog->{Green,Rectangle[{1308,1274},{1310,1276}]},FrameLabel->{x,y},PlotRange->{{1304,1313}+1/2,{1270,1279}+1/2},PlotRangeClipping->True,ImageSize->250]

2×2 filled (small x value measured from the y-axis)

pts=Flatten[Table[{x,y},{x,6175,6225},{y,75,125}],1];

ByteCount[pts]

v=GatherBy[pts,VisibleQ];

CoprimeQ@@@{{104,6200},{105,6200}}

g2=Graphics[{Red,AbsolutePointSize[2],Point[v[[1]]],AbsolutePointSize[3],Blue,Point[v[[2]]]},Frame->True,Prolog->{Green,Rectangle[{6200,104},{6202,106}]},FrameLabel->{x,y},PlotRange->{{6190,6210},{94,114}},PlotRangeClipping->True]

3x3

FirstInvisibleSquare[3]//Timing

{xx,yy}={42273,35397};

pts=Flatten[Table[{x,y},{x,xx-10,xx+10},{y,yy-10,yy+10}],1];

v=GatherBy[pts,VisibleQ];

Graphics[{Red,AbsolutePointSize[2],Point[v[[2]]],AbsolutePointSize[3],Blue,Point[v[[1]]]},Frame->True,Prolog->{Green,Rectangle[{xx,yy},{xx+3,yy+3}]},FrameLabel->{x,y},PlotRange->{{xx-10,xx+10},{yy-10,yy+10}},PlotRangeClipping->True]