Mercurial > repos > public > sbplib_julia
diff src/Grids/geometry.jl @ 2012:4617e4b74b82 feature/grids/geometry_functions
Add arc() for constructing circle arcs between two points
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 07 May 2025 08:39:06 +0200 |
parents | d0b6c63c506e |
children | 7895b509f9bf |
line wrap: on
line diff
--- a/src/Grids/geometry.jl Wed May 07 08:38:35 2025 +0200 +++ b/src/Grids/geometry.jl Wed May 07 08:39:06 2025 +0200 @@ -181,6 +181,40 @@ return nothing end + +""" + arc(a,b,r) + +# TODO +""" +function arc(a,b,r) + if abs(r) < norm(b-a)/2 + throw(DomainError(r, "arc was called with radius r = $r smaller than half the distance between the points.")) + end + + R̂ = @SMatrix[0 -1; 1 0] + + α = sign(r)*√(r^2 - norm((b-a)/2)^2) + t̂ = R̂*(b-a)/norm(b-a) + + c = (a+b)/2 + α*t̂ + + ca = a-c + cb = b-c + θₐ = atan(ca[2],ca[1]) + θᵦ = atan(cb[2],cb[1]) + + Δθ = mod(θᵦ-θₐ+π, 2π)-π # Δθ in the interval (-π,π) + + if r > 0 + Δθ = abs(Δθ) + else + Δθ = -abs(Δθ) + end + + return Arc(Circle(c,abs(r)), θₐ, θₐ+Δθ) +end + """ TransfiniteInterpolationSurface(c₁, c₂, c₃, c₄)