ThreeJS:3D对象区域计算(三角剖分) [英] ThreeJS: 3D Object Area Calculation (Triangulated)

查看:629
本文介绍了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天全站免登陆