comparison src/Grids/parameter_space.jl @ 1992:ca6d898d3a38 feature/grids/parameter_spaces/in

Implement Base.in(x, ::Simplex)
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 24 Apr 2025 09:23:12 +0200
parents 7ead7a87af18
children 2912975ddc2f
comparison
equal deleted inserted replaced
1991:7ead7a87af18 1992:ca6d898d3a38
163 T = SVector{length(verticies[1]),ET} 163 T = SVector{length(verticies[1]),ET}
164 164
165 return Simplex(Tuple(convert(T,v) for v ∈ verticies)) 165 return Simplex(Tuple(convert(T,v) for v ∈ verticies))
166 end 166 end
167 167
168
169 function Base.in(x, s::Simplex)
170 v₁ = s.verticies[1]
171 V = map(s.verticies) do v
172 v - v₁
173 end
174
175 A = hcat(V[2:end]...) # matrix with edge vectors as columns
176 b = x - v₁
177
178 # Solve Aλ = b
179 λ = A \ b
180
181 # Compute full barycentric coordinates: first is 1 - sum(λ), then λ
182 λ_full = (1 - sum(λ), λ...) # Tuple of length NV
183
184 all(λᵢ -> zero(λᵢ) ≤ λᵢ ≤ one(λᵢ), λ_full)
185 end
186
187
168 """ 188 """
169 verticies(s::Simplex) 189 verticies(s::Simplex)
170 190
171 Verticies of `s`. 191 Verticies of `s`.
172 """ 192 """