Skip to content

Commit

Permalink
Add Mesh.SharpEdges
Browse files Browse the repository at this point in the history
  • Loading branch information
fogleman committed Aug 18, 2020
1 parent 576996a commit 29d82a3
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,39 @@ func (m *Mesh) SplitTriangles(maxEdgeLength float64) {
m.Triangles = triangles
m.dirty()
}

func (m *Mesh) SharpEdges(angleThreshold float64) *Mesh {
type Edge struct {
A, B Vector
}

makeEdge := func(a, b Vector) Edge {
if a.Less(b) {
return Edge{a, b}
}
return Edge{b, a}
}

var lines []*Line
other := make(map[Edge]*Triangle)
for _, t := range m.Triangles {
p1 := t.V1.Position
p2 := t.V2.Position
p3 := t.V3.Position
e1 := makeEdge(p1, p2)
e2 := makeEdge(p2, p3)
e3 := makeEdge(p3, p1)
for _, e := range []Edge{e1, e2, e3} {
if u, ok := other[e]; ok {
a := math.Acos(t.Normal().Dot(u.Normal()))
if a > angleThreshold {
lines = append(lines, NewLineForPoints(e.A, e.B))
}
}
}
other[e1] = t
other[e2] = t
other[e3] = t
}
return NewLineMesh(lines)
}

0 comments on commit 29d82a3

Please sign in to comment.