A
amakusa
Unregistered / Unconfirmed
GUEST, unregistred user!
//我有一段C++的算法如下,但是本人是从object pascal进阶的 ,希望哪位高手能帮忙转成
delphi语法
#define distance (*((double*)params))
void scan( double x_dest,double y_dest, double* x_src, double* y_src, void* params)
{
// params: double distance
register double phi, theta, r,s;
double v[3];
phi = x_dest / distance;
theta = - y_dest / distance + PI / 2;
if(theta < 0)
{
theta = - theta;
phi += PI;
}
if(theta > PI)
{
theta = PI - (theta - PI);
phi += PI;
}
#if 0
v[2] = *((double*)params) * sin( theta ) * cos( phi ); // x' -> z
v[0] = *((double*)params) * sin( theta ) * sin( phi ); // y' -> x
v[1] = *((double*)params) * cos( theta ); // z' -> y
theta = atan2( sqrt( v[0]*v[0] + v[1]*v[1] ) , v[2] );
phi = atan2( v[1], v[0] );
*x_src = *((double*)params) * theta * cos( phi );
*y_src = *((double*)params) * theta * sin( phi );
#endif
s = sin( theta );
v[0] = s * sin( phi ); // y' -> x
v[1] = cos( theta ); // z' -> y
r = sqrt( v[1]*v[1] + v[0]*v[0]);
theta = distance * atan2( r , s * cos( phi ) );
*x_src = theta * v[0] / r;
*y_src = theta * v[1] / r;
}
delphi语法
#define distance (*((double*)params))
void scan( double x_dest,double y_dest, double* x_src, double* y_src, void* params)
{
// params: double distance
register double phi, theta, r,s;
double v[3];
phi = x_dest / distance;
theta = - y_dest / distance + PI / 2;
if(theta < 0)
{
theta = - theta;
phi += PI;
}
if(theta > PI)
{
theta = PI - (theta - PI);
phi += PI;
}
#if 0
v[2] = *((double*)params) * sin( theta ) * cos( phi ); // x' -> z
v[0] = *((double*)params) * sin( theta ) * sin( phi ); // y' -> x
v[1] = *((double*)params) * cos( theta ); // z' -> y
theta = atan2( sqrt( v[0]*v[0] + v[1]*v[1] ) , v[2] );
phi = atan2( v[1], v[0] );
*x_src = *((double*)params) * theta * cos( phi );
*y_src = *((double*)params) * theta * sin( phi );
#endif
s = sin( theta );
v[0] = s * sin( phi ); // y' -> x
v[1] = cos( theta ); // z' -> y
r = sqrt( v[1]*v[1] + v[0]*v[0]);
theta = distance * atan2( r , s * cos( phi ) );
*x_src = theta * v[0] / r;
*y_src = theta * v[1] / r;
}