Mercurial > repos > public > sbplib_julia
diff src/Grids/geometry.jl @ 1915:c003685d9926 feature/grids/geometry_functions
Add geometry functions removed from feature/grids/manifolds
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 03 Feb 2025 15:43:00 +0100 |
parents | |
children | 6859089b361e |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Grids/geometry.jl Mon Feb 03 15:43:00 2025 +0100 @@ -0,0 +1,67 @@ +### +# Geometry +### + +abstract type Curve end +abstract type Surface end + + +struct Line{PT} <: Curve + p::PT + tangent::PT +end + +(c::Line)(s) = c.p + s*c.tangent + + +struct LineSegment{PT} <: Curve + a::PT + b::PT +end + +(c::LineSegment)(s) = (1-s)*c.a + s*c.b + + +function linesegments(ps...) + return [LineSegment(ps[i], ps[i+1]) for i ∈ 1:length(ps)-1] +end + + +function polygon_edges(ps...) + n = length(ps) + return [LineSegment(ps[i], ps[mod1(i+1,n)]) for i ∈ eachindex(ps)] +end + +struct Circle{T,PT} <: Curve + c::PT + r::T +end + +function (C::Circle)(θ) + (;c, r) = C + c + r*@SVector[cos(θ), sin(θ)] +end + +struct TransfiniteInterpolationSurface{T1,T2,T3,T4} <: Surface + c₁::T1 + c₂::T2 + c₃::T3 + c₄::T4 +end + +function (s::TransfiniteInterpolationSurface)(u,v) + c₁, c₂, c₃, c₄ = s.c₁, s.c₂, s.c₃, s.c₄ + P₀₀ = c₁(0) + P₁₀ = c₂(0) + P₁₁ = c₃(0) + P₀₁ = c₄(0) + return (1-v)*c₁(u) + u*c₂(v) + v*c₃(1-u) + (1-u)*c₄(1-v) - ( + (1-u)*(1-v)*P₀₀ + u*(1-v)*P₁₀ + u*v*P₁₁ + (1-u)*v*P₀₁ + ) +end + +function (s::TransfiniteInterpolationSurface)(ξ̄::AbstractArray) + s(ξ̄...) +end + +# TODO: Implement jacobian() for the different mapping helpers