我試圖計算圖像重心,像這樣:找到一個圖像的輪廓質心
// Calculate centroid
double signedArea = 0.0;
sskp_point centroid;
for(int i=0;i<numPoints;i++)
{
double a = (points[i].x*points[(i+1)%numPoints].y)-(points[(i+1)%numPoints].x*points[i].y);
signedArea += a;
centroid.x += (points[i].x*points[(i+1)%numPoints].x)*a;
centroid.y += (points[i].y*points[(i+1)%numPoints].y)*a;
printf("points[%d] = { %f, %f }\n",i,points[i].x,points[i].y);
}
signedArea /= 2.0;
centroid.x /= (6*signedArea);
centroid.y /= (6*signedArea);
printf("centroid = { %f, %f }\n",centroid.x,centroid.y);
我從算法here適應這一點,但它給我的錯誤results,誰能告訴我是什麼這適應錯了嗎?
我真是個傻瓜,謝謝。 – user293895 2012-07-18 13:24:13
它發生了。人非聖賢孰能。 :d – 2012-07-18 13:25:15