Circles of given radius through two points: Difference between revisions

m
→‎{{header|REXX}}: changed column tags, simplified SQRT, added whitespace.
m (→‎{{header|REXX}}: removed OVERFLOW from PRE html tag.)
m (→‎{{header|REXX}}: changed column tags, simplified SQRT, added whitespace.)
Line 976:
{{trans|XPL0}}
<lang rexx>/*REXX pgm finds 2 circles with a specific radius given two (X,Y) points*/
@. =
@.1 = 0.1234 0.9876 0.8765 0.2345 2
@.2 = 0.0000 2.0000 0.0000 0.0000 1
@.3 = 0.1234 0.9876 0.1234 0.9876 2
@.4 = 0.1234 0.9876 0.8765 0.2345 0.5
@.5 = 0.1234 0.9876 0.1234 0.9876 0
say ' x1 y1 x2 y2 radius circle1x cir1xcircle1y circle2x cir1y cir2x cir2ycircle2y'
say ' ──────── ──────── ──────── ──────── ────── ──────── ──────── ──────── ────────'
do j=1 while @.j\=='' /*process all given points&radius*/
do k=1 for 4; w.k=f(word(@.j,k)); end /*k*/format # with /*format4 num.dec digs*/
end end /*jk*/
say w.1 w.2 w.3 w.4 center(word(@.j,5)/1,9) "───► " twoCircles(@.j)
end /*j*/
end /*j*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────F subroutine────────────────────────*/
f: return right(format(arg(1),,4),9) /*format a number# with 4 decdecimal digdigs.*/
/*──────────────────────────────────SQRT subroutine─────────────────────*/
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); numeric digits 11
numeric form; m.=11; p=d+d%4+2; parse value format(x,2,1,,0) 'E0' with g 'E' _ .; return g*.5'E'_%2
g=.sqrtGuess(); do j=0 while p>9; m.j=p; p=p%2+1; end
g=g*.5'E'_%2; do k=j+5 to 0 by -1; if m.k>11do thenj=0 numeric digitswhile p>9; m.kj=p; g p=.5*(gp%2+x/g)1; end
do k=j+5 to 0 by -1; if m.k>11 then numeric digits dm.k; return g=.5*(g+x/1g); 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───────────────*/
parse value format(x,2,1,,0) 'E0' with g 'E' _ .; return g*.5'E'_%2
/*──────────────────────────────────twoCircles subroutine───────────────*/
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)
if pbr=0 then return 'coincidentradius of pointszero givegives infiniteno circles'
if pb>r=0 then return 'coincident points are too far apart for thegive giveninfinite radiuscircles'
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
return f(bx-x1) f(by+y1) f(bx+x1) f(by-y1)</lang>
'''output''' when using the default input(s)inputs:
<pre>
x1 y1 x2 y2 radius circle1x cir1xcircle1y circle2x cir1y cir2x cir2ycircle2y
──────── ──────── ──────── ──────── ────── ──────── ──────── ──────── ────────
0.1234 0.9876 0.8765 0.2345 2 ───► 1.8631 1.9742 -0.8632 -0.7521
Line 1,014:
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.1234 0.9876 0 ───► radius of zero gives no circles.
</pre>