Created
November 21, 2022 01:41
-
-
Save jdh30/48b4375c26cf3ed8beabdc94e53ac7cc to your computer and use it in GitHub Desktop.
Circle from 3 points
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let det₃((a₁₁,a₁₂,a₁₃),(a₂₁,a₂₂,a₂₃),(a₃₁,a₃₂,a₃₃)) = | |
-a₁₃*a₂₂*a₃₁ + a₁₂*a₂₃*a₃₁ + a₁₃*a₂₁*a₃₂ - | |
a₁₁*a₂₃*a₃₂ - a₁₂*a₂₁*a₃₃ + a₁₁*a₂₂*a₃₃ | |
let createCircle ((x₁, y₁), (x₂, y₂), (x₃, y₃)) = | |
let a = det₃((x₁, y₁, 1), (x₂, y₂, 1), (x₃, y₃, 1)) in | |
let d = -det₃((sqr x₁ + sqr y₁, y₁, 1), (sqr x₂ + sqr y₂, y₂, 1), (sqr x₃ + sqr y₃, y₃, 1)) in | |
let e = det₃((sqr x₁ + sqr y₁, x₁, 1), (sqr x₂ + sqr y₂, x₂, 1), (sqr x₃ + sqr y₃, x₃, 1)) in | |
let f = -det₃((sqr x₁ + sqr y₁, x₁, y₁), (sqr x₂ + sqr y₂, x₂, y₂), (sqr x₃ + sqr y₃, x₃, y₃)) in | |
let r = (sqr d + sqr e)/(4 * sqr a) - f/a @ sqrt in | |
Circle((-d/(2*a), -e/(2*a)), r) | |
let () = | |
let p₁, p₂, p₃ = ((150, 100), (350, 200), (300, 50)) in | |
let geometry = createCircle (p₁, p₂, p₃) in | |
{p₁; p₂; p₃} | |
@ Array.map [p -> Shape(Style(Fill White, Stroke(Black, 3)), Circle(p, 5))] | |
@ Array.prepend (Shape(Style(Fill Red, Stroke(Black, 3)), geometry)) | |
@ Html.ofSvg (600, 300) | |
@ yield |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment