Original Post : https://forums.cgsociety.org/t/how-to-create-a-arc-through-3-points-with…
(
local p1 = point pos:[0,0,0], p2 = point pos:[20,80,0], p3 = point pos:[100,100,0]
local a = p1.pos, b = p2.pos, c = p3.pos
fn intersection2d p1 r1 p2 r2 = (
local dx = p2.x - p1.x, dy = p2.y - p1.y,
det = r2.x * r1.y - r2.y * r1.x
p1 + r1 * (dy * r2.x - dx * r2.y) / det
)
fn Make_Arc a b c ccw:false = (
local ab = b - a, bc = c - b, mab = a + 0.5 * ab, mbc = b + 0.5 * bc,
ab = normalize ab; bc = normalize bc
if dot ab bc == 1.0 then ( -- draw line if the points are at the same line
local sp = splineshape(), sl = addnewSpline sp
addKnot sp sl #Corner #line a; addKnot sp sl #Corner #line c
updateShape sp ; CenterPivot sp
)
else (
local r1 = [-ab.y, ab.x, ab.z], r2 = [-bc.y, bc.x, bc.z],
p = intersection2d mab r1 mbc r2, r = distance p a,
atc = atan2 (p.y - c.y) (p.x - c.x), ata = atan2 (p.y - a.y) (p.x - a.x)
if ccw then (atc2 = ata ; ata = atc ; atc = atc2)
arc radius:r pos:p from:(180 + atc) to:(180 + ata)
)
)
Make_Arc a b c
-- Make_Arc a b c ccw:true -- in case of arc is inversed points order is ccw
clearListener()
)