Circles of given radius through two points: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added/changed whitespace and comments, used a template for the output sections.) |
Alextretyak (talk | contribs) (Added 11l) |
||
Line 30: | Line 30: | ||
* [http://mathforum.org/library/drmath/view/53027.html Finding the Center of a Circle from 2 Points and Radius] from Math forum @ Drexel |
* [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> |
<br><br> |
||
=={{header|11l}}== |
|||
{{trans|Python}} |
|||
<lang 11l>T Circle |
|||
Float x, y, r |
|||
F String() |
|||
R ‘Circle(x=#.6, y=#.6, r=#.6)’.format(.x, .y, .r) |
|||
F (x, y, r) |
|||
.x = x |
|||
.y = y |
|||
.r = r |
|||
T Error |
|||
String msg |
|||
F (msg) |
|||
.msg = msg |
|||
F circles_from_p1p2r(p1, p2, r) |
|||
‘Following explanation at http://mathforum.org/library/drmath/view/53027.html’ |
|||
I r == 0.0 |
|||
X Error(‘radius of zero’) |
|||
V (x1, y1) = p1 |
|||
V (x2, y2) = p2 |
|||
I p1 == p2 |
|||
X Error(‘coincident points gives infinite number of Circles’) |
|||
V (dx, dy) = (x2 - x1, y2 - y1) |
|||
V q = sqrt(dx ^ 2 + dy ^ 2) |
|||
I q > 2.0 * r |
|||
X Error(‘separation of points > diameter’) |
|||
V (x3, y3) = ((x1 + x2) / 2, (y1 + y2) / 2) |
|||
V d = sqrt(r ^ 2 - (q / 2) ^ 2) |
|||
V c1 = Circle(x' x3 - d * dy / q, |
|||
y' y3 + d * dx / q, |
|||
r' abs(r)) |
|||
V c2 = Circle(x' x3 + d * dy / q, |
|||
y' y3 - d * dx / q, |
|||
r' abs(r)) |
|||
R (c1, c2) |
|||
L(p1, p2, r) [((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)] |
|||
print("Through points:\n #.,\n #.\n and radius #.6\nYou can construct the following circles:".format(p1, p2, r)) |
|||
X.try |
|||
V (c1, c2) = circles_from_p1p2r(p1, p2, r) |
|||
print(" #.\n #.\n".format(c1, c2)) |
|||
X.catch Error v |
|||
print(" ERROR: #.\n".format(v.msg))</lang> |
|||
{{out}} |
|||
<pre> |
|||
Through points: |
|||
(0.1234, 0.9876), |
|||
(0.8765, 0.2345) |
|||
and radius 2.000000 |
|||
You can construct the following circles: |
|||
Circle(x=1.863112, y=1.974212, r=2.000000) |
|||
Circle(x=-0.863212, y=-0.752112, r=2.000000) |
|||
Through points: |
|||
(0, 2), |
|||
(0, 0) |
|||
and radius 1.000000 |
|||
You can construct the following circles: |
|||
Circle(x=0.000000, y=1.000000, r=1.000000) |
|||
Circle(x=0.000000, y=1.000000, r=1.000000) |
|||
Through points: |
|||
(0.1234, 0.9876), |
|||
(0.1234, 0.9876) |
|||
and radius 2.000000 |
|||
You can construct the following circles: |
|||
ERROR: coincident points gives infinite number of Circles |
|||
Through points: |
|||
(0.1234, 0.9876), |
|||
(0.8765, 0.2345) |
|||
and radius 0.500000 |
|||
You can construct the following circles: |
|||
ERROR: separation of points > diameter |
|||
Through points: |
|||
(0.1234, 0.9876), |
|||
(0.1234, 0.9876) |
|||
and radius 0.000000 |
|||
You can construct the following circles: |
|||
ERROR: radius of zero |
|||
</pre> |
|||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |