/* given 3 line-lengths, construct a triangle */ /* Calculate triangle apex with intersecting circles */ hyp_s : 5$ long_s : 4$ short_s : 3$ load('newton1)$ kill(t)$ /* remove value; symbol used by newton() */ /* Discover one angle of triangle by Newton's method */ t : newton(cos(t)*long_s+sin(t)*short_s-hyp_s, t, .7, 1E-6)$ k : [[0, 0], [hyp_s, 0], [cos(t)*long_s, sin(t)*long_s], [0, 0]]$ kill(t)$ /* remove value; for [parametric] */ plot2d([ [discrete, k], [parametric, cos(t)*long_s, sin(t)*long_s, [t, 0, 2*%pi]], [parametric, cos(t)*short_s+hyp_s, sin(t)*short_s, [t, 0, 2*%pi]] ], [legend, "triangle", concat("r = ", long_s), concat("r = ", short_s)], [color, green, red, blue], [y, -1 - long_s, 1 + long_s], same_xy); hyp_s : 5$ long_s : 4$ short_s : 3$ /* Discover angle by dividing into 2 right triangles, then trigonometry */ answ : linsolve([ long_s / hyp_s - x / long_s, /* cosine; x, unknown 'long' */ short_s / hyp_s - height / long_s, /* sine; height, unknown 'short' */ short_s / long_s - height / x /* tangent; long_s, known hypotenuse */ ], [x, height])$ k : [[0, 0], [hyp_s, 0], [subst(answ[1], x), subst(answ[2], height)], [0, 0]]$ draw2d (yrange=[-1 - long_s, 1 + long_s], proportional_axes='xy, points_joined=true, point_type=none, color=green, key="triangle", points(k), nticks=300, color=red, key=concat(" r = ", long_s), parametric(cos(t)*long_s, sin(t)*long_s, t, 0, 2*%pi), color=blue, key=concat(" r = ", short_s), parametric(cos(t)*short_s+hyp_s, sin(t)*short_s, t, 0, 2*%pi) );