2013년 6월 11일 화요일

STL File - Volume 구하기

아- 넘 졸리다..

얼마전 STL Vector정보가 3 Points 에대한 Vector 정보가 아닌, 쉐이딩 정보라는것을 Wiki 에서 발견했다.. -_-

나름 Grading 한 정보가 Vector 정보가 맞지 않아 고심했던 걸 생각하면 괴씸하군. 뒤통수 맞은 기분 ㅠㅠ

쉐이딩 정보를 어떻게 변환해야할지에 대해서는 아직 고심하지 않았지만,
볼륨을 구하는 목적의 프로그램에는 특별히 상관이 없어서 나중에 검토 하기로 했다.



Let we have field F(P)=P . It have constant divergence Ñ·F = 3 . Flow of F(P) through triangle ABC is 1/2 * A.BXC . Method above uses exactly that. (it indeed could be said that it just adds volume of pyramids. [grin] but you can derive it from divergence theorem (aka Gauss's Theorem) , and will not have problems proving that negative volume trick will work)

(2everyone who suggested my method explained in other tread, that only differs in "volume+=(v0.x+v1.x+v2.x)*Cross(v1-v0,v2-v0).x" (uses field F(P)=[P.x,0,0] with divergence 1) : it was made to simplify computation of volume of submerged object. In other cases, "pyramids method" is nicer)
       
Suppose you have a vertex array V[] of N vertices. The triangle list is an array I[] of 3*T indices into the vertex array and represents T triangles. Suppose the mesh is closed, each edge is shared by two triangles, and the mesh is not self-intersecting ("water tight" in the vernacular). Also assume that the triangles are counterclockwise oriented as viewed by an observer outside the mesh. Finally, assume that the mass density is constant (1). If nonconstant, the problem is much more difficult.

float volume = 0;
int* index = I;
for (i = 0; i < T; i++)
{
    Vector3 v0 = V[*index++];
    Vector3 v1 = V[*index++];
    Vector3 v2 = V[*index++];
    volume += Dot(v0,Cross(v1,v2));
}
volume /= 6;

댓글 없음:

댓글 쓰기