Login|Register   
   Home |  Active Topics |  Members |  Search Forums |  FAQ     
  All Forums >>  Coffee Lounge  >>  Surface Area Calculation
   Printer Friendly  New Topic     Reply to Topic
Author Previous Topic Topic Next Topic  

sirhc108
Member

1 Posts

Posted - 20 Feb 2010 :  10:01:31  Show Profile  Visit sirhc108's Homepage  Reply with Quote

Hi,

I'm doing a project and need calculate the surface area. I found the follow script to calculate volume. It looks as if it already calculates polyarea. Can anyone modify this to give the surface area. Im not an experienced programmer and dont have a clue how to do it. Any help would be appreciated.

Thanks,
Chris
------------------------------------------
#!/usr/bin/env python


try:
volume = 0
# get default units
magnitude = 1
units = lx.eval('pref.value units.default ?')

if units == 'micrometers':
magnitude = 1000000
elif units == 'millimeters':
magnitude = 1000
elif units == 'centimeters':
magnitude = 100
elif units == 'meters':
magnitude = 1
elif units == 'kilometers':
magnitude = 0.001
elif units == 'megameters':
magnitude = 0.000001


# get selected layer
layerID = lx.eval('query layerservice layer.ID ? selected')

# triple and freeze polys
lx.eval('poly.freeze false')
lx.eval('poly.triple')

# get layer polys
polys = lx.eval('query layerservice polys ? all')

for poly in polys:
znormal = lx.eval('query layerservice poly.normal ? %s' % poly)[2]

if znormal == 0:
pass
else:
if znormal > 0:
factor = 1.0
elif znormal < 0:
factor = -1

verts = lx.eval('query layerservice poly.vertList ? %s' % poly)
coords = {}

for index, vert in enumerate(verts):
coords[index] = lx.eval('query layerservice vert.wpos ? %s' % vert)

x1 = coords[0][0]
y1 = coords[0][1]
z1 = coords[0][2]

x2 = coords[1][0]
y2 = coords[1][1]
z2 = coords[1][2]

x3 = coords[2][0]
y3 = coords[2][1]
z3 = coords[2][2]

polyarea = 0.5*abs((x1*(y3-y2))+(x2*(y1-y3))+(x3*(y2-y1)))
vol = ((z1+z2+z3)/3.0)*polyarea

volume += (factor * vol)

volume = volume * magnitude * magnitude * magnitude

litres = volume / (1000 * magnitude)
if litres < 0.005:
litres = '%.8f' % litres
else:
litres = '%.3f' % litres

lx.eval('dialog.setup info')
lx.eval('dialog.title {mm_MeshVolume}')
lx.eval('dialog.msg {Mesh Volume is %.3f cubic %s (%s L)}' % (volume, units, litres))
lx.eval('dialog.open')

except Exception, e:
lx.out('%s line: %s' % (e, sys.exc_traceback.tb_lineno))
  Previous Topic Topic Next Topic  
   Printer Friendly  New Topic     Reply to Topic