mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-01 09:49:45 +00:00
further vnf_volume speed improvement
This commit is contained in:
parent
224555a9ec
commit
57034ac955
1 changed files with 3 additions and 7 deletions
10
vnf.scad
10
vnf.scad
|
@ -357,17 +357,13 @@ module vnf_polyhedron(vnf, convexity=2) {
|
||||||
// Returns the volume enclosed by the given manifold VNF. The VNF must describe a valid polyhedron with consistent face direction and
|
// Returns the volume enclosed by the given manifold VNF. The VNF must describe a valid polyhedron with consistent face direction and
|
||||||
// no holes; otherwise the results are undefined. Returns a positive volume if face direction is clockwise and a negative volume
|
// no holes; otherwise the results are undefined. Returns a positive volume if face direction is clockwise and a negative volume
|
||||||
// if face direction is counter-clockwise.
|
// if face direction is counter-clockwise.
|
||||||
|
|
||||||
|
// Algorithm adapted/simplified from: https://wwwf.imperial.ac.uk/~rn/centroid.pdf
|
||||||
function vnf_volume(vnf) =
|
function vnf_volume(vnf) =
|
||||||
let(verts = vnf[0])
|
let(verts = vnf[0])
|
||||||
sum([
|
sum([
|
||||||
for(face=vnf[1], j=[1:1:len(face)-2])
|
for(face=vnf[1], j=[1:1:len(face)-2])
|
||||||
let(
|
cross(verts[face[j+1]], verts[face[j]]) * verts[face[0]]
|
||||||
v0 = verts[face[0]],
|
|
||||||
v1 = verts[face[j]],
|
|
||||||
v2 = verts[face[j+1]],
|
|
||||||
n = cross(v2-v0,v1-v0)
|
|
||||||
)
|
|
||||||
v0 * n
|
|
||||||
])/6;
|
])/6;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue