Constrained random points on a circle: Difference between revisions

→‎{{header|REXX}}: used a template for the output section, elided version 0 (which didn't use an aspect ratio), added/changed comments and whitespace.
(Add Factor)
(→‎{{header|REXX}}: used a template for the output section, elided version 0 (which didn't use an aspect ratio), added/changed comments and whitespace.)
Line 2,846:
 
=={{header|REXX}}==
===version 0, without aspect adjustment1===
NoThis REXX version uses aspect adjustment isfor donethe in versionplot of the REXX(sparse) programannulus.
 
Both version '''0''' and version '''1''' suppress the displaying of blank lines at the top and bottom of the plot.
<lang rexx>/*REXX program generates 100 random points in an annulus: 10 ≤ √(x²≤y²) ≤ 15 */
parse arg pointspts lowLO highHI . /*obtain optional args from the C.L. */
if highpts=='' then highpts=15; 100 high2=high**2 /* " " " " /*Not specified? Then " use the HIGHdefault.*/
if points=='' then points=100
if lowLO=='' then lowLO= 10; low2= low**2 LO2= LO**2 /*define a shortcut for squaring LOW LO. */
if highHI=='' then high HI= 15; high2=high**2 HI2= HI**2 /* " " " " " HIGHHI. */
$=
do x=-highHI; x2=x*x xx= x*x /*generate all possible annulus points.*/
if x<0 & x2xx>high2HI2 then iterate
if x>0 & x2xx>high2HI2 then leave
do y=-highHI; s=x2 xx + y*y
if (y<0 & s>high2HI2) | s<low2LO2 then iterate
if y>0 & s>high2 HI2 then leave
$= $ x','y /*add a point─set to the $ list. */
end /*y*/
end end /*x*/
plotChar='Θ'; minY plotChr=high2 'Θ'; minY= HI2; maxY= -minY; #= ap=words($); @.=
 
do pts; parse value word($, random(1,ap#)) with x ',' y /*pick a /*random point in the annulus.*/
plotChar='Θ'; minY=high2; maxY=-minY; ap=words($); @.=
@.y= overlay(plotChr, @.y, x*2 + HI*2 + 1); minY= min(minY, y); maxY= max(maxY, y)
 
doend /*pts*/ j=1 for points /*define the[↑] x,yplot pointsa [characterpoint; O]find min & max Y.*/
/*stick a fork in it, we're all done. */</lang>
parse value word($,random(1,ap)) with x ',' y /*pick a random point in the annulus.*/
@.do y=overlay(plotChar,minY @.y, x+high+1)to maxY; say @.y; /*define: the data point.end /*display the annulus to the terminal. */</lang>
'''{{out|output''' &nbsp; (with aspect adjustment) |text=&nbsp; when using the default inputinputs:}}
minY=min(minY,y); maxY=max(maxY,y) /*perform the plot point restricting. */
end /*j*/
/* [↓] only show displayable section. */
do y=minY to maxY; say @.y; end /*display the annulus to the terminal. */
/*stick a fork in it, we're all done. */</lang>
'''output''' &nbsp; (without aspect adjustment) &nbsp; when using the default input:
<pre>
Θ
ΘΘ ΘΘ
ΘΘ Θ Θ Θ
Θ Θ Θ
ΘΘ Θ Θ Θ
Θ Θ Θ
 
ΘΘ Θ Θ Θ
Θ Θ Θ
Θ Θ ΘΘ
Θ Θ Θ
Θ
Θ Θ
Θ Θ Θ
Θ ΘΘ
Θ
Θ
ΘΘ
Θ Θ Θ
Θ
Θ Θ Θ
Θ Θ Θ Θ
Θ Θ Θ
Θ ΘΘ Θ Θ
ΘΘΘΘ Θ Θ Θ
Θ Θ Θ Θ ΘΘ
Θ Θ Θ Θ
Θ Θ
</pre>
 
===version 1, with aspect adjustment===
Aspect adjustment is done in this version of the REXX program.
<lang rexx>/*REXX program generates 100 random points in an annulus: 10 ≤ √(x²≤y²) ≤ 15 */
parse arg points low high . /*obtain optional args from the C.L. */
if points=='' then points=100
if low=='' then low=10; low2= low**2 /*define a shortcut for squaring LOW. */
if high=='' then high=15; high2=high**2 /* " " " " " HIGH.*/
$=
do x=-high; x2=x*x /*generate all possible annulus points.*/
if x<0 & x2>high2 then iterate
if x>0 & x2>high2 then leave
do y=-high; s=x2+y*y
if (y<0 & s>high2) | s<low2 then iterate
if y>0 & s>high2 then leave
$=$ x','y /*add a point─set to the $ list. */
end /*y*/
end /*x*/
 
plotChar='Θ'; minY=high2; maxY=-minY; ap=words($); @.=
 
do j=1 for points /*define the x,y points [character O].*/
parse value word($,random(1,ap)) with x ',' y /*pick a random point in the annulus.*/
@.y=overlay(plotChar, @.y, 2*x+2*high+1) /*define: the data point. */
minY=min(minY,y); maxY=max(maxY,y) /*perform the plot point restricting. */
end /*j*/
/* [↓] only show displayable section. */
do y=minY to maxY; say @.y; end /*display the annulus to the terminal. */
/*stick a fork in it, we're all done. */</lang>
'''output''' &nbsp; (with aspect adjustment) &nbsp; when using the default input:
<pre>
Θ