How should I calculate the surface area of a 3D Mesh file. Is there any predefined function for surface area calculation. I am working on a project, where after selecting picture volume and area gets calculated automatically in there field.
Asked
Active
Viewed 1,776 times
-2
-
1The sum of areas of all the triangles in a mesh? – prisoner849 Jul 17 '18 at 09:20
-
no , the figure is not triangular shape. – Priya Jul 17 '18 at 09:24
-
Do you use quads? What revision of Three.js? – prisoner849 Jul 17 '18 at 09:27
-
Please, read about [ask] and [mcve]. So far, it's very unclear what you're asking about. – prisoner849 Jul 17 '18 at 09:44
2 Answers
2
There is no direct method to get the area but you can create your own custom logic. The logic is to create triangles out of your mesh and calculate there area and add them which will be equals to the area of your mesh.
The example is as follows:
function crossVectors( a, b ) {
var ax = a.X, ay = a.Y, az = a.Z;
var bx = b.X, by = b.Y, bz = b.Z;
var P={X:ay * bz - az * by,
Y:az * bx - ax * bz,
Z:ax * by - ay * bx}
return P;
}
function SuperficialAreaOfMesh(points) {
var _len =points.length,
_area = 0.0;
if (!_len) return 0.0;
var i= 0,vols=0;
var va,vb,vc;
do {
va={X:points[i],Y:points[i+1],Z:points[i+2]};
vb={X:points[i+3],Y:points[i+4],Z:points[i+5]};
vc={X:points[i+6],Y:points[i+7],Z:points[i+8]};
var ab = {X:vb.X-va.X,Y:vb.Y-va.Y,Z:vb.Z-va.Z};
//vb.clone().sub(va); var ac = {X:vc.X-va.X,Y:vc.Y-va.Y,Z:va.Z-vc.Z};
//vc.clone().sub(va); var cross = new THREE.Vector3();
cross=crossVectors( ab, ac );
_area += Math.sqrt(Math.pow(cross.X,2)+Math.pow(cross.Y,2)+Math.pow(cross.Z,2))/2;
i+=9;
}
while (i<points.length);
return customRound(Math.abs(_area)/100,2);
}
// Let's say you have mesh named mesh
SuperficialAreaOfMesh(mesh.vertices);
The example above follows the tutorial found here.

Ullas Hunka
- 2,119
- 1
- 15
- 28
-
1For less code, it could be done with `THREE.Triangle()` and its [`.getArea()`](https://threejs.org/docs/index.html#api/math/Triangle.getArea) method. – prisoner849 Jul 17 '18 at 09:32
-
Dimensions X,Y,Z value is given but i dont know what formula i have to use for calculating surface area of a3D file. – Priya Jul 17 '18 at 09:37
-
1
-
Actually I am getting area as an array and function takes only 2 arguments. Please Help me..... [0.10762328 0.02869747 0.11791313 0.11009426 0.04056691 0.11645208 0.10868461 0.03259173 0.12078221] – Priya Jul 18 '18 at 04:01
-
@UllasHunka Actually my points comes up as nested array [[12.671184 4.1647673 13.446729 ... 12.671184 4.1647673 13.946729 ] [12.303494 2.7925358 13.946729 ... 12.671184 4.1647673 13.946729 ] [12.303494 2.7925358 13.446729 ... 12.303494 2.7925358 13.946729 ] ... [ 1.0177865 6.900198 14.36 ... 0.84364206 6.250282 14.36 ] [ 1.3021419 7.51 19.36 ... 1.0177865 6.900198 14.36 ] [ 1.3021419 7.51 14.36 ... 1.0177865 6.900198 14.36 ]] – Priya Jul 18 '18 at 04:26
-
My Code def find_mins_maxs(self, obj): arr1 = obj.points length_1 =len(arr1) _area = 0.0; va = vb = vc = {} if length_1 ==0: return 0.0 i= 0; while i<=length_1-2: va['X'] = arr1[i] va['Y'] = arr1[i+1] va['Z'] = arr1[i+2] _area += np.sqrt(np.power(va['X'],2)+np.power(va['Y'],2)+np.power(va['Z'],2))/2; i+=3; area = np.abs(_area)/100 y = self.custom(area,2) return y – Priya Jul 18 '18 at 04:29
-
Can you please update your question with the points so that I can see and can update the logic – Ullas Hunka Jul 18 '18 at 04:44
-
Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/176206/discussion-between-ullas-hunka-and-priya). – Ullas Hunka Jul 18 '18 at 04:45
2
def crossVectors(a,b):
P = {}
ax = b[0]['X']
ay = b[0]['Y']
az = b[0]['Z']
bx = b[1]['X']
by = b[1]['Y']
bz = b[1]['Z']
P['X'] = ay * bz - az * by
P['Y'] = az * bx - ax * bz
P['Z'] = ax * by - ay * bx
return P
def find_mins_maxs(self, obj):
minx = maxx = miny = maxy = minz = maxz = None
# print"##############", obj #dir(obj)
arr1 = obj.points
length_1 =len(arr1)
_area = 0.0;
va ={}
vb = {}
vc = {}
ab= {}
ac= {}
val = []
if length_1 ==0:
return 0.0
i= 0;
while i<length_1-2:
va['X'] = arr1[i][0]
va['Y'] = arr1[i][1]
va['Z'] = arr1[i][2]
vb['X'] = arr1[i+1][0]
vb['Y'] = arr1[i+1][1]
vb['Z'] = arr1[i+1][2]
vc['X'] = arr1[i+2][0]
vc['Y'] = arr1[i+2][1]
vc['Z'] = arr1[i+2][2]
ab['X'] = vb['X']-va['X']
ab['Y'] = vb['Y']-va['Y']
ab['Z'] = vb['Z']-va['Z']
ac['X'] = vc['X']-va['X']
ac['Y'] = vc['Y']-va['Y']
ac['Z'] = vc['Z']-va['Z']
val.append(ab)
val.append(ac)
cross= self.crossVectors(val)
_area +=np.sqrt(np.power(cross['X'],2)+np.power(cross['Y'],2)+np.power(cross['Z'],2))/2;
i+=9;
area = np.abs(_area)/100
fractiondigits =2
area =round(area*np.power(10,fractiondigits))/np.power(10,fractiondigits)
print"@@@@@@@@@@@@@@@",area
return area

Priya
- 102
- 1
- 14