Circles of given radius through two points: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
m (→‎{{header|REXX}}: handled case of lowercase E in a number, added/changed whitespace and comments.)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 188:
0.1234 0.9876 0.1234 0.9876 0.0 > No circles can be drawn, points are identical
</pre>
 
=={{header|AWK}}==
<lang AWK>
Line 1,306 ⟶ 1,307:
Nothing
Nothing</pre>
 
=={{header|Icon}} and {{header|Unicon}}==
{{trans|AutoHotKey}}
Line 1,551 ⟶ 1,553:
Test: 3: p1: 0.1234,0.9876, p2: 0.8765,0.2345, r:0.5 Result: No intersection. Points further apart than circle diameter
Test: 4: p1: 0.1234,0.9876, p2: 0.1234,0.9876, r:0 Result: Radius Zero
</lang>
 
=={{header|jq}}==
Line 2,384 ⟶ 2,386:
%4 = [0.370374144 + 0.740625856*I, 0.629525856 + 0.481474144*I]
%5 = "impossible"</pre>
 
 
=={{header|Perl}}==
Line 2,427 ⟶ 2,428:
(0.1234, 0.9876) and (0.8765, 0.2345) with radius 0.5: Separation of points greater than diameter
(0.1234, 0.9876) and (0.1234, 0.9876) with radius 0.0: Radius is zero</pre>
 
=={{header|Perl 6}}==
<lang Perl6>multi sub circles (@A, @B where ([and] @A Z== @B), 0.0) { 'Degenerate point' }
multi sub circles (@A, @B where ([and] @A Z== @B), $) { 'Infinitely many share a point' }
multi sub circles (@A, @B, $radius) {
my @middle = (@A Z+ @B) X/ 2;
my @diff = @A Z- @B;
my $q = sqrt [+] @diff X** 2;
return 'Too far apart' if $q > $radius * 2;
 
my @orth = -@diff[0], @diff[1] X* sqrt($radius ** 2 - ($q / 2) ** 2) / $q;
return (@middle Z+ @orth), (@middle Z- @orth);
}
 
my @input =
([0.1234, 0.9876], [0.8765, 0.2345], 2.0),
([0.0000, 2.0000], [0.0000, 0.0000], 1.0),
([0.1234, 0.9876], [0.1234, 0.9876], 2.0),
([0.1234, 0.9876], [0.8765, 0.2345], 0.5),
([0.1234, 0.9876], [0.1234, 0.9876], 0.0),
;
 
for @input {
say .list.perl, ': ', circles(|$_).join(' and ');
}</lang>
{{out}}
<pre>([0.1234, 0.9876], [0.8765, 0.2345], 2.0): 1.86311180165819 1.97421180165819 and -0.863211801658189 -0.752111801658189
([0.0, 2.0], [0.0, 0.0], 1.0): 0 1 and 0 1
([0.1234, 0.9876], [0.1234, 0.9876], 2.0): Infinitely many share a point
([0.1234, 0.9876], [0.8765, 0.2345], 0.5): Too far apart
([0.1234, 0.9876], [0.1234, 0.9876], 0.0): Degenerate point</pre>
 
Another possibility is to use the Complex plane,
for it often makes calculations easier with plane geometry:
 
<lang perl6>multi sub circles ($a, $b where $a == $b, 0.0) { 'Degenerate point' }
multi sub circles ($a, $b where $a == $b, $) { 'Infinitely many share a point' }
multi sub circles ($a, $b, $r) {
my $h = ($b - $a) / 2;
my $l = sqrt($r**2 - $h.abs**2);
return 'Too far apart' if $l.isNaN;
return map { $a + $h + $l * $_ * $h / $h.abs }, i, -i;
}
 
my @input =
(0.1234 + 0.9876i, 0.8765 + 0.2345i, 2.0),
(0.0000 + 2.0000i, 0.0000 + 0.0000i, 1.0),
(0.1234 + 0.9876i, 0.1234 + 0.9876i, 2.0),
(0.1234 + 0.9876i, 0.8765 + 0.2345i, 0.5),
(0.1234 + 0.9876i, 0.1234 + 0.9876i, 0.0),
;
 
for @input {
say .join(', '), ': ', circles(|$_).join(' and ');
}</lang>
 
