yingjie, Peng wrote:
> I just want to calculate the volume of a cube with MESH_VOLUME and
> start to test with the following simple code:
>
>
> cube =[[0,0,10] ,[1,0,10] ,[1,1,10] ,[0,1,10] $
> ,[0,0,11] ,[1,0,11] ,[1,1,11] ,[0,1,11] ]
>
> conn=[4,0,1,2,3, $
> 4,0,1,5,4, $
> 4,1,2,6,5, $
> 4,2,3,7,6, $
> 4,3,0,4,7, $
> 4,4,5,6,7]
>
> print,MESH_VOLUME ( cube , conn )
>
> It gives me a volume: 7.66667
> It's just a cube with each length of 1 and the volume should be 1.
> Why is 7.66667 ~~~~>o<~~~~~~
> I have tried one whole night to find the problem but nothing worked.
The answer can be found (maybe) subtly stated in the docs:
"The MESH_VOLUME function computes the volume that the mesh encloses. A
region that a mesh encloses has a positive value for its volume when it
is enclosed by mesh polygons that face outward from the enclosed region.
Outward-facing polygons follow the convention of their vertices being
ordered in a counter-clockwise direction while observing the polygon
from the outside of the enclosed region. Likewise, a region has a
negative value for its volume when it is enclosed by polygons that face
inward to the enclosed region."
Look at the how your polygons are "wound" in your connectivity array.
The first two are counter-clockwise, but the last 4 are clockwise. They
must all be wound CCW to get the correct answer:
cube =[[0,0,10] ,[1,0,10] ,[1,1,10] ,[0,1,10] $
,[0,0,11] ,[1,0,11] ,[1,1,11] ,[0,1,11] ]
conn=[4,0,1,2,3, $
4,0,1,5,4, $
4,1,5,6,2, $
4,2,6,7,3, $
4,0,3,7,4, $
4,5,4,7,6]
print, MESH_VOLUME (cube , conn)
IDL> .GO
1.00000
-Rick
|