comparison src/Grids/geometry.jl @ 2037:e1ce0697caf5 feature/sbp_operators/laplace_curvilinear

Merge feature/grids/geometry_functions
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 04 Feb 2026 09:44:55 +0100
parents 6478c29effce
children 00b274a118e0
comparison
equal deleted inserted replaced
2003:524a52f190d7 2037:e1ce0697caf5
151 end 151 end
152 152
153 function Grids.jacobian(C::Circle, θ) 153 function Grids.jacobian(C::Circle, θ)
154 (;r) = C 154 (;r) = C
155 r*@SVector[-sin(θ), cos(θ)] 155 r*@SVector[-sin(θ), cos(θ)]
156 end
157
158 struct Arc{PT,T}
159 c::Circle{PT,T}
160 θ₀::T
161 θ₁::T
162 end
163
164 """
165 Arc(C::Circle, θ₀, θ₁)
166
167 A circular arc as a callable object. The arc is around the circle `C` between
168 angles `θ₀` and `θ₁` and is paramatrized between 0 and 1.
169
170 See also: [`arc`](@ref), [`Circle`](@ref).
171 """
172 function Arc(C, θ₀, θ₁)
173 r, θ₀, θ₁ = promote(C.r, θ₀, θ₁)
174
175 return Arc(Circle(C.c, r), θ₀, θ₁)
176 end
177
178 function (A::Arc)(t)
179 (; θ₀, θ₁) = A
180 return A.c((1-t)*θ₀ + t*θ₁)
181 end
182
183 function Grids.jacobian(A::Arc, t)
184 (;c, θ₀, θ₁) = A
185 return (θ₁-θ₀)*jacobian(c, t)
186 end
187
188
189 """
190 arc(a,b,r)
191
192 A circular arc between the points `a` and `b` with radius `abs(r)`. If `r > 0`
193 the arc goes counter clockwise and if `r<0` the arc goes clockwise. The arc is
194 parametrized such that if `A = arc(a,b,r)` then `A(0)` corresponds to `a` and
195 `A(1)` to `b`.
196
197 See also: [`Arc`](@ref), [`Circle`](@ref).
198 """
199 function arc(a,b,r)
200 if abs(r) < norm(b-a)/2
201 throw(DomainError(r, "arc was called with radius r = $r smaller than half the distance between the points."))
202 end
203
204 R̂ = @SMatrix[0 -1; 1 0]
205
206 α = sign(r)*√(r^2 - norm((b-a)/2)^2)
207 t̂ = R̂*(b-a)/norm(b-a)
208
209 c = (a+b)/2 + α*t̂
210
211 ca = a-c
212 cb = b-c
213 θₐ = atan(ca[2],ca[1])
214 θᵦ = atan(cb[2],cb[1])
215
216 Δθ = mod(θᵦ-θₐ+π, 2π)-π # Δθ in the interval (-π,π)
217
218 if r > 0
219 Δθ = abs(Δθ)
220 else
221 Δθ = -abs(Δθ)
222 end
223
224 return Arc(Circle(c,abs(r)), θₐ, θₐ+Δθ)
156 end 225 end
157 226
158 """ 227 """
159 TransfiniteInterpolationSurface(c₁, c₂, c₃, c₄) 228 TransfiniteInterpolationSurface(c₁, c₂, c₃, c₄)
160 229