ThreeJS:3D对象面积计算(三角化) [英] ThreeJS: 3D Object Area Calculation (Triangulated)

查看:60
本文介绍了ThreeJS:3D对象面积计算(三角化)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在threeJS中计算整个对象的面积/表面.这就是我所拥有的:

I need to calculate the area/surface of a whole object in threeJS. Thats what I have:

    var _len = object.geometry.faces.length,
        _area = 0.0;

    if (!_len) return 0.0;

    for (var i = 0; i < _len; i++) {
        var va = object.geometry.vertices[object.geometry.faces[i].a];
        var vb = object.geometry.vertices[object.geometry.faces[i].b];
        var vc = object.geometry.vertices[object.geometry.faces[i].c];

        var ab = vb.clone().sub(va);
        var ac = vc.clone().sub(va);

        var cross = new THREE.Vector3();
        cross.crossVectors( ab, ac );

        _area += cross.lengthSq() / 2;
    }

结果有点错误.我得到一个浮动值,很好,但是将一个非常小的对象与一个大对象进行比较.使用提供的代码,较小的可能具有更大的表面.在比较它们时,我检查了许多不同的对象,但得到的值并不现实.

The results are kind of wrong. I get a floating value, fine, but comparing a very small object with a big object. The smaller could have a bigger surface with the provided code. I checked on many different objects and got not realistic values, when comparing them.

实际上,具有最大面但在整个表面中最小的对象似乎必须使用当前版本的代码获得最高值.

Actually the objects having the biggest faces, but being the smallest in the overall surface, seem to have to highest values with the current version of the code.

我希望有人可以看看代码,看看有什么问题.非常感谢!

I hope someone could have a look at the code and see whats wrong. Very much appreciated!

推荐答案

您使用的是 lengthSq(),对吗?我猜你需要的是交叉向量的长度,而不是长度的平方.

You are using lengthSq(), is that right? I guess you need the length of the cross vector, not the length squared.

这篇关于ThreeJS:3D对象面积计算(三角化)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