Smallest enclosing circle problem: Difference between revisions

m
→‎{{header|Phix}}: minor simplifications
m (→‎{{header|Phix}}: minor simplifications)
Line 358:
function circle_from2(point a, b)
-- return the smallest circle that intersects 2 points:
point centremidpoint = sq_div(sq_add(a,b),2) -- (ie midpoint)
atom radiushalfdiameter = distance(a,b)/2
circle res = { centremidpoint, radiushalfdiameter }
return res
end function
Line 366:
function circle_from3(point a, b, c)
-- return a unique circle that intersects three points
atompoint {{aX,aY},{bX,bY},{cX,cY}}bma = {a,sq_sub(b,a),sq_sub(c,a)},
B cma = bX * bX + bY * bYsq_sub(c,a)
atom C = {{aX,aY},{bX,bY},{cX * cX + ,cY}} *= cY{a,bma,cma},
DB = bX * cY - bY * cX sum(sq_power(bma,2)),
point centre = { (cY * B - bY * C) /= sum(sq_power(cma,2 * D) + aX),
D = (bX * CcY - bY*cX )* B) / (2 * D) + aY }
circlepoint rescentre = {(cY*B centre,- distance(centrebY*C)/D + aX, a) }
(bX*C - cX*B)/D + aY }
atom radius = distance(centre,a) -- (=== b,c)
circle res = { centre, radius }
return res
end function
Line 396 ⟶ 399:
 
procedure welzl(sequence p)
printf(1,"Pointscircle %vc ==> centre %v radius %.14g\n",prepend(welzlr(shuffle(p),{}),p))
string s = sprintf("centre %v radius %.14g",c)
printf(1,"Points %v ==> %s\n",{p,s})
end procedure
 
constant tests = {{ { 0, 0 }, { 0, 1 }, { 1, 0 } },
{ { 5, -2 }, { -3, -2 }, { -2, 5 }, { 1, 6 }, { 0, 2 } }}
papply(tests,welzl)</lang>
{{out}}
7,794

edits