点云上的体积计算

问题描述 投票:0回答:1

我目前正在研究点云,我将选择我需要的特定区域的特定区域,其中我的代码给我提供的值超出预期,请帮助我解决问题

calculateVolume(points) {
            // Ensure uniqueness of points based on x, y, z coordinates
            const uniquePoints = Array.from(new Set(points.map(p => JSON.stringify(p)))).map(p => JSON.parse(p));
            
            if (uniquePoints.length < 4) {
                console.error("Not enough points to calculate volume.");
                return 0;
            }
        
            // Find the minimum z-value among all points
            const minZ = Math.min(...uniquePoints.map(point => point.z));
            const maxz = Math.max(...uniquePoints.map(point => point.z));
            console.log("minZ value is ",minZ);
            console.log("maxZ value is ",maxz);
            const boundedPoints = uniquePoints.map(point => ({ x: point.x, y: point.y, z: (point.z > minZ) && (point.z < maxz) }));
            // console.log(boundedPoints)
            const delaunay = Delaunator.from(boundedPoints.map(point => [point.x, point.y, point.z]));
        
            let volume = 0;
            const triangles = delaunay.triangles;
        
            for (let i = 0; i < triangles.length; i += 3) {
                const p1 = boundedPoints[triangles[i]];
                const p2 = boundedPoints[triangles[i + 1]];
                const p3 = boundedPoints[triangles[i + 2]];
                console.log("points p1 is", p1);
                console.log("points p2 is", p2);
                console.log("points p3 is", p3);

        
                volume += (
                    p1.x * (p2.y * p3.z - p3.y * p2.z) -
                    p1.y * (p2.x * p3.z - p2.z * p3.x) +
                    p1.z * (p2.x * p3.y - p2.y * p3.x)
                );
                console.log("volume is", volume);
            }
        
            // Calculate the volume using the minimum z-value
            volume = Math.abs(volume) / 6.0;
        
            return volume;
        }

我想要上面代码中的点内所选区域的体积,我正在使用 delaunay 三角测量方法

point-cloud-library delaunay potree
1个回答
0
投票

在三角形的特殊情况下,在平面上凸起的三角柱的体积是三个顶点的平均高度乘以三角形的面积。所以你可以尝试类似维基百科中的以下公式

area = ( (p1.x-p3.x)*(p2.y-p1.y)-(p1.x-p2.x)*(p3.y-p1.y) )/2.0;
zMean =  (p1.z+p2.z+p3.z)/3.0;
volume += area*zMean; 

Kevin Brown 在三角形下的体积

给出了很好的解释和替代计算公式

我有一篇关于计算湖泊体积的网络文章,位于 使用 Delaunay 计算湖泊体积

© www.soinside.com 2019 - 2024. All rights reserved.