From 1cd7ed657e0ff52861a19eb0db317651943976e8 Mon Sep 17 00:00:00 2001 From: PaulOlyslager Date: Wed, 25 Oct 2023 17:13:27 +0200 Subject: [PATCH 01/13] possible to permute vertices of triangle without changing the normal, tangents change --- Project.toml | 1 + src/charts.jl | 7 ++++++- src/neighborhood.jl | 12 ++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 924ca74..5a09f6a 100644 --- a/Project.toml +++ b/Project.toml @@ -13,6 +13,7 @@ FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838" GmshTools = "82e2f556-b1bd-5f1a-9576-f93c0da5f0ee" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Requires = "ae029012-a4dd-5104-9daa-d747884805df" +Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" diff --git a/src/charts.jl b/src/charts.jl index 03d8ccd..e631eaa 100644 --- a/src/charts.jl +++ b/src/charts.jl @@ -12,9 +12,14 @@ struct Simplex{U,D,C,N,T} normals::SVector{C,SVector{U,T}} volume::T end - +normal(t::Simplex{3,2,1,3,<:Number}) = t.normals[1] dimtype(splx::Simplex{U,D}) where {U,D} = Val{D} +function permute_vertices(s::Simplex{3,2,1,3,<:Number},permutation::Union{Vector{3,Int},SVector{3,Int}}) +vert = vertices(s)[permutation] +simp = simplex(vert) +Simplex(vertics(simp),tangents(simp),s.normals,volume(simp)) +end """ coordtype(simplex) diff --git a/src/neighborhood.jl b/src/neighborhood.jl index e107e2c..e48f0c0 100644 --- a/src/neighborhood.jl +++ b/src/neighborhood.jl @@ -80,3 +80,15 @@ to parameter `(1/(D+1), 1/(D+1), ...)` where `D` is the simplex dimension. uv = ones(T,D)/(D+1) :(neighborhood(p, $uv)) end + +function permute_barycentric(perm,bary::Tuple{T,T}) where {T} + last_coef = 1-sum(bary) + total_bary = SVector{3,T}([bary[1],bary[2],last_coef]) + return Tuple{T,T}(total_bary[perm][1:end-1]) +end +function permute_barycentric(perm,bary::Tuple{T,T,T}) where {T} + last_coef = 1-sum(bary) + total_bary = SVector{4,T}([bary[1],bary[2],bary[3],last_coef]) + return Tuple{T,T,T}(total_bary[perm][1:end-1]) +end +export permute_barycentric From 4884d5673ef7ddafc2d85f2984e9ae1ad559d391 Mon Sep 17 00:00:00 2001 From: PaulOlyslager Date: Thu, 26 Oct 2023 13:57:32 +0200 Subject: [PATCH 02/13] normal decoupled from chart, possible to keep orientation when vertices are permuted. function added to do find the barycentric permutation for a given vertex permutation --- src/charts.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/charts.jl b/src/charts.jl index e631eaa..c808157 100644 --- a/src/charts.jl +++ b/src/charts.jl @@ -15,10 +15,10 @@ end normal(t::Simplex{3,2,1,3,<:Number}) = t.normals[1] dimtype(splx::Simplex{U,D}) where {U,D} = Val{D} -function permute_vertices(s::Simplex{3,2,1,3,<:Number},permutation::Union{Vector{3,Int},SVector{3,Int}}) -vert = vertices(s)[permutation] +function permute_vertices(s::Simplex{3,2,1,3,T},permutation::Union{Vector{P},SVector{P}}) where {T,P} +vert = SVector{3,SVector{3,T}}(s.vertices[permutation]) simp = simplex(vert) -Simplex(vertics(simp),tangents(simp),s.normals,volume(simp)) +Simplex(simp.vertices,simp.tangents,s.normals,simp.volume) end """ From 9d1b7ee0196850044435ae2d4c4079f9d93e95dd Mon Sep 17 00:00:00 2001 From: PaulOlyslager Date: Thu, 26 Oct 2023 16:04:04 +0200 Subject: [PATCH 03/13] possible to flip the normal --- src/charts.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/charts.jl b/src/charts.jl index c808157..86f4f3f 100644 --- a/src/charts.jl +++ b/src/charts.jl @@ -20,6 +20,7 @@ vert = SVector{3,SVector{3,T}}(s.vertices[permutation]) simp = simplex(vert) Simplex(simp.vertices,simp.tangents,s.normals,simp.volume) end +flip_normal(t::Simplex{3,2,1,3,<:Number}) = Simplex(t.vertices,t.tangents,-t.normals,t.volume) """ coordtype(simplex) From e4f036de9acb9c7c9475e8513a1c18f96148a5dc Mon Sep 17 00:00:00 2001 From: PaulOlyslager Date: Fri, 27 Oct 2023 17:08:17 +0200 Subject: [PATCH 04/13] decouple normal from Simplex{3,2,1,3,.} --- src/charts.jl | 10 ++++++++-- src/intersect.jl | 4 +++- src/mesh.jl | 4 ++-- src/quadpoints.jl | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/charts.jl b/src/charts.jl index 86f4f3f..3447505 100644 --- a/src/charts.jl +++ b/src/charts.jl @@ -21,7 +21,11 @@ simp = simplex(vert) Simplex(simp.vertices,simp.tangents,s.normals,simp.volume) end flip_normal(t::Simplex{3,2,1,3,<:Number}) = Simplex(t.vertices,t.tangents,-t.normals,t.volume) - +function flip_normal(t::Simplex{3,2,1,3,<:Number},sign::Int) +sign == 1 && return t +return flip_normal(t) +end +export flip_normal """ coordtype(simplex) @@ -347,4 +351,6 @@ Returns a matrix whose columns are the tangents of the simplex `splx`. """ tangents(splx::Simplex) = hcat((splx.tangents)...) -vertices(splx::Simplex) = hcat((splx.vertices)...) \ No newline at end of file +vertices(splx::Simplex) = hcat((splx.vertices)...) +verticeslist(splx::Simplex) = splx.vertices +export verticeslist \ No newline at end of file diff --git a/src/intersect.jl b/src/intersect.jl index 92cd380..54cdb00 100644 --- a/src/intersect.jl +++ b/src/intersect.jl @@ -36,7 +36,9 @@ The output inherits the orientation from the first operand """ function intersection(p1::Simplex{U,2,C,3}, p2::Simplex{U,2,C,3}) where {U,C} pq = sutherlandhodgman(p1.vertices, p2.vertices) - [ simplex(pq[1], pq[i], pq[i+1]) for i in 2:length(pq)-1 ] + nonoriented_simplexes = [ simplex(pq[1], pq[i], pq[i+1]) for i in 2:length(pq)-1 ] + signs = Int.(sign.(dot.(normal.(nonoriented_simplexes,Ref(normal(p1)))))) + flip_normal.(nonoriented_simplexes,signs) end diff --git a/src/mesh.jl b/src/mesh.jl index eea46ff..5a43d59 100644 --- a/src/mesh.jl +++ b/src/mesh.jl @@ -139,7 +139,7 @@ or vertices not appearing in any cell. In other words the following is not neces numvertices(mesh) == numcells(skeleton(mesh,0)) ``` """ -numvertices(m::Mesh) = length(m.vertices) +numvertices(m::Mesh) = length(vertices(m)) @@ -148,7 +148,7 @@ numvertices(m::Mesh) = length(m.vertices) Returns the number of cells in the mesh. """ -numcells(m::AbstractMesh) = length(m.faces) +numcells(m::AbstractMesh) = length(cells(m)) diff --git a/src/quadpoints.jl b/src/quadpoints.jl index 1b54e07..e9ae71d 100644 --- a/src/quadpoints.jl +++ b/src/quadpoints.jl @@ -80,7 +80,7 @@ this method used `quadpoints(chart, rule)` to retrieve the points and weights fo a certain quadrature rule over `chart`. """ function quadpoints(f, charts, rules) - + println(typeof(charts)) pw = quadpoints(charts[1], rules[1]) P = typeof(pw[1][1]) W = typeof(pw[1][2]) From 7b8c1782342e92038cd6cec3ad8d3f1bcfe33f5d Mon Sep 17 00:00:00 2001 From: PaulOlyslager Date: Mon, 30 Oct 2023 15:27:56 +0100 Subject: [PATCH 05/13] Made intersection2 function which returns chart with respect to both normals, made it possible to get tangent of chart, check in intersection if triangle is non empty, brought quadpoints back to original state, wrote function verticeslist wich gives vertices in array --- src/charts.jl | 8 +++++--- src/intersect.jl | 18 ++++++++++++++++-- src/quadpoints.jl | 1 - src/subd_chart.jl | 1 + 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/charts.jl b/src/charts.jl index 3447505..7e4dfeb 100644 --- a/src/charts.jl +++ b/src/charts.jl @@ -22,10 +22,12 @@ Simplex(simp.vertices,simp.tangents,s.normals,simp.volume) end flip_normal(t::Simplex{3,2,1,3,<:Number}) = Simplex(t.vertices,t.tangents,-t.normals,t.volume) function flip_normal(t::Simplex{3,2,1,3,<:Number},sign::Int) -sign == 1 && return t -return flip_normal(t) -end + sign == 1 && return t + return flip_normal(t) + end export flip_normal + +tangents(s::Simplex{3,2,1,3,<:Number},i) = s.tangents[i] """ coordtype(simplex) diff --git a/src/intersect.jl b/src/intersect.jl index 54cdb00..f7ab13b 100644 --- a/src/intersect.jl +++ b/src/intersect.jl @@ -34,9 +34,10 @@ end The output inherits the orientation from the first operand """ -function intersection(p1::Simplex{U,2,C,3}, p2::Simplex{U,2,C,3}) where {U,C} +function intersection(p1::Simplex{U,2,C,3}, p2::Simplex{U,2,C,3};tol=eps()) where {U,C} pq = sutherlandhodgman(p1.vertices, p2.vertices) nonoriented_simplexes = [ simplex(pq[1], pq[i], pq[i+1]) for i in 2:length(pq)-1 ] + nonoriented_simplexes = nonoriented_simplexes[volume.(nonoriented_simplexes).>tol] signs = Int.(sign.(dot.(normal.(nonoriented_simplexes,Ref(normal(p1)))))) flip_normal.(nonoriented_simplexes,signs) end @@ -47,8 +48,21 @@ function intersection(p1::Simplex{U,3,C,4}, p2::Simplex{U,3,C,4}) where {U,C} volume(p1) <= volume(p2) ? [p1] : [p2] end +function intersection2(p1::Simplex, p2::Simplex) where {U,C} + a = intersection(p1,p2) + return [(i,i) for i in a] +end - +function intersection2(p1::Simplex{U,2,C,3}, p2::Simplex{U,2,C,3}; tol=eps()) where {U,C} + pq = sutherlandhodgman(p1.vertices, p2.vertices) + nonoriented_simplexes = [ simplex(pq[1], pq[i], pq[i+1]) for i in 2:length(pq)-1 ] + nonoriented_simplexes = nonoriented_simplexes[volume.(nonoriented_simplexes).>tol] + signs1 = Int.(sign.(dot.(normal.(nonoriented_simplexes),Ref(normal(p1))))) + + signs2 = Int.(sign.(dot.(normal.(nonoriented_simplexes),Ref(normal(p2))))) + return [(flip_normal(s,signs1[i]),flip_normal(s,signs2[i])) for (i,s) in enumerate(nonoriented_simplexes)] +end +export intersection2 """ intersectline(a,b,p,q) diff --git a/src/quadpoints.jl b/src/quadpoints.jl index e9ae71d..3d789d1 100644 --- a/src/quadpoints.jl +++ b/src/quadpoints.jl @@ -80,7 +80,6 @@ this method used `quadpoints(chart, rule)` to retrieve the points and weights fo a certain quadrature rule over `chart`. """ function quadpoints(f, charts, rules) - println(typeof(charts)) pw = quadpoints(charts[1], rules[1]) P = typeof(pw[1][1]) W = typeof(pw[1][2]) diff --git a/src/subd_chart.jl b/src/subd_chart.jl index 351058c..bddf5af 100644 --- a/src/subd_chart.jl +++ b/src/subd_chart.jl @@ -30,3 +30,4 @@ function getelementVertices(chart::subd_chart{T}) where {T} verticecoords3[3] = verticescoords[chart.N-6] return verticecoords3 end +verticeslist(chart::subd_chart) = chart.vertices \ No newline at end of file From 289561679dde1b212c54cb6925867138fca65816 Mon Sep 17 00:00:00 2001 From: PaulOlyslager Date: Mon, 30 Oct 2023 15:31:58 +0100 Subject: [PATCH 06/13] fixed bug in intersection --- src/intersect.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/intersect.jl b/src/intersect.jl index f7ab13b..1f3704f 100644 --- a/src/intersect.jl +++ b/src/intersect.jl @@ -38,7 +38,7 @@ function intersection(p1::Simplex{U,2,C,3}, p2::Simplex{U,2,C,3};tol=eps()) wher pq = sutherlandhodgman(p1.vertices, p2.vertices) nonoriented_simplexes = [ simplex(pq[1], pq[i], pq[i+1]) for i in 2:length(pq)-1 ] nonoriented_simplexes = nonoriented_simplexes[volume.(nonoriented_simplexes).>tol] - signs = Int.(sign.(dot.(normal.(nonoriented_simplexes,Ref(normal(p1)))))) + signs = Int.(sign.(dot.(normal.(nonoriented_simplexes),Ref(normal(p1))))) flip_normal.(nonoriented_simplexes,signs) end From 054e8eb28e698c6df079beda4b63cd14b8e75b7a Mon Sep 17 00:00:00 2001 From: PaulOlyslager Date: Mon, 30 Oct 2023 15:44:29 +0100 Subject: [PATCH 07/13] fixed bug intersection --- src/intersect.jl | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/intersect.jl b/src/intersect.jl index 1f3704f..14fcb9c 100644 --- a/src/intersect.jl +++ b/src/intersect.jl @@ -34,13 +34,17 @@ end The output inherits the orientation from the first operand """ -function intersection(p1::Simplex{U,2,C,3}, p2::Simplex{U,2,C,3};tol=eps()) where {U,C} +function intersection(p1::Simplex{U,2,C,3}, p2::Simplex{U,2,C,3}) where {U,C} pq = sutherlandhodgman(p1.vertices, p2.vertices) - nonoriented_simplexes = [ simplex(pq[1], pq[i], pq[i+1]) for i in 2:length(pq)-1 ] - nonoriented_simplexes = nonoriented_simplexes[volume.(nonoriented_simplexes).>tol] - signs = Int.(sign.(dot.(normal.(nonoriented_simplexes),Ref(normal(p1))))) - flip_normal.(nonoriented_simplexes,signs) + return [ simplex(pq[1], pq[i], pq[i+1]) for i in 2:length(pq)-1 ] end +function intersection(p1::Simplex{3,2,1,3}, p2::Simplex{3,2,1,3};tol=eps()) where {U,C} + pq = sutherlandhodgman(p1.vertices, p2.vertices) + nonoriented_simplexes = [ simplex(pq[1], pq[i], pq[i+1]) for i in 2:length(pq)-1 ] + nonoriented_simplexes = nonoriented_simplexes[volume.(nonoriented_simplexes).>tol] + signs = Int.(sign.(dot.(normal.(nonoriented_simplexes),Ref(normal(p1))))) + flip_normal.(nonoriented_simplexes,signs) + end function intersection(p1::Simplex{U,3,C,4}, p2::Simplex{U,3,C,4}) where {U,C} @@ -53,7 +57,7 @@ function intersection2(p1::Simplex, p2::Simplex) where {U,C} return [(i,i) for i in a] end -function intersection2(p1::Simplex{U,2,C,3}, p2::Simplex{U,2,C,3}; tol=eps()) where {U,C} +function intersection2(p1::Simplex{3,2,1,3}, p2::Simplex{3,2,1,3}; tol=eps()) where {U,C} pq = sutherlandhodgman(p1.vertices, p2.vertices) nonoriented_simplexes = [ simplex(pq[1], pq[i], pq[i+1]) for i in 2:length(pq)-1 ] nonoriented_simplexes = nonoriented_simplexes[volume.(nonoriented_simplexes).>tol] From ff7cf213224448d33ade3f8ab43bc61baeb75695 Mon Sep 17 00:00:00 2001 From: PaulOlyslager Date: Mon, 30 Oct 2023 15:45:47 +0100 Subject: [PATCH 08/13] fixed warnings --- src/intersect.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/intersect.jl b/src/intersect.jl index 14fcb9c..a918cd6 100644 --- a/src/intersect.jl +++ b/src/intersect.jl @@ -38,7 +38,7 @@ function intersection(p1::Simplex{U,2,C,3}, p2::Simplex{U,2,C,3}) where {U,C} pq = sutherlandhodgman(p1.vertices, p2.vertices) return [ simplex(pq[1], pq[i], pq[i+1]) for i in 2:length(pq)-1 ] end -function intersection(p1::Simplex{3,2,1,3}, p2::Simplex{3,2,1,3};tol=eps()) where {U,C} +function intersection(p1::Simplex{3,2,1,3}, p2::Simplex{3,2,1,3};tol=eps()) pq = sutherlandhodgman(p1.vertices, p2.vertices) nonoriented_simplexes = [ simplex(pq[1], pq[i], pq[i+1]) for i in 2:length(pq)-1 ] nonoriented_simplexes = nonoriented_simplexes[volume.(nonoriented_simplexes).>tol] @@ -52,12 +52,12 @@ function intersection(p1::Simplex{U,3,C,4}, p2::Simplex{U,3,C,4}) where {U,C} volume(p1) <= volume(p2) ? [p1] : [p2] end -function intersection2(p1::Simplex, p2::Simplex) where {U,C} +function intersection2(p1::Simplex, p2::Simplex) a = intersection(p1,p2) return [(i,i) for i in a] end -function intersection2(p1::Simplex{3,2,1,3}, p2::Simplex{3,2,1,3}; tol=eps()) where {U,C} +function intersection2(p1::Simplex{3,2,1,3}, p2::Simplex{3,2,1,3}; tol=eps()) pq = sutherlandhodgman(p1.vertices, p2.vertices) nonoriented_simplexes = [ simplex(pq[1], pq[i], pq[i+1]) for i in 2:length(pq)-1 ] nonoriented_simplexes = nonoriented_simplexes[volume.(nonoriented_simplexes).>tol] From 5de2e8e7593006150a5fc362fa0168e528e83115 Mon Sep 17 00:00:00 2001 From: PaulOlyslager Date: Mon, 30 Oct 2023 18:25:06 +0100 Subject: [PATCH 09/13] update --- src/neighborhood.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/neighborhood.jl b/src/neighborhood.jl index e48f0c0..ae8aab6 100644 --- a/src/neighborhood.jl +++ b/src/neighborhood.jl @@ -26,7 +26,7 @@ function parametric(mp::MeshPointNM) mp.bary end -chart(nbd::MeshPointNM) = mp.patch +chart(nbd::MeshPointNM) = nbd.patch "Return the barycentric coordinates of `mp`" barycentric(mp::MeshPointNM) = SVector(mp.bary[1], mp.bary[2], 1-mp.bary[1]-mp.bary[2]) From 753adc6395cd8249b96e1ccf5d04441eb82d1448 Mon Sep 17 00:00:00 2001 From: PaulOlyslager Date: Tue, 7 Nov 2023 16:46:49 +0100 Subject: [PATCH 10/13] clean up --- src/charts.jl | 14 ++++++++++---- src/neighborhood.jl | 22 +++++++++++----------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/charts.jl b/src/charts.jl index 7e4dfeb..aa6965f 100644 --- a/src/charts.jl +++ b/src/charts.jl @@ -14,11 +14,17 @@ struct Simplex{U,D,C,N,T} end normal(t::Simplex{3,2,1,3,<:Number}) = t.normals[1] dimtype(splx::Simplex{U,D}) where {U,D} = Val{D} +""" + permute_simplex(simplex,permutation) + +Permutation is a Vector v which sets the v[i]-th vertex at the i-th place. +Return Simplex with permuted vertices list, tangents are recalculated, normal is kept the same +""" function permute_vertices(s::Simplex{3,2,1,3,T},permutation::Union{Vector{P},SVector{P}}) where {T,P} -vert = SVector{3,SVector{3,T}}(s.vertices[permutation]) -simp = simplex(vert) -Simplex(simp.vertices,simp.tangents,s.normals,simp.volume) + vert = SVector{3,SVector{3,T}}(s.vertices[permutation]) + simp = simplex(vert) + Simplex(simp.vertices,simp.tangents,s.normals,simp.volume) end flip_normal(t::Simplex{3,2,1,3,<:Number}) = Simplex(t.vertices,t.tangents,-t.normals,t.volume) function flip_normal(t::Simplex{3,2,1,3,<:Number},sign::Int) @@ -138,7 +144,7 @@ simplex(vertices...) = simplex(SVector((vertices...,))) :(simplex(SVector{$D1,$P}($xp))) end -normal(s::Simplex{3,2,1,3,T}) where {T} = normalize(cross(s[1]-s[3],s[2]-s[3])) +# normal(s::Simplex{3,2,1,3,T}) where {T} = normalize(cross(s[1]-s[3],s[2]-s[3])) function _normals(tangents, ::Type{Val{1}}) diff --git a/src/neighborhood.jl b/src/neighborhood.jl index ae8aab6..24eb02d 100644 --- a/src/neighborhood.jl +++ b/src/neighborhood.jl @@ -81,14 +81,14 @@ to parameter `(1/(D+1), 1/(D+1), ...)` where `D` is the simplex dimension. :(neighborhood(p, $uv)) end -function permute_barycentric(perm,bary::Tuple{T,T}) where {T} - last_coef = 1-sum(bary) - total_bary = SVector{3,T}([bary[1],bary[2],last_coef]) - return Tuple{T,T}(total_bary[perm][1:end-1]) -end -function permute_barycentric(perm,bary::Tuple{T,T,T}) where {T} - last_coef = 1-sum(bary) - total_bary = SVector{4,T}([bary[1],bary[2],bary[3],last_coef]) - return Tuple{T,T,T}(total_bary[perm][1:end-1]) -end -export permute_barycentric +# function permute_barycentric(perm,bary::Tuple{T,T}) where {T} +# last_coef = 1-sum(bary) +# total_bary = SVector{3,T}([bary[1],bary[2],last_coef]) +# return Tuple{T,T}(total_bary[perm][1:end-1]) +# end +# function permute_barycentric(perm,bary::Tuple{T,T,T}) where {T} +# last_coef = 1-sum(bary) +# total_bary = SVector{4,T}([bary[1],bary[2],bary[3],last_coef]) +# return Tuple{T,T,T}(total_bary[perm][1:end-1]) +# end +# export permute_barycentric From 81e950efb2245cb1431bed310048a3cf07e540d8 Mon Sep 17 00:00:00 2001 From: PaulOlyslager Date: Thu, 9 Nov 2023 09:47:35 +0100 Subject: [PATCH 11/13] documentation --- src/charts.jl | 18 ++++++++++++++++++ src/intersect.jl | 8 ++++++++ src/neighborhood.jl | 11 ----------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/charts.jl b/src/charts.jl index aa6965f..861f5ee 100644 --- a/src/charts.jl +++ b/src/charts.jl @@ -26,7 +26,19 @@ function permute_vertices(s::Simplex{3,2,1,3,T},permutation::Union{Vector{P},SVe simp = simplex(vert) Simplex(simp.vertices,simp.tangents,s.normals,simp.volume) end + +""" + flip_normal(simplex) + +Flips the normal of the simplex. Only on triangles embedded in 3D space +""" flip_normal(t::Simplex{3,2,1,3,<:Number}) = Simplex(t.vertices,t.tangents,-t.normals,t.volume) + +""" + flip_normal(simplex, sign) + +Flips the normal of the simplex if sign is -1. Only on triangles embedded in 3D space +""" function flip_normal(t::Simplex{3,2,1,3,<:Number},sign::Int) sign == 1 && return t return flip_normal(t) @@ -360,5 +372,11 @@ Returns a matrix whose columns are the tangents of the simplex `splx`. tangents(splx::Simplex) = hcat((splx.tangents)...) vertices(splx::Simplex) = hcat((splx.vertices)...) + +""" + verticeslist(simplex) + +Returns the vertices as a list. +""" verticeslist(splx::Simplex) = splx.vertices export verticeslist \ No newline at end of file diff --git a/src/intersect.jl b/src/intersect.jl index a918cd6..c224330 100644 --- a/src/intersect.jl +++ b/src/intersect.jl @@ -38,6 +38,7 @@ function intersection(p1::Simplex{U,2,C,3}, p2::Simplex{U,2,C,3}) where {U,C} pq = sutherlandhodgman(p1.vertices, p2.vertices) return [ simplex(pq[1], pq[i], pq[i+1]) for i in 2:length(pq)-1 ] end + function intersection(p1::Simplex{3,2,1,3}, p2::Simplex{3,2,1,3};tol=eps()) pq = sutherlandhodgman(p1.vertices, p2.vertices) nonoriented_simplexes = [ simplex(pq[1], pq[i], pq[i+1]) for i in 2:length(pq)-1 ] @@ -52,6 +53,12 @@ function intersection(p1::Simplex{U,3,C,4}, p2::Simplex{U,3,C,4}) where {U,C} volume(p1) <= volume(p2) ? [p1] : [p2] end +""" + intersection2(triangleA, triangleB) + +returns intersection in which the first operand inhirits orientation from first argument +and second argument inhirits orientation of second argument. +""" function intersection2(p1::Simplex, p2::Simplex) a = intersection(p1,p2) return [(i,i) for i in a] @@ -67,6 +74,7 @@ function intersection2(p1::Simplex{3,2,1,3}, p2::Simplex{3,2,1,3}; tol=eps()) return [(flip_normal(s,signs1[i]),flip_normal(s,signs2[i])) for (i,s) in enumerate(nonoriented_simplexes)] end export intersection2 + """ intersectline(a,b,p,q) diff --git a/src/neighborhood.jl b/src/neighborhood.jl index 24eb02d..c56c28a 100644 --- a/src/neighborhood.jl +++ b/src/neighborhood.jl @@ -81,14 +81,3 @@ to parameter `(1/(D+1), 1/(D+1), ...)` where `D` is the simplex dimension. :(neighborhood(p, $uv)) end -# function permute_barycentric(perm,bary::Tuple{T,T}) where {T} -# last_coef = 1-sum(bary) -# total_bary = SVector{3,T}([bary[1],bary[2],last_coef]) -# return Tuple{T,T}(total_bary[perm][1:end-1]) -# end -# function permute_barycentric(perm,bary::Tuple{T,T,T}) where {T} -# last_coef = 1-sum(bary) -# total_bary = SVector{4,T}([bary[1],bary[2],bary[3],last_coef]) -# return Tuple{T,T,T}(total_bary[perm][1:end-1]) -# end -# export permute_barycentric From 0da8059da199867f9063f6b9936b8c44db81b2cb Mon Sep 17 00:00:00 2001 From: PaulOlyslager Date: Thu, 9 Nov 2023 09:53:28 +0100 Subject: [PATCH 12/13] toml updated --- Project.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Project.toml b/Project.toml index 5a09f6a..924ca74 100644 --- a/Project.toml +++ b/Project.toml @@ -13,7 +13,6 @@ FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838" GmshTools = "82e2f556-b1bd-5f1a-9576-f93c0da5f0ee" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Requires = "ae029012-a4dd-5104-9daa-d747884805df" -Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" From 1096da06033cb1a9211e63039084900cfb1e78c4 Mon Sep 17 00:00:00 2001 From: Kristof Cools Date: Fri, 10 Nov 2023 12:27:48 +0100 Subject: [PATCH 13/13] add tests for pr39 --- test/runtests.jl | 1 + test/test_permute_vertices.jl | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 test/test_permute_vertices.jl diff --git a/test/runtests.jl b/test/runtests.jl index 69c255e..8a2372f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -36,6 +36,7 @@ include("test_sh_intersection.jl") include("test_isinside.jl") include("test_jctweld.jl") include("test_isinclosure.jl") +include("test_permute_vertices.jl") include("test_trgauss.jl") include("test_chartquad.jl") diff --git a/test/test_permute_vertices.jl b/test/test_permute_vertices.jl new file mode 100644 index 0000000..a095eff --- /dev/null +++ b/test/test_permute_vertices.jl @@ -0,0 +1,34 @@ +using CompScienceMeshes +using Test + +splx = simplex( + point(0,0,0), + point(1,0,0), + point(0,1,0) +); + +@test normal(splx) ≈ point(0,0,1) + +splx1 = CompScienceMeshes.permute_vertices(splx, [2,1,3]) +@test normal(splx1) ≈ point(0,0,1) + +splx2 = CompScienceMeshes.flip_normal(splx) +@test normal(splx2) ≈ point(0,0,-1) + +for i in 1:2 + @test CompScienceMeshes.tangents(splx2,i) ≈ CompScienceMeshes.tangents(splx,i) +end + +splx3 = simplex( + point(1,0.5,0), + point(-1,0.5,0), + point(-1,2.5,0) +) + +isct = CompScienceMeshes.intersection2(splx, splx3) +@test length(isct) == 1 + +splx4, splx5 = isct[1] +@test volume(splx4) ≈ volume(splx5) +@test normal(splx4) ≈ -normal(splx5) +