Reputation: 765
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!
Upvotes: 1
Views: 1820
Reputation: 344
You are using lengthSq(), is that right? I guess you need the length of the cross vector, not the length squared.
Upvotes: 1