{{out}}
<pre>0.1234+0.9876i, 0.8765+0.2345i, 2: 1.86311180165819+1.97421180165819i and -0.863211801658189-0.752111801658189i
0+2i, 0+0i, 1: 0+1i and 0+1i
0.1234+0.9876i, 0.1234+0.9876i, 2: Infinitely many share a point
0.1234+0.9876i, 0.8765+0.2345i, 0.5: Too far apart
0.1234+0.9876i, 0.1234+0.9876i, 0: Degenerate point</pre>
 
=={{header|Phix}}==
Line 2,668 ⟶ 2,607:
You can construct the following circles:
ERROR: radius of zero</pre>
 
 
=={{header|Racket}}==
Line 2,739 ⟶ 2,677:
(empty-scene 100 100))
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
<lang perl6>multi sub circles (@A, @B where ([and] @A Z== @B), 0.0) { 'Degenerate point' }
multi sub circles (@A, @B where ([and] @A Z== @B), $) { 'Infinitely many share a point' }
multi sub circles (@A, @B, $radius) {
my @middle = (@A Z+ @B) X/ 2;
my @diff = @A Z- @B;
my $q = sqrt [+] @diff X** 2;
return 'Too far apart' if $q > $radius * 2;
 
my @orth = -@diff[0], @diff[1] X* sqrt($radius ** 2 - ($q / 2) ** 2) / $q;
return (@middle Z+ @orth), (@middle Z- @orth);
}
 
my @input =
([0.1234, 0.9876], [0.8765, 0.2345], 2.0),
([0.0000, 2.0000], [0.0000, 0.0000], 1.0),
([0.1234, 0.9876], [0.1234, 0.9876], 2.0),
([0.1234, 0.9876], [0.8765, 0.2345], 0.5),
([0.1234, 0.9876], [0.1234, 0.9876], 0.0),
;
 
for @input {
say .list.perl, ': ', circles(|$_).join(' and ');
}</lang>
{{out}}
<pre>([0.1234, 0.9876], [0.8765, 0.2345], 2.0): 1.86311180165819 1.97421180165819 and -0.863211801658189 -0.752111801658189
([0.0, 2.0], [0.0, 0.0], 1.0): 0 1 and 0 1
([0.1234, 0.9876], [0.1234, 0.9876], 2.0): Infinitely many share a point
([0.1234, 0.9876], [0.8765, 0.2345], 0.5): Too far apart
([0.1234, 0.9876], [0.1234, 0.9876], 0.0): Degenerate point</pre>
 
Another possibility is to use the Complex plane,
for it often makes calculations easier with plane geometry:
 
<lang perl6>multi sub circles ($a, $b where $a == $b, 0.0) { 'Degenerate point' }
multi sub circles ($a, $b where $a == $b, $) { 'Infinitely many share a point' }
multi sub circles ($a, $b, $r) {
my $h = ($b - $a) / 2;
my $l = sqrt($r**2 - $h.abs**2);
return 'Too far apart' if $l.isNaN;
return map { $a + $h + $l * $_ * $h / $h.abs }, i, -i;
}
 
my @input =
(0.1234 + 0.9876i, 0.8765 + 0.2345i, 2.0),
(0.0000 + 2.0000i, 0.0000 + 0.0000i, 1.0),
(0.1234 + 0.9876i, 0.1234 + 0.9876i, 2.0),
(0.1234 + 0.9876i, 0.8765 + 0.2345i, 0.5),
(0.1234 + 0.9876i, 0.1234 + 0.9876i, 0.0),
;
 
for @input {
say .join(', '), ': ', circles(|$_).join(' and ');
}</lang>
 
{{out}}
<pre>0.1234+0.9876i, 0.8765+0.2345i, 2: 1.86311180165819+1.97421180165819i and -0.863211801658189-0.752111801658189i
0+2i, 0+0i, 1: 0+1i and 0+1i
0.1234+0.9876i, 0.1234+0.9876i, 2: Infinitely many share a point
0.1234+0.9876i, 0.8765+0.2345i, 0.5: Too far apart
0.1234+0.9876i, 0.1234+0.9876i, 0: Degenerate point</pre>
 
=={{header|REXX}}==
Line 3,627 ⟶ 3,628:
points {0,1234, 0,9876}, {0,8765, 0,2345} with radius 0,5 ==> too far apart 1,06504423382318 > 1
points {0,1234, 0,9876}, {0,1234, 0,9876} with radius 0 ==> same points/radius is zero</pre>
 
=={{header|Visual Basic .NET}}==
{{trans|C#}}
10,327

edits