|
发表于 2003-10-23 08:44:00
|
显示全部楼层
Re:大家有没有快速近似开方的算法?
快速的开发算法没有,不过有一个快速计算两点间距离的算法,希望能帮得上忙。
int Fast_Distance_2D(int x, int y)
{
// this function computes the distance from 0,0 to x,y with 3.5% error
// first compute the absolute value of x,y
x = abs(x);
y = abs(y);
// compute the minimum of x,y
int mn = MIN(x,y);
// return the distance
return(x+y-(mn>>1)-(mn>>2)+(mn>>4));
} // end Fast_Distance_2D
此函数计算(0,0)点到(x,y)的距离,任意两点的距离 = Fast_Distance_2D(x1 -x2, y1 - y2); |
|