How to resolve the algorithm Circles of given radius through two points step by step in the Lambdatalk programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Circles of given radius through two points step by step in the Lambdatalk programming language
Table of Contents
Problem Statement
Given two points on a plane and a radius, usually two circles of given radius can be drawn through the points.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Circles of given radius through two points step by step in the Lambdatalk programming language
Source code in the lambdatalk programming language
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}
{if {= :r 0}
then radius is zero
else {if {and {= :x1 :x2} {= :y1 :y2}}
then same points
else {let { {:r :r}
{:vx {- :x2 :x1}} {:vy {- :y2 :y1}} // v = P1P2
{:hx {/ {+ :x1 :x2} 2}} {:hy {/ {+ :y1 :y2} 2}} } // h = OH
{let { {:r :r} {:vx :vx} {:vy :vy} {:hx :hx} {:hy :hy} // closure
{:d {sqrt {+ {* :px :px} {* :py :py}}} } } // d = |P1P2|
{if {> :d {* 2 :r}} // d > diam
then no circle, points are too far apart
else {if {= :d {* 2 :r}} // d = diam
then one circle: opposite ends of diameter with centre (:hx,:hy)
else {let { {:r :r} {:hx :hx} {:hy :hy} // closure
{:jx {- {/ :vy :d}}} {:jy {/ :vx :d}} // j unit -90° to P1P2
{:d {sqrt {- {* :r :r} {/ {* :d :d} 4}}}} } // |HC|
two circles: {br}({+ :hx {* :d :jx}},{+ :hy {* :d :jy}}) // OH + j*|HC|
{br}({- :hx {* :d :jx}},{- :hy {* :d :jy}}) // OH - j*|HC|
}}}}}}}}}
{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}
-> two circles:
(1.8631118016581893,1.974211801658189)
(-0.8632118016581896,-0.7521118016581892)
{circleby2points 0.0000 2.0000 0.0000 0.0000 1.0}
-> one circle: opposite ends of diameter with centre (0,1)
{circleby2points 0.1234 0.9876 0.1234 0.9876 2.0}
-> same points
{circleby2points 0.1234 0.9876 0.8765 0.2345 0.5}
-> no circle, points are too far apart
{circleby2points 0.1234 0.9876 0.1234 0.9876 0.0}
-> radius is zero
You may also check:How to resolve the algorithm Sockets step by step in the Sidef programming language
You may also check:How to resolve the algorithm Literals/Integer step by step in the Rust programming language
You may also check:How to resolve the algorithm Non-decimal radices/Input step by step in the Julia programming language
You may also check:How to resolve the algorithm Text processing/1 step by step in the COBOL programming language
You may also check:How to resolve the algorithm HTTPS step by step in the R programming language