Circles of given radius through two points: Difference between revisions
Content deleted Content added
Updated D entry |
→{{header|Maxima}}: add a solution |
||
Line 167:
└───────────────────────────────┴────────────────────────────────────────────────────┘
</lang>
=={{header|Maxima}}==
<lang Maxima>/* define helper function */
vabs(a):= sqrt(a.a);
realp(e):=freeof(%i, e);
/* get a general solution */
sol: block(
[p1: [x1, y1], p2: [x2, y2], c: [x0, y0], eq],
local(r),
eq: [vabs(p1-c) = r, vabs(p2-c) = r],
load(to_poly_solve),
assume(r>0),
args(to_poly_solve(eq, c, use_grobner = true)))$
/* use general solution for concrete case */
getsol(sol, x1, y1, x2, y2, r):=block([n, lsol],
if [x1, y1]=[x2, y2] then (
print("infinity many solutions"),
return('infmany)),
lsol: sublist(''sol, 'realp),
n: length(lsol),
if n=0 then (
print("no solutions"),
[])
else if n=1 then (
print("single solution"),
lsol[1])
else if [assoc('x0, lsol[1]), assoc('y0, lsol[1])]=[assoc('x0, lsol[2]), assoc('y0, lsol[2])] then (
print("single solution"),
lsol[1])
else (
print("two solutions"),
lsol))$
/* [x1, y1, x2, y2, r] */
d[1]: [0.1234, 0.9876, 0.8765, 0.2345, 2];
d[2]: [0.0000, 2.0000, 0.0000, 0.0000, 1];
d[3]: [0, 0, 0, 1, 0.4];
d[4]: [0, 0, 0, 0, 0.4];
apply('getsol, cons(sol, d[1]));
apply('getsol, cons(sol, d[2]));
apply('getsol, cons(sol, d[3]));
apply('getsol, cons(sol, d[4]));</lang>
Output:
<lang>apply('getsol, cons(sol, d[1]));
two solutions
(%o9) [[x0 = 1.86311180165819, y0 = 1.974211801658189],
[x0 = - 0.86321180165819, y0 = - 0.75211180165819]]
(%i10) apply('getsol, cons(sol, d[2]));
single solution
(%o10) [x0 = 0.0, y0 = 1.0]
(%i11) apply('getsol, cons(sol, d[3]));
no solutions
(%o11) []
(%i12) apply('getsol, cons(sol, d[4]));
infinity many solutions
(%o12) infmany</lang>
=={{header|PL/I}}==
|