Anonymous user
Circles of given radius through two points: Difference between revisions
Circles of given radius through two points (view source)
Revision as of 18:37, 17 October 2014
, 9 years ago→{{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
@.2 = 0
@.3 = 0.1234 0.9876 0.1234
@.4 = 0.1234 0.9876 0.8765
@.5 = 0.1234 0.9876 0.1234
say ' x1 y1 x2 y2 radius circle1x
say ' ──────── ──────── ──────── ──────── ────── ──────── ──────── ──────── ────────'
do j=1 while @.j\=='' /*process all given points&radius*/
do k=1 for 4;
say w.1 w.2 w.3 w.4 center(word(@.j,5)/1,9) "───► "
▲ 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
/*──────────────────────────────────SQRT subroutine─────────────────────*/
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); numeric digits 11
numeric form; m.=11;
g=g*.5'E'_%2;
do k=j+5 to 0 by -1; if m.k>11 then numeric digits
numeric digits d; return g/1
/*──────────────────────────────────TWOCIRCLES subroutine───────────────*/
▲ parse value format(x,2,1,,0) 'E0' with g 'E' _ .; return g*.5'E'_%2
twoCircles: procedure; parse arg px py qx qy r .
x=(qx-px)/2; y=(qy-py)/2; bx=px+x; by=py+y; pb=sqrt(x**2+y**2)
if
if pb
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
<pre>
x1 y1 x2 y2 radius circle1x
──────── ──────── ──────── ──────── ────── ──────── ──────── ──────── ────────
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>
|