我应该如何计算3D网格文件的表面积。 是否有任何预定义的表面积计算功能。我正在做一个项目,选择了图片的体积和面积后,该字段就会自动计算出来。
答案 0 :(得分:1)
没有直接方法可以获取区域,但是您可以创建自己的自定义逻辑。逻辑是在网格之外创建三角形并计算该区域的面积,然后将其相加,使其等于网格的面积。
示例如下:
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);
上面的示例遵循here找到的教程。
答案 1 :(得分:1)
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