Circles of given radius through two points: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: removed OVERFLOW from PRE html tag.) |
m (→{{header|REXX}}: changed column tags, simplified SQRT, added whitespace.) |
||
Line 976: | Line 976: | ||
{{trans|XPL0}} |
{{trans|XPL0}} |
||
<lang rexx>/*REXX pgm finds 2 circles with a specific radius given two (X,Y) points*/ |
<lang rexx>/*REXX pgm finds 2 circles with a specific radius given two (X,Y) points*/ |
||
@. = |
@. = |
||
@.1= 0.1234 0.9876 0.8765 |
@.1 = 0.1234 0.9876 0.8765 0.2345 2 |
||
@.2= 0 |
@.2 = 0 2 0 0 1 |
||
@.3= 0.1234 0.9876 0.1234 |
@.3 = 0.1234 0.9876 0.1234 0.9876 2 |
||
@.4= 0.1234 0.9876 0.8765 |
@.4 = 0.1234 0.9876 0.8765 0.2345 0.5 |
||
@.5= 0.1234 0.9876 0.1234 |
@.5 = 0.1234 0.9876 0.1234 0.9876 0 |
||
say ' x1 y1 x2 y2 radius |
say ' x1 y1 x2 y2 radius circle1x circle1y circle2x circle2y' |
||
say ' ──────── ──────── ──────── ──────── ────── ──────── ──────── ──────── ────────' |
say ' ──────── ──────── ──────── ──────── ────── ──────── ──────── ──────── ────────' |
||
do j=1 while @.j\=='' /*process all given points&radius*/ |
do j=1 while @.j\=='' /*process all given points&radius*/ |
||
do k=1 for 4; |
do k=1 for 4; w.k=f(word(@.j,k)) /*format # with 4 dec digs*/ |
||
⚫ | |||
say w.1 w.2 w.3 w.4 center(word(@.j,5),9) "───► " |
say w.1 w.2 w.3 w.4 center(word(@.j,5)/1,9) "───► " twoCircles(@.j) |
||
⚫ | |||
end /*j*/ |
|||
exit /*stick a fork in it, we're done.*/ |
exit /*stick a fork in it, we're done.*/ |
||
/*──────────────────────────────────F subroutine────────────────────────*/ |
/*──────────────────────────────────F subroutine────────────────────────*/ |
||
f: return right(format(arg(1),,4),9) /*format a |
f: return right(format(arg(1),,4),9) /*format a # with 4 decimal digs.*/ |
||
/*──────────────────────────────────SQRT subroutine─────────────────────*/ |
/*──────────────────────────────────SQRT subroutine─────────────────────*/ |
||
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits();numeric digits 11 |
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); numeric digits 11 |
||
⚫ | |||
g=.sqrtGuess(); do j=0 while p>9; m.j=p; p=p%2+1; end |
|||
g=g*.5'E'_%2; do j=0 while p>9; m.j=p; p=p%2+1; end |
|||
numeric digits |
do k=j+5 to 0 by -1; if m.k>11 then numeric digits m.k; g=.5*(g+x/g); end |
||
numeric digits d; return g/1 |
|||
.sqrtGuess: if x<0 then call sqrtErr; numeric form; m.=11; p=d+d%4+2 |
|||
/*──────────────────────────────────TWOCIRCLES subroutine───────────────*/ |
|||
⚫ | |||
/*──────────────────────────────────twoCircles subroutine───────────────*/ |
|||
twoCircles: procedure; parse arg px py qx qy r . |
twoCircles: procedure; parse arg px py qx qy r . |
||
if r=0 then return 'radius of zero gives no circles.' |
|||
x=(qx-px)/2; y=(qy-py)/2; bx=px+x; by=py+y; pb=sqrt(x**2+y**2) |
x=(qx-px)/2; y=(qy-py)/2; bx=px+x; by=py+y; pb=sqrt(x**2+y**2) |
||
if |
if r=0 then return 'radius of zero gives no circles' |
||
if pb |
if pb=0 then return 'coincident points give infinite circles' |
||
if pb>r then return 'points are too far apart for the given radius' |
|||
cb=sqrt(r**2-pb**2); x1=y*cb/pb; y1=x*cb/pb |
cb=sqrt(r**2-pb**2); x1=y*cb/pb; y1=x*cb/pb |
||
return f(bx-x1) f(by+y1) f(bx+x1) f(by-y1)</lang> |
return f(bx-x1) f(by+y1) f(bx+x1) f(by-y1)</lang> |
||
'''output''' when using the default |
'''output''' when using the default inputs: |
||
<pre> |
<pre> |
||
x1 y1 x2 y2 radius |
x1 y1 x2 y2 radius circle1x circle1y circle2x circle2y |
||
──────── ──────── ──────── ──────── ────── ──────── ──────── ──────── ──────── |
──────── ──────── ──────── ──────── ────── ──────── ──────── ──────── ──────── |
||
0.1234 0.9876 0.8765 0.2345 2 ───► 1.8631 1.9742 -0.8632 -0.7521 |
0.1234 0.9876 0.8765 0.2345 2 ───► 1.8631 1.9742 -0.8632 -0.7521 |
||
Line 1,014: | Line 1,014: | ||
0.1234 0.9876 0.1234 0.9876 2 ───► coincident points give infinite circles |
0.1234 0.9876 0.1234 0.9876 2 ───► coincident points give infinite circles |
||
0.1234 0.9876 0.8765 0.2345 0.5 ───► points are too far apart for the given radius |
0.1234 0.9876 0.8765 0.2345 0.5 ───► points are too far apart for the given radius |
||
0.1234 0.9876 0.1234 0.9876 0 ───► radius of zero gives no circles |
0.1234 0.9876 0.1234 0.9876 0 ───► radius of zero gives no circles |
||
</pre> |
</pre> |
||