comparison 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
comparison
equal deleted inserted replaced
1914:e7f8d11c4670 1915:c003685d9926
1 ###
2 # Geometry
3 ###
4
5 abstract type Curve end
6 abstract type Surface end
7
8
9 struct Line{PT} <: Curve
10 p::PT
11 tangent::PT
12 end
13
14 (c::Line)(s) = c.p + s*c.tangent
15
16
17 struct LineSegment{PT} <: Curve
18 a::PT
19 b::PT
20 end
21
22 (c::LineSegment)(s) = (1-s)*c.a + s*c.b
23
24
25 function linesegments(ps...)
26 return [LineSegment(ps[i], ps[i+1]) for i ∈ 1:length(ps)-1]
27 end
28
29
30 function polygon_edges(ps...)
31 n = length(ps)
32 return [LineSegment(ps[i], ps[mod1(i+1,n)]) for i ∈ eachindex(ps)]
33 end
34
35 struct Circle{T,PT} <: Curve
36 c::PT
37 r::T
38 end
39
40 function (C::Circle)(θ)
41 (;c, r) = C
42 c + r*@SVector[cos(θ), sin(θ)]
43 end
44
45 struct TransfiniteInterpolationSurface{T1,T2,T3,T4} <: Surface
46 c₁::T1
47 c₂::T2
48 c₃::T3
49 c₄::T4
50 end
51
52 function (s::TransfiniteInterpolationSurface)(u,v)
53 c₁, c₂, c₃, c₄ = s.c₁, s.c₂, s.c₃, s.c₄
54 P₀₀ = c₁(0)
55 P₁₀ = c₂(0)
56 P₁₁ = c₃(0)
57 P₀₁ = c₄(0)
58 return (1-v)*c₁(u) + u*c₂(v) + v*c₃(1-u) + (1-u)*c₄(1-v) - (
59 (1-u)*(1-v)*P₀₀ + u*(1-v)*P₁₀ + u*v*P₁₁ + (1-u)*v*P₀₁
60 )
61 end
62
63 function (s::TransfiniteInterpolationSurface)(ξ̄::AbstractArray)
64 s(ξ̄...)
65 end
66
67 # TODO: Implement jacobian() for the different mapping helpers