Mercurial > repos > public > sbplib_julia
comparison 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 |
comparison
equal
deleted
inserted
replaced
2011:d0b6c63c506e | 2012:4617e4b74b82 |
---|---|
177 return A.c((1-t)*θ₀ + t*θ₁) | 177 return A.c((1-t)*θ₀ + t*θ₁) |
178 end | 178 end |
179 | 179 |
180 function Grids.jacobian(a::Arc, t) | 180 function Grids.jacobian(a::Arc, t) |
181 return nothing | 181 return nothing |
182 end | |
183 | |
184 | |
185 """ | |
186 arc(a,b,r) | |
187 | |
188 # TODO | |
189 """ | |
190 function arc(a,b,r) | |
191 if abs(r) < norm(b-a)/2 | |
192 throw(DomainError(r, "arc was called with radius r = $r smaller than half the distance between the points.")) | |
193 end | |
194 | |
195 R̂ = @SMatrix[0 -1; 1 0] | |
196 | |
197 α = sign(r)*√(r^2 - norm((b-a)/2)^2) | |
198 t̂ = R̂*(b-a)/norm(b-a) | |
199 | |
200 c = (a+b)/2 + α*t̂ | |
201 | |
202 ca = a-c | |
203 cb = b-c | |
204 θₐ = atan(ca[2],ca[1]) | |
205 θᵦ = atan(cb[2],cb[1]) | |
206 | |
207 Δθ = mod(θᵦ-θₐ+π, 2π)-π # Δθ in the interval (-π,π) | |
208 | |
209 if r > 0 | |
210 Δθ = abs(Δθ) | |
211 else | |
212 Δθ = -abs(Δθ) | |
213 end | |
214 | |
215 return Arc(Circle(c,abs(r)), θₐ, θₐ+Δθ) | |
182 end | 216 end |
183 | 217 |
184 """ | 218 """ |
185 TransfiniteInterpolationSurface(c₁, c₂, c₃, c₄) | 219 TransfiniteInterpolationSurface(c₁, c₂, c₃, c₄) |
186 | 220 |