Circles of given radius through two points: Difference between revisions

→‎{{header|Python}}: Update to handle r==0.0 special case.
(Update to task description to add to special case exceptions to be handled.)
(→‎{{header|Python}}: Update to handle r==0.0 special case.)
Line 22:
 
=={{header|Python}}==
The function raises the ValueError exception for the special cases and usess try - except to catch these and extract the exception detail.
 
<lang python>from collections import namedtuple
from math import sqrt
Line 30 ⟶ 32:
def circles_from_p1p2r(p1, p2, r):
'Following explanation at http://mathforum.org/library/drmath/view/53027.html'
if r == 0.0:
raise ValueError('radius of zero')
(x1, y1), (x2, y2) = p1, p2
if p1 == p2:
Line 56 ⟶ 60:
for p1, p2, r in [(Pt(0.1234, 0.9876), Pt(0.8765, 0.2345), 2.0),
(Pt(0.1234, 0.9876), Pt(0.1234, 0.9876), 2.0),
(Pt(0.1234, 0.9876), Pt(0.8765, 0.2345), 0.5)]:,
(Pt(0.1234, 0.9876), Pt(0.1234, 0.9876), 0.0)]:
print('Through points:\n %r,\n %r\n and radius %f\nYou can construct the following circles:'
% (p1, p2, r))
Line 93 ⟶ 98:
and radius 0.500000
You can construct the following circles:
ERROR: separation of points > diameter</pre>
 
Through points:
Pt(x=0.1234, y=0.9876),
Pt(x=0.1234, y=0.9876)
and radius 0.000000
You can construct the following circles:
ERROR: radius of zero</pre>
Anonymous user