Mình có viết một hàm tính thể tích như sau:
Code:
CGAL::Gmpzf Volume()
{
int count,R;
CGAL::Gmpzf Insc, tichluy, d, vol;
count = 0;
R = 1;
tichluy = 0;
while (count < nS)
{
R++;//tại sao R luôn = 2
Insc = 1 + (tichluy + count)/(nS-count);
tichluy = 0;
for(int i = 0; i<nS; i++)
{
cout<<"i="<<i<<endl;
if (PSphere[i].flag ==0)
{
//Tim khoang cach nho nhat tu diem dang xet den tat ca cac mat cua mo hinh
Point e = PSphere[i].point;
d= squared_distance(e,VPlane[0]);
for (int j = 1; j < VPlane.size(); j++) //Tinh khoang cach tu dinh den mat
if (squared_distance(e,VPlane[j]) < d)
d = squared_distance(e,VPlane[j]);
PSphere[i].dist = d;
Vector v = PSphere[i].point - Pcenter;
if (Insc == d)
{
v = Insc*v;
PSphere[i].point =Pcenter + v;
PSphere[i].flag = 1; //Ghi nhan dinh da cham mo hinh
count++; //Co them 1 dinh cham mo hinh
}
else if (d > Insc)
{
v = Insc*v;
PSphere[i].point =Pcenter + v;
}
else //d < Insc
{
v = d*v;
PSphere[i].point =Pcenter + v;
PSphere[i].flag = 1;
tichluy += Insc - d;
count++;
}
}//Ket thuc if
}//Ket thuc for
}
/*if (tichluy!=0)
R =R- tichluy/nS;*/
vol = (4*PI*R*R*R)/3;
return vol;
}
Khi mình debug thì phát hiện trong vòng lặp while 3 câu lệnh sau chỉ thực hiện đúng một lần, nó không được lặp lại
Code:
R++;
Insc = 1 + (tichluy + count)/(nS-count);
tichluy = 0;
Nên R luôn = 2, do đó thể tích luôn bằng 33,5103. Các bạn làm ơn chỉ ra chỗ sai dùm mình nha. Giờ mình rối quá,'mò' hoài mà chẳng ra gì cả.
Thanks nhìu!!
Bookmarks