Skip to content

Commit cbeef13

Browse files
authored
Merge pull request #10 from sjkelly/sjk/dihedral
Sjk/dihedral
2 parents d763e05 + 684ee46 commit cbeef13

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

src/quality.jl

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ function triqual(p1, p2, p3)
88
d13 = p3 - p1
99
d23 = p3 - p2
1010
n = cross(d12,d13)
11-
vol = sqrt(sum(n.^2))/2
11+
vol = sqrt(sum(n.^2))
1212
den = dot(d12,d12) + dot(d13,d13) + dot(d23,d23)
13-
return sqrt(3)*4*vol/den
13+
return sqrt(3)*2*vol/den
1414
end
1515

1616
function triangle_qualities(p,tets)
@@ -32,4 +32,56 @@ end
3232

3333
function triangle_qualities!(tris::Vector,qualities::Vector,p,tets)
3434
triangle_qualities!(tris,Set{eltype(tris)}(),qualities,p,tets)
35-
end
35+
end
36+
37+
const = dot
38+
const × = cross
39+
40+
function dihedral(p0,p1,p2,p3)\
41+
b1 = p1 - p0
42+
b2 = p2 - p1
43+
b3 = p3 - p2
44+
45+
abs(atan(((b1×b2)×(b2×b3))normalize(b2), (b1×b2)(b2×b3)))
46+
end
47+
48+
"""
49+
Compute dihedral angles within a tetrahedra
50+
radians
51+
"""
52+
function dihedral_angles(p,t)
53+
AT = eltype(eltype(p))
54+
nangs = length(t)*6
55+
a = fill(zero(AT), nangs)
56+
for i in 1:length(t)
57+
t1, t2, t3, t4 = t[i]
58+
a[i*6-5] = dihedral(p[t1],p[t2],p[t3],p[t4])
59+
a[i*6-4] = dihedral(p[t1],p[t2],p[t4],p[t3])
60+
a[i*6-3] = dihedral(p[t2],p[t1],p[t4],p[t3])
61+
a[i*6-2] = dihedral(p[t2],p[t3],p[t4],p[t1])
62+
a[i*6-1] = dihedral(p[t2],p[t1],p[t3],p[t4])
63+
a[i*6] = dihedral(p[t3],p[t1],p[t2],p[t4])
64+
end
65+
a
66+
end
67+
68+
"""
69+
Compute the minimum dihedral angle within a tetrahedra
70+
radians
71+
"""
72+
function min_dihedral_angles(p,t)
73+
AT = eltype(eltype(p))
74+
nangs = length(t)
75+
a = fill(zero(AT), nangs)
76+
for i in 1:length(t)
77+
t1, t2, t3, t4 = t[i]
78+
d = (dihedral(p[t1],p[t2],p[t3],p[t4]),
79+
dihedral(p[t1],p[t2],p[t4],p[t3]),
80+
dihedral(p[t2],p[t1],p[t4],p[t3]),
81+
dihedral(p[t2],p[t3],p[t4],p[t1]),
82+
dihedral(p[t2],p[t1],p[t3],p[t4]),
83+
dihedral(p[t3],p[t1],p[t2],p[t4]))
84+
a[i] = minimum(d)
85+
end
86+
a
87+
end

test/runtests.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,15 @@ end
8585
@test isapprox(getproperty(s,fn), getproperty(stat_04,fn))
8686
end
8787
end
88+
89+
@testset "dihedral metrics" begin
90+
d(p) = sqrt(sum(p.^2))-1
91+
p,t,_ = distmesh(d,HUniform(),0.2)
92+
all_angs = DistMesh.dihedral_angles(p,t)
93+
min_angs = DistMesh.min_dihedral_angles(p,t)
94+
ax = extrema(all_angs)
95+
mx = extrema(min_angs)
96+
@test ax[1] == mx[1]
97+
@test ax == (0.023502688273828173, 3.104396619996953)
98+
@test mx == (0.023502688273828173, 1.2044902180168893)
99+
end

0 commit comments

Comments
 (0)