Anonymous user
Total circles area: Difference between revisions
m
→optimized: added/changed comments and whitespace, used a template for the output section.
m (→using all circles: added/changed comments and whitespace, used a template for the output section.) |
m (→optimized: added/changed comments and whitespace, used a template for the output section.) |
||
Line 2,451:
===optimized===
This REXX version elides any circle that is completely contained in another circle.
<br>this reduces the computation time (for overlapping circles) by around 25%.
This version also has additional information displayed.
Line 2,460 ⟶ 2,462:
if box=='' | box==',' then box= -500 /*Not specified? Then use the default.*/
if dig=='' | dig==',' then dig= 12 /* " " " " " " */
verbose= box<0;
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,476 ⟶ 2,479:
' 1.4685857879 -0.8347049536 1.3670667538 -0.6855727502 1.6465021616 1.0593087096',
' 0.0152957411 0.0638919221 0.9771215985 ' /*define circles with X, Y, and R.*/
circles= words($) % 3
if verbose then say 'There are' circles "circles." /*display the number of circles. */
parse var $ minX minY . 1 maxX maxY . /*assign minimum & maximum values.*/
do j=1 for circles; _= j * 3
@x.j= word($, _); @y.j=word($, _ + 1)
@r.j=word($, _ + 2) / 1; @rr.j= @r.j **2
minX= min(minX, @x.j - @r.j); maxX= max(maxX, @x.j + @r.j)
minY= min(minY, @y.j - @r.j); maxY= max(maxY, @y.j + @r.j)
end /*j*/
do m=1 for circles
do n=m+1 to circles
if @r.n>@r.m then parse value @x.n @y.n @r.n @x.m @y.m @r.m with,
@x.m @y.m @r.m @x.n @y.n @r.n
Line 2,494 ⟶ 2,498:
end /*m*/
dx= (maxX-minX) / box; dy= (maxY-minY) / box
w= length(circles)
#in= 0
do j=1 for circles /*traipse through the J circles.*/
do k=1 for circles; if k==j | @r.j==0 then iterate /*ignore self and/or 0*/
Line 2,503 ⟶ 2,507:
@y.j-@r.j < @y.k-@r.k | @x.j+@r.j > @x.k+@r.k then iterate
if verbose then say 'Circle ' right(j,w) ' is contained in circle ' right(k,w)
@r.j= 0; #in= #in +
end /*k*/
end /*j*/ /* [↑] elided overlapping circle.*/
Line 2,517 ⟶ 2,521:
do col=0 for boxen; x=minX + col*dx /* " " " " " column.*/
do k=1 for nC /*now process each new circle. */
if (x - @x.k)**2 + (y - @y.k)**2
end /*k*/
end /*col*/
Line 2,524 ⟶ 2,528:
say 'Using ' box " boxes (which have " box**2 ' points) and ' dig " decimal digits,"
say 'the approximate area is: ' #*dx*dy</lang>
<pre>
There are 25 circles.
|