Circles of given radius through two points: Difference between revisions

→‎{{header|11l}}: make Error a non-fatal exception
m (syntax highlighting fixup automation)
(→‎{{header|11l}}: make Error a non-fatal exception)
(11 intermediate revisions by 9 users not shown)
Line 1:
[[Category:Geometry]]
{{task}}
[[File:2 circles through 2 points.jpg|650px||right|2 circles with a given radius through 2 points in 2D space.]]
Line 30 ⟶ 31:
*   [http://mathforum.org/library/drmath/view/53027.html Finding the Center of a Circle from 2 Points and Radius] from Math forum @ Drexel
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">T Circle
Float x, y, r
 
Line 50:
.msg = msg
 
F circles_from_p1p2r(p1, p2, r) X(Error)
‘Following explanation at http://mathforum.org/library/drmath/view/53027.html’
I r == 0.0
Line 81:
V (c1, c2) = circles_from_p1p2r(p1, p2, r)
print(" #.\n #.\n".format(c1, c2))
X.catchhandle Error v
print(" ERROR: #.\n".format(v.msg))</syntaxhighlight>
 
Line 127:
{{libheader|Action! Tool Kit}}
{{libheader|Action! Real Math}}
<syntaxhighlight lang=Action"action!">INCLUDE "H6:REALMATH.ACT"
 
PROC Circles(CHAR ARRAY sx1,sy1,sx2,sy2,sr)
Line 214:
p1=(.1234 .9876) p2=(.1234 .9876) r=0 -> Radius is zero, no circles
</pre>
 
=={{header|ALGOL 68}}==
Calculations based on the C solution.
<syntaxhighlight lang="algol68"># represents a point #
MODE POINT = STRUCT( REAL x, REAL y );
# returns TRUE if p1 is the same point as p2, FALSE otherwise #
Line 332 ⟶ 331:
One circle : radius: 0.0000 @( 0.1234, 0.9876)
</pre>
=={{header|Arturo}}==
 
<syntaxhighlight lang="arturo">getPoint: function [p]-> ~{(x: |p\0|, y: |p\1|)}
getCircle: function [c]-> ~{(x: |c\0|, y: |c\1|, r: |c\2|)}
 
circles: function [p1, p2, r][
if r = 0 -> return "radius of zero"
if p1 = p2 -> return "coincident points gives infinite number of circles"
 
[dx, dy]: @[p2\0 - p1\0, p2\1 - p1\1]
q: sqrt add dx*dx dy*dy
if q > 2*r -> return "separation of points > diameter"
 
p3: @[(p1\0 + p2\0)/ 2, (p1\1 + p2\1) / 2]
d: sqrt (r*r) - (q/2)*(q/2)
return @[
@[(p3\0 - d*dy/q), (p3\1 + d*dx/q), abs r],
@[(p3\0 + d*dy/q), (p3\1 - d*dx/q), abs r]
]
]
 
loop [
[[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]
] 'tr [
[p1, p2, r]: tr
print ["Through points:\n " getPoint p1 "\n " getPoint p2]
print ["and radius" (to :string r)++"," "you can construct the following circles:"]
if? string? cic: <= circles p1 p2 r -> print [" ERROR:" cic]
else [
[c1, c2]: cic
print [" " getCircle c1]
print [" " getCircle c2]
]
print ""
]</syntaxhighlight>
 
{{out}}
 
<pre>Through points:
(x: 0.1234, y: 0.9876)
(x: 0.8764999999999999, y: 0.2345)
and radius 2.0, you can construct the following circles:
(x: 1.863111801658189, y: 1.974211801658189, r: 2.0)
(x: -0.8632118016581896, y: -0.7521118016581892, r: 2.0)
 
Through points:
(x: 0.0, y: 2.0)
(x: 0.0, y: 0.0)
and radius 1.0, you can construct the following circles:
(x: 0.0, y: 1.0, r: 1.0)
(x: 0.0, y: 1.0, r: 1.0)
 
Through points:
(x: 0.1234, y: 0.9876)
(x: 0.1234, y: 0.9876)
and radius 2.0, you can construct the following circles:
ERROR: coincident points gives infinite number of circles
 
Through points:
(x: 0.1234, y: 0.9876)
(x: 0.8764999999999999, y: 0.2345)
and radius 0.5, you can construct the following circles:
ERROR: separation of points > diameter
 
Through points:
(x: 0.1234, y: 0.9876)
(x: 0.1234, y: 0.9876)
and radius 0.0, you can construct the following circles:
ERROR: radius of zero</pre>
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang=AutoHotkey"autohotkey">CircleCenter(x1, y1, x2, y2, r){
d := sqrt((x2-x1)**2 + (y2-y1)**2)
x3 := (x1+x2)/2 , y3 := (y1+y2)/2
Line 351 ⟶ 423:
return cx1 "," cy1 " & " cx2 "," cy2
}</syntaxhighlight>
Examples:<syntaxhighlight lang=AutoHotkey"autohotkey">data =
(
0.1234 0.9876 0.8765 0.2345 2.0
Line 374 ⟶ 446:
 
=={{header|AWK}}==
<syntaxhighlight lang=AWK"awk">
# syntax: GAWK -f CIRCLES_OF_GIVEN_RADIUS_THROUGH_TWO_POINTS.AWK
# converted from PL/I
Line 415 ⟶ 487:
0.1234 0.9876 0.1234 0.9876 0.00 radius of zero gives no circles
</pre>
=={{header|BASIC}}==
 
==={{header|BASIC256}}===
 
=={{header|BASIC256}}==
{{trans|Liberty BASIC}}
<syntaxhighlight lang=BASIC256"basic256">
function twoCircles(x1, y1, x2, y2, radio)
if x1 = x2 and y1 = y2 then #Si los puntos coinciden
Line 468 ⟶ 539:
end
</syntaxhighlight>
 
 
=={{header|C}}==
<syntaxhighlight lang=C"c">#include<stdio.h>
#include<math.h>
 
Line 549 ⟶ 619:
No circles can be drawn through (0.1234,0.9876)
</pre>
 
=={{header|C sharp|C#}}==
{{works with|C sharp|6}}
<syntaxhighlight lang="csharp">using System;
public class CirclesOfGivenRadiusThroughTwoPoints
{
Line 636 ⟶ 705:
Points (0.1234, 0.9876) and (0.1234, 0.9876) with radius 0:
(0.1234, 0.9876)</pre>
 
=={{header|C++}}==
{{works with|C++11}}
<syntaxhighlight lang="cpp">
#include <iostream>
#include <cmath>
Line 667 ⟶ 735:
if(half_distance > r) return std::make_tuple(NONE, ans1, ans2);
if(half_distance - r == 0) return std::make_tuple(ONE_DIAMETER, center, ans2);
double root = std::hypotsqrt(pow(r, 2.l) - pow(half_distance, 2.l)) / distance(p1, p2);
ans1.x = center.x + root * (p1.y - p2.y);
ans1.y = center.y + root * (p2.x - p1.x);
Line 706 ⟶ 774:
{{out}}
<pre>
Two solutions: 1.9634486311 21.0745497421 and -0.963536863212 -0.852436752112
Only one solution: 0 1
Infinitely many circles can be drawn
Line 715 ⟶ 783:
=={{header|D}}==
{{trans|Python}}
<syntaxhighlight lang="d">import std.stdio, std.typecons, std.math;
 
class ValueException : Exception {
Line 810 ⟶ 878:
{{libheader| System.Math}}
{{Trans|C}}
<syntaxhighlight lang=Delphi"delphi">
program Circles_of_given_radius_through_two_points;
 
Line 901 ⟶ 969:
readln;
end.</syntaxhighlight>
=={{header|EasyLang}}==
{{trans|AWK}}
<syntaxhighlight>
func$ fmt a b .
return "(" & a & " " & b & ")"
.
proc test m1x m1y m2x m2y r . .
print "Points: " & fmt m1x m1y & " " & fmt m2x m2y & " Radius: " & r
if r = 0
print "Radius of zero gives no circles"
print ""
return
.
x = (m2x - m1x) / 2
y = (m2y - m1y) / 2
bx = m1x + x
by = m1y + y
pb = sqrt (x * x + y * y)
if pb = 0
print "Coincident points give infinite circles"
print ""
return
.
if pb > r
print "Points are too far apart for the given radius"
print ""
return
.
cb = sqrt (r * r - pb * pb)
x1 = y * cb / pb
y1 = x * cb / pb
print "Circles: " & fmt (bx - x1) (by + y1) & " " & fmt (bx + x1) (by - y1)
print ""
.
test 0.1234 0.9876 0.8765 0.2345 2.0
test 0.0000 2.0000 0.0000 0.0000 1.0
test 0.1234 0.9876 0.1234 0.9876 2.0
test 0.1234 0.9876 0.8765 0.2345 0.5
test 0.1234 0.9876 0.1234 0.9876 0.0
</syntaxhighlight>
 
=={{header|Elixir}}==
{{trans|Ruby}}
<syntaxhighlight lang="elixir">defmodule RC do
def circle(p, p, r) when r>0.0 do
raise ArgumentError, message: "Infinite number of circles, points coincide."
Line 981 ⟶ 1,089:
 
=={{header|ERRE}}==
<syntaxhighlight lang="text">
PROGRAM CIRCLES
 
Line 1,034 ⟶ 1,142:
END PROGRAM
</syntaxhighlight>
 
=={{header|F Sharp|F#}}==
<syntaxhighlight lang="fsharp">open System
 
let add (a:double, b:double) (x:double, y:double) = (a + x, b + y)
Line 1,077 ⟶ 1,184:
<null>
<null></pre>
 
=={{header|Factor}}==
<syntaxhighlight lang="factor">USING: accessors combinators combinators.short-circuit
formatting io kernel literals locals math math.distances
math.functions prettyprint sequences strings ;
Line 1,191 ⟶ 1,297:
one degenerate circle found at (0.1234, 0.9876).
</pre>
 
=={{header|Fortran}}==
<syntaxhighlight lang="fortran">
! Implemented by Anant Dixit (Nov. 2014)
! Transpose elements in find_center to obtain correct results. R.N. McLean (Dec 2017)
Line 1,338 ⟶ 1,443:
===Using complex numbers===
Fortran 66 made standard the availability of complex number arithmetic. This version however takes advantage of facilities offered in F90 so as to perform some array-based arithmetic, though the opportunities in this small routine are thin: two statements become one (look for CMPLX). More seriously, the MODULE facility allows the definition of an array SQUAWK which contains an explanatory text associated with each return code. The routine has a troublesome variety of possible odd conditions to report. An older approach would be to have a return message CHARACTER variable to present the remark, at the cost of filling up that variable with text every time. By returning an integer code, less effort is required, but there is no explication of the return codes. One could still have an array of messages (and prior to F90, array index counting started at one only, so no starting with -3 for errorish codes) but making that array available would require some sort of COMMON storage. The MODULE facility eases this problem.
<syntaxhighlight lang=Fortran"fortran"> MODULE GEOMETRY !Limited scope.
CHARACTER*(*) SQUAWK(-3:2) !Holds a schedule of complaints.
PARAMETER (SQUAWK = (/ !According to what might go wrong.
Line 1,433 ⟶ 1,538:
One 'circle', centred on the co-incident points. R is zero!
</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">Type Point
As Double x,y
Declare Property length As Double
Line 1,489 ⟶ 1,593:
Points (0.1234,0.9876),(0.1234,0.9876), Rad 0
Points are the same</pre>
 
=={{header|Go}}==
<syntaxhighlight lang="go">package main
 
import (
Line 1,596 ⟶ 1,699:
Center: {0.1234 0.9876}
</pre>
 
=={{header|Groovy}}==
{{trans|Java}}
<syntaxhighlight lang="groovy">class Circles {
private static class Point {
private final double x, y
Line 1,698 ⟶ 1,800:
For points (0.1234, 0.9876) and (0.1234, 0.9876) with radius 0.000000
there is just one circle with center at (0.1234, 0.9876)</pre>
 
=={{header|Haskell}}==
<syntaxhighlight lang=Haskell"haskell">add (a, b) (x, y) = (a + x, b + y)
sub (a, b) (x, y) = (a - x, b - y)
magSqr (a, b) = (a ^^ 2) + (b ^^ 2)
Line 1,742 ⟶ 1,843:
Nothing
Nothing</pre>
 
=={{header|Icon}} and {{header|Unicon}}==
{{trans|AutoHotKey}}
Works in both languages.
<syntaxhighlight lang="unicon">procedure main()
A := [ [0.1234, 0.9876, 0.8765, 0.2345, 2.0],
[0.0000, 2.0000, 0.0000, 0.0000, 1.0],
Line 1,779 ⟶ 1,879:
->
</pre>
 
=={{header|J}}==
 
2D computations are often easier using the complex plane.
<syntaxhighlight lang=J"j">average =: +/ % #
 
circles =: verb define"1
Line 1,828 ⟶ 1,927:
└───────────────────────────────┴────────────────────────────────────────────────────┘
</syntaxhighlight>
 
=={{header|Java}}==
{{trans|Kotlin}}
<syntaxhighlight lang=Java"java">import java.util.Objects;
 
public class Circles {
Line 1,932 ⟶ 2,030:
For points (0.1234, 0.9876) and (0.1234, 0.9876) with radius 0.000000
there is just one circle with center at (0.1234, 0.9876)</pre>
 
=={{header|JavaScript}}==
 
====ES6====
 
<syntaxhighlight lang=JavaScript"javascript">const hDist = (p1, p2) => Math.hypot(...p1.map((e, i) => e - p2[i])) / 2;
const pAng = (p1, p2) => Math.atan(p1.map((e, i) => e - p2[i]).reduce((p, c) => c / p, 1));
const solveF = (p, r) => t => [r*Math.cos(t) + p[0], r*Math.sin(t) + p[1]];
Line 1,982 ⟶ 2,079:
 
Output:
<syntaxhighlight lang=JavaScript"javascript">
Test: 0: p1: 0.1234,0.9876, p2: 0.8765,0.2345, r:2 Result: Circle at 1.8631118016581891,1.974211801658189 Circle at -0.863211801658189,-0.7521118016581889
Test: 1: p1: 0,2, p2: 0,0, r:1 Result: Points on diameter. Circle at: 0,1
Line 1,989 ⟶ 2,086:
Test: 4: p1: 0.1234,0.9876, p2: 0.1234,0.9876, r:0 Result: Radius Zero
</syntaxhighlight>
 
=={{header|jq}}==
{{works with|jq|1.4}}
In this section, a point in the plane will be represented by its Cartesian co-ordinates expressed as a JSON array: [x,y].
<syntaxhighlight lang="jq"># circle_centers is defined here as a filter.
# Input should be an array [x1, y1, x2, y2, r] giving the co-ordinates
# of the two points and a radius.
Line 2,021 ⟶ 2,117:
end;</syntaxhighlight>
'''Examples''':
<syntaxhighlight lang="jq">(
[0.1234, 0.9876, 0.8765, 0.2345, 2],
[0.0000, 2.0000, 0.0000, 0.0000, 1],
Line 2,031 ⟶ 2,127:
{{out}}
<syntaxhighlight lang="sh">$ jq -n -c -r -f /Users/peter/jq/circle_centers.jq
 
[0.1234,0.9876,0.8765,0.2345,2] ───► [1.8631118016581893,1.974211801658189,-0.8632118016581896,-0.7521118016581892]
Line 2,038 ⟶ 2,134:
[0.1234,0.9876,0.8765,0.2345,0.5] ───► points are too far from each other
[0.1234,0.9876,0.1234,0.9876,0] ───► [0.1234,0.9876]</syntaxhighlight>
 
=={{header|Julia}}==
This solution uses the package [https://github.com/timholy/AffineTransforms.jl AffineTransforms.jl] to introduce a coordinate system (u, v) centered on the midpoint between the two points and rotated so that these points are on the u-axis. In this system, solving for the circles' centers is trivial. The two points are cast as complex numbers to aid in determining the location of the midpoint and rotation angle.
 
'''Types and Functions'''
<syntaxhighlight lang=Julia"julia">
immutable Point{T<:FloatingPoint}
x::T
Line 2,088 ⟶ 2,183:
 
'''Main'''
<syntaxhighlight lang=Julia"julia">
tp = [Point(0.1234, 0.9876),
Point(0.0000, 2.0000),
Line 2,131 ⟶ 2,226:
(0.1234, 0.9876), 0.0000
</pre>
 
=={{header|Kotlin}}==
<syntaxhighlight lang="scala">// version 1.1.51
 
typealias IAE = IllegalArgumentException
Line 2,215 ⟶ 2,309:
there is just one circle with center at (0.1234, 0.9876)
</pre>
 
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
input: OP1=(x1,y1), OP2=(x2,y2), r
output: OC = OH + HC
Line 2,279 ⟶ 2,372:
-> radius is zero
</syntaxhighlight>
 
=={{header|Liberty BASIC}}==
<syntaxhighlight lang="lb">
'[RC] Circles of given radius through two points
for i = 1 to 5
Line 2,330 ⟶ 2,422:
 
Output:
<syntaxhighlight lang="text">
1) 0.1234 0.9876 0.8765 0.2345 2
(1.8631118,1.9742118)
Line 2,344 ⟶ 2,436:
It will be a single point (0.1234,0.9876) of radius 0
</syntaxhighlight>
 
=={{header|Lua}}==
{{trans|C}}
<syntaxhighlight lang="lua">function distance(p1, p2)
local dx = (p1.x-p2.x)
local dy = (p1.y-p2.y)
Line 2,414 ⟶ 2,505:
Case 5
No circles can be drawn through (0.1234, 0.9876)</pre>
 
=={{header|Maple}}==
<syntaxhighlight lang="maple">drawCircles := proc(x1, y1, x2, y2, r, $)
local c1, c2, p1, p2;
use geometry in
Line 2,453 ⟶ 2,543:
The circle is a point at [.1234, .9876].
</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang=Mathematica"mathematica">Off[Solve::ratnz];
circs::invrad = "The radius is invalid.";
circs::equpts = "The given points (`1`, `2`) are equivalent.";
Line 2,480 ⟶ 2,569:
circs[{.1234, .9876}, {.1234, .9876}, 0.]
circs::invrad: The radius is invalid.</pre>
 
=={{header|Maxima}}==
<syntaxhighlight lang=Maxima"maxima">/* define helper function */
vabs(a):= sqrt(a.a);
realp(e):=freeof(%i, e);
Line 2,526 ⟶ 2,614:
apply('getsol, cons(sol, d[4]));</syntaxhighlight>
{{out}}
<syntaxhighlight lang="text">apply('getsol, cons(sol, d[1]));
two solutions
(%o9) [[x0 = 1.86311180165819, y0 = 1.974211801658189],
Line 2,539 ⟶ 2,627:
infinity many solutions
(%o12) infmany</syntaxhighlight>
 
=={{header|МК-61/52}}==
<syntaxhighlight lang="text">П0 С/П П1 С/П П2 С/П П3 С/П П4
ИП2 ИП0 - x^2 ИП3 ИП1 - x^2 + КвКор П5
ИП0 ИП2 + 2 / П6 ИП1 ИП3 + 2 / П7
Line 2,562 ⟶ 2,649:
"8.L" if the points are coincident; "8.-" if the points are opposite ends of a diameter of the circle, РY and РZ are coordinates of the center; "8.Г" if the points are farther away from each other than a diameter of a circle; else РX, РY and РZ, РT are coordinates of the circles centers.
</pre>
 
=={{header|Modula-2}}==
<syntaxhighlight lang="modula2">MODULE Circles;
FROM EXCEPTIONS IMPORT AllocateSource,ExceptionSource,GetMessage,RAISE;
FROM FormatString IMPORT FormatString;
Line 2,682 ⟶ 2,768:
ReadChar
END Circles.</syntaxhighlight>
 
=={{header|Nim}}==
{{trans|Python}}
<syntaxhighlight lang="nim">import math
 
type
Line 2,770 ⟶ 2,855:
You can construct the following circles:
ERROR: radius of zero</pre>
 
=={{header|OCaml}}==
Original version by [http://rosettacode.org/wiki/User:Vanyamil User:Vanyamil]
<syntaxhighlight lang=OCaml"ocaml">
(* Task : Circles of given radius through two points *)
 
Line 2,847 ⟶ 2,931:
One solution: (0.123400, 0.987600)
</pre>
 
=={{header|Oforth}}==
 
<syntaxhighlight lang="oforth">: circleCenter(x1, y1, x2, y2, r)
| d xmid ymid r1 md |
x2 x1 - sq y2 y1 - sq + sqrt -> d
Line 2,886 ⟶ 2,969:
 
</pre>
 
=={{header|ooRexx}}==
{{trans|REXX}}
<syntaxhighlight lang="oorexx">/*REXX pgm finds 2 circles with a specific radius given two (X,Y) points*/
a.=''
a.1=0.1234 0.9876 0.8765 0.2345 2
Line 2,936 ⟶ 3,018:
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.0 radius of zero gives no circles.</pre>
=={{header|OpenSCAD}}==
<syntaxhighlight lang="OpenSCAD">
// distance between two points
function distance(p1, p2) = sqrt((difference(p2.x, p1.x)) ^ 2 + (difference(p2.y, p1.y) ^ 2));
// difference between two values in any order
function difference(a, b) = let(x = a > b ? a - b : b - a) x;
 
// function to find the circles of given radius through two points
function circles_of_given_radius_through_two_points(p1, p2, radius) =
let(mid = (p1 + p2)/2, q = distance(p1, p2), x_dist = sqrt(radius ^ 2 - (q / 2) ^ 2) * (p1.y - p2.y) / q,
y_dist = sqrt(radius ^ 2 - (q / 2) ^ 2) * (p2.x - p1.x) / q)
// point 1 and point 2 must not be the same point
assert(p1 != p2)
// radius must be more than 0
assert(radius > 0)
// distance between points cannot be more than diameter
assert(q < radius * 2)
// return both qualifying centres
[mid + [ x_dist, y_dist ], mid - [ x_dist, y_dist ]];
 
// test module for circles_of_given_radius_through_two_points
module test_circles_of_given_radius_through_two_points()
{
tests = [
[ [ -10, -10, 0 ], [ 50, 0, 0 ], 100 ], [ [ 200, 0, 0 ], [ 220, -20, 0 ], 30 ],
[ [ 300, 100, 0 ], [ 350, 200, 0 ], 80 ]
];
 
for (t = tests)
{
let(start = t[0], end = t[1], radius = t[2])
{
// plot start and end dots - these should be at the intersections of the circles
color("green") translate(start) cylinder(h = 3, r = 4);
color("green") translate(end) cylinder(h = 3, r = 4);
 
// call function
centres = circles_of_given_radius_through_two_points(start, end, radius);
echo("centres", centres);
// plot results
color("yellow") translate(centres[0]) cylinder(h = 1, r = radius);
color("red") translate(centres[1]) cylinder(h = 2, r = radius);
};
};
// The following tests will stop all execution. To run them, uncomment one at a time
// should fail - same points
// echo(circles_of_given_radius_through_two_points([0,0],[0,0],1));
// should fail - points are more than diameter apart
// echo(circles_of_given_radius_through_two_points(p1 = [0,0], p2 = [0,101], radius = 50));
// should fail - radius must be greater than 0
// echo(circles_of_given_radius_through_two_points(p1= [1,1], p2 = [10,1], radius = 0));
}
 
test_circles_of_given_radius_through_two_points();
</syntaxhighlight>
 
=={{header|PARI/GP}}==
<syntaxhighlight lang="parigp">circ(a, b, r)={
if(a==b, return("impossible"));
my(h=(b-a)/2,t=sqrt(r^2-abs(h)^2)/abs(h)*h);
Line 2,957 ⟶ 3,094:
=={{header|Perl}}==
{{trans|Python}}
<syntaxhighlight lang="perl">use strict;
 
sub circles {
Line 2,996 ⟶ 3,133:
(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|Phix}}==
<!--<syntaxhighlight lang=Phix"phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">tests</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{{</span><span style="color: #000000;">0.1234</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.9876</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.8765</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.2345</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2.0</span><span style="color: #0000FF;">},</span>
Line 3,032 ⟶ 3,168:
points {0.1234,0.9876}, {0.1234,0.9876} with radius 0.0 ==> same points/radius is zero
</pre>
 
=={{header|PL/I}}==
{{trans|REXX}}
<syntaxhighlight lang=PL"pl/Ii">twoci: Proc Options(main);
Dcl 1 *(5),
2 m1x Dec Float Init(0.1234, 0,0.1234,0.1234,0.1234),
Line 3,086 ⟶ 3,221:
0.1234 0.9876 0.1234 0.9876 0 radius of zero gives no circles.
</pre>
 
=={{header|PureBasic}}==
<syntaxhighlight lang=PureBasic"purebasic">DataSection
DataStart:
Data.d 0.1234, 0.9876, 0.8765, 0.2345, 2.0
Line 3,131 ⟶ 3,265:
No circles possible.
Illegal radius.</pre>
 
=={{header|Python}}==
The function raises the ValueError exception for the special cases
and uses try - except to catch these and extract the exception detail.
 
<syntaxhighlight lang="python">from collections import namedtuple
from math import sqrt
 
Line 3,219 ⟶ 3,352:
You can construct the following circles:
ERROR: radius of zero</pre>
 
=={{header|Racket}}==
Using library `plot/utils` for simple vector operations.
 
<syntaxhighlight lang="racket">
#lang racket
(require plot/utils)
Line 3,272 ⟶ 3,404:
Drawing circles:
 
<syntaxhighlight lang="racket">
(require 2htdp/image)
 
Line 3,289 ⟶ 3,421:
(empty-scene 100 100))
</syntaxhighlight>
 
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2020.08.1}}
<syntaxhighlight lang="raku" line>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) {
Line 3,326 ⟶ 3,457:
for it often makes calculations easier with plane geometry:
 
<syntaxhighlight lang="raku" line>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) {
Line 3,353 ⟶ 3,484:
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}}==
{{trans|XPL0}}
 
<br>The REXX language doesn't have a &nbsp; '''sqrt''' &nbsp; function, &nbsp; so one is included below.
<syntaxhighlight lang="rexx">/*REXX pgm finds 2 circles with a specific radius given 2 (X1,Y1) and (X2,Y2) ctr points*/
@.=; @.1= 0.1234 0.9876 0.8765 0.2345 2
@.2= 0 2 0 0 1
Line 3,398 ⟶ 3,528:
0.1234 0.9876 0.1234 0.9876 0 ───► radius of zero gives no circles.
</pre>
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
# Project : Circles of given radius through two points
 
Line 3,488 ⟶ 3,617:
It will be a single point (0.1234,0.9876) of radius 0
</pre>
 
=={{header|Ruby}}==
{{trans|Python}}
<syntaxhighlight lang="ruby">Pt = Struct.new(:x, :y)
Circle = Struct.new(:x, :y, :r)
 
Line 3,564 ⟶ 3,692:
#<struct Circle x=0.1234, y=0.9876, r=0.0>
</pre>
 
=={{header|Run BASIC}}==
<syntaxhighlight lang="rnbasic">
html "<TABLE border=1>"
html "<tr bgcolor=wheat align=center><td>No.</td><td>x1</td><td>y1</td><td>x2</td><td>y2</td><td>r</td><td>cir x1</td><td>cir y1</td><td>cir x2</td><td>cir y2</td></tr>"
Line 3,626 ⟶ 3,753:
<TD ALIGN="LEFT" COLSPAN="4">It will be a single point (0.1234,0.9876) of radius 0</TD></TR>
</TABLE>
 
=={{header|Rust}}==
{{trans|C}}
<syntaxhighlight lang="rust">use std::fmt;
 
#[derive(Clone,Copy)]
Line 3,703 ⟶ 3,829:
Points: ((0.1234, 0.9876), (0.1234, 0.9876)), Radius: 0.0000
No circles can be drawn through (0.1234, 0.9876)</pre>
 
=={{header|Scala}}==
<syntaxhighlight lang="scala">import org.scalatest.FunSuite
import math._
 
Line 3,767 ⟶ 3,892:
(0.1234, 0.9876) (0.8765, 0.2345) 0.5: radius is less then the distance between points
(0.1234, 0.9876) (0.1234, 0.9876) 0.0: radius of zero yields no circlesEmpty test suite.</pre>
 
=={{header|Scheme}}==
 
<syntaxhighlight lang="scheme">
(import (scheme base)
(scheme inexact)
Line 3,843 ⟶ 3,967:
p1: (0.1234 0.9876) p2: (0.1234 0.9876) r: 0.0 => ((0.1234 0.9876))
</pre>
 
=={{header|Seed7}}==
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "float.s7i";
include "math.s7i";
Line 3,931 ⟶ 4,054:
Radius of zero. No circles can be drawn through (0.1234, 0.9876)
</pre>
 
=={{header|Sidef}}==
{{trans|Raku}}
<syntaxhighlight lang="ruby">func circles(a, b, r) {
 
if (a == b) {
Line 3,977 ⟶ 4,099:
0.1234+0.9876i, 0.1234+0.9876i, 0: Degenerate point
</pre>
 
=={{header|Stata}}==
Each circle center is the image of B by the composition of a rotation and homothecy centered at A. It's how the centers are computed in this implementation. The coordinates are returned as the columns of a 2x2 matrix. When the solution is not unique or does not exist, this matrix contains only missing values.
 
<syntaxhighlight lang="stata">real matrix centers(real colvector a, real colvector b, real scalar r) {
real matrix rot
real scalar d, u, v
Line 4,003 ⟶ 4,124:
Examples:
 
<syntaxhighlight lang="stata">:a=0.1234\0.9876
:b=0.8765\0.2345
: centers(a,b,2)
Line 4,041 ⟶ 4,162:
2 | .9876 .9876 |
+-----------------+</syntaxhighlight>
 
=={{header|Swift}}==
 
{{trans|F#}}
 
<syntaxhighlight lang="swift">import Foundation
 
struct Point: Equatable {
Line 4,133 ⟶ 4,253:
No ans
No ans</pre>
 
=={{header|Tcl}}==
{{trans|Python}}
<syntaxhighlight lang="tcl">proc findCircles {p1 p2 r} {
lassign $p1 x1 y1
lassign $p2 x2 y2
Line 4,170 ⟶ 4,289:
 
{{out|Demo}}
<syntaxhighlight lang="tcl">foreach {p1 p2 r} {
{0.1234 0.9876} {0.8765 0.2345} 2.0
{0.0000 2.0000} {0.0000 0.0000} 1.0
Line 4,201 ⟶ 4,320:
Circle:(0.1234, 0.9876, 0.0)
</pre>
 
=={{header|VBA}}==
{{trans|Phix}}<syntaxhighlight lang="vb">Public Sub circles()
tests = [{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 i = 1 To UBound(tests)
Line 4,243 ⟶ 4,361:
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#}}
<syntaxhighlight lang="vbnet">Public Class CirclesOfGivenRadiusThroughTwoPoints
Public Shared Sub Main()
For Each valu In New Double()() {
Line 4,325 ⟶ 4,442:
Points (0.1234, 0.9876) and (0.2345, 0.8765) with radius 0:
No circles.</pre>
 
=={{header|Visual FoxPro}}==
Translation of BASIC.
<syntaxhighlight lang="vfp">
LOCAL p1 As point, p2 As point, rr As Double
CLOSE DATABASES ALL
Line 4,443 ⟶ 4,559:
Points are coincident.
</pre>
=={{header|V (Vlang)}}==
 
=={{header|Vlang}}==
{{trans|Go}}
<syntaxhighlight lang="v (vlang)">import math
 
const (
Line 4,603 ⟶ 4,718:
{{trans|Go}}
{{libheader|Wren-math}}
<syntaxhighlight lang=ecmascript"wren">import "./math" for Math
 
var Two = "Two circles."
Line 4,708 ⟶ 4,823:
The method used here is a streamlining of these steps.
 
<syntaxhighlight lang=XPL0"xpl0">include c:\cxpl\codes;
 
proc Circles; real Data; \Show centers of circles, given points P & Q and radius
Line 4,742 ⟶ 4,857:
Radius = zero gives no circles
</pre>
 
 
=={{header|Yabasic}}==
{{trans|Liberty BASIC}}
<syntaxhighlight lang=Yabasic"yabasic">
sub twoCircles (x1, y1, x2, y2, radio)
if x1 = x2 and y1 = y2 then //Si los puntos coinciden
Line 4,791 ⟶ 4,904:
 
</syntaxhighlight>
 
 
=={{header|zkl}}==
{{trans|C}}
<syntaxhighlight lang="zkl">fcn findCircles(a,b, c,d, r){ //-->T(T(x,y,r) [,T(x,y,r)]))
delta:=(a-c).hypot(b-d);
switch(delta){ // could just catch MathError
Line 4,843 ⟶ 4,954:
Circles: singularity
</pre>
 
=={{header|ZX Spectrum Basic}}==
{{trans|Liberty BASIC}}
<syntaxhighlight lang="zxbasic">10 FOR i=1 TO 5
20 READ x1,y1,x2,y2,r
30 PRINT i;") ";x1;" ";y1;" ";x2;" ";y2;" ";r
Line 4,873 ⟶ 4,983:
1200 PRINT "(";cx-dy;",";cy-dx;")"
1210 RETURN</syntaxhighlight>
 
[[Category:Geometry]]
1,480

edits