Total circles area: Difference between revisions

→‎optimized: optimized for faster grid calculations.
m (→‎optimized: changed a comment.)
(→‎optimized: optimized for faster grid calculations.)
Line 2,582:
verbose= box<0; box= abs(box); boxen= box+1 /*set a flag if we're in verbose mode. */
numeric digits dig /*have enough decimal digits for points*/
 
/* ══════x══════ ══════y══════ ═══radius═══ ══════x══════ ══════y══════ ═══radius═══*/
$=' 1.6417233788 1.6121789534 0.0848270516 -1.4944608174 1.2077959613 1.1039549836',
Line 2,602 ⟶ 2,601:
parse var $ minX minY . 1 maxX maxY . /*assign minimum & maximum values.*/
 
do j=1 for circles; _= j * 3 - 2 2 /*assign some circles with datum. */
@x.j= word($, _); @y.j=word($, _ + 1)
@r.j=word($, _ + 2) / 1; @rr.j= @r.j **2
Line 2,617 ⟶ 2,616:
 
dx= (maxX-minX) / box; dy= (maxY-minY) / box /*compute the DX and DY values*/
do z=0 for boxen; rowDY.z= z*dy; colDX.z= z*dx
end /*z*/
w= length(circles) /*W: used for aligning output. */
#in= 0 /*#in ◄───fully contained circles.*/
Line 2,630 ⟶ 2,631:
if #in==0 then #in= 'no' /*use gooder English. (humor). */
if verbose then do; say; say #in " circles are fully contained within other circles.";end
nC=0 0 /*number of "new" circles. */
do n=1 for circles; if @r.n==0 then iterate /*skip circles 0with zero radii. */
nC= nC + 1; @x.nC= @x.n; @y.nC= @y.n; @r.nC= @r.n; @rr.nC= @r.n**2
end /*n*/ /* [↑] elide overlapping circles.*/
#=0 0 /*count of sample points (so far).*/
do row=0 for boxen; y= minY + rowDY.row*dy /*process each of the grid row. */
do col=0 for boxen; x= minX + colDX.col*dx /* " " " " " column.*/
do k=1 for nC /*now process each new circle. */
if (x - @x.k)**2 + (y - @y.k)**2 <= @rr.k then do; #= # + 1; leave; end
end /*k*/
end /*col*/
end /*row*/
say /*stick a fork in it, we're done. */
say 'Using ' box " boxes (which have " box**2 ' points) and ' dig " decimal digits,"
say 'the approximate area is: ' # * dx * dy</lang>
{{out|output|text=&nbsp; when using various number of boxes:}}