Curve that touches three points: Difference between revisions

Content added Content deleted
Line 61: Line 61:
=={{header|Julia}}==
=={{header|Julia}}==
To make things more specific, find the circle determined by the points. The curve is then the arc between the 3 points.
To make things more specific, find the circle determined by the points. The curve is then the arc between the 3 points.
<lang julia>using Makie
<lang julia>using Luxor # Luxor has the library function center3pts() for this, but no library functions per task, so matrix math it is.


struct Point; x::Float64; y::Float64; end
# Find a circle passing through the 3 points
# Find a circle passing through the 3 points
const p1 = Point(10, 10)
const p1 = Point(10, 10)
Line 83: Line 84:
println("The circle with center at x = $a, y = $b and radius $r.")
println("The circle with center at x = $a, y = $b and radius $r.")


x = a-r:0.25:a+r
# draw it (produces a PNG file by default).
y0 = sqrt.(r^2 .- (x .- a).^2)
Drawing()
scene = lines(x, y0 .+ b)
origin()
lines!(scene, x, b .- y0)
sethue("red")
scatter!(scene, [p.x for p in allp], [p.y for p in allp])
circle(Point(a, b), r, :stroke)
sethue("black")
foreach(p -> circle(p, 5, :fill), allp)
finish()
</lang>{{out}}
</lang>{{out}}
<pre>
<pre>