Circles of given radius through two points: Difference between revisions
Content deleted Content added
adding lambdatalk |
m lambdatalk minor edit |
||
Line 1,885:
=={{header|Lambdatalk}}==
<lang scheme>
input: OP1=(x1,y1), OP2=(x2,y2), r
output: OC = OH + HC
where OH = (OP1+OP2)/2
and HC = j*|HC|
where j is the unit vector rotated -90° from P1P2
and |HC| = √(r^2 - (|P1P2|/2)^2) if exists
{def circleby2points
{lambda {:x1 :y1 :x2 :y2 :r}
Line 1,892 ⟶ 1,899:
then same points
else {let { {:r :r}
{:
{:hx {/ {+ :x1 :x2} 2}} {:hy {/ {+ :y1 :y2} 2}} } // h = OH
{let { {:r :r} {:
{:
{if {> :
then no circle, points are too far apart
else {if {= :
then one circle: opposite ends of diameter with centre (:hx,:hy)
else {let { {:r :r} {:hx :hx} {:hy :hy} // closure
{:jx {- {/ :
{:d {sqrt {- {* :r :r} {/ {* :
two circles: {br}({
{br}({
}}}}}}}}}
{circleby2points -1 0 1 0 0.5}
-> no circle:
points are too far apart
{circleby2points -1 0 1 0 1}
-> one circle:
opposite ends of diameter with centre (0,0)
{circleby2points -1 0 1 0 {sqrt 2}}
-> two circles:
(0,1.0000000000000002)
(0,-1.0000000000000002)
rosetta's task:
{circleby2points 0.1234 0.9876 0.8765 0.2345 2.0}
|