C++算法转为delphi ,高手帮忙!(200分)

  • 主题发起人 主题发起人 amakusa
  • 开始时间 开始时间
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;

}
 
编译通过:
procedure Scan(x_dest, y_dest: Double; var x_src, y_src: Double; var params: Pointer);
var
phi, theta, r, s: Double;
v: array [0..2] of Double;
tmpParams: Double;
begin
tmpParams := Double(params^);
phi := x_dest / tmpParams;
theta := -y_dest / tmpParams + PI / 2;

if theta < 0 then
begin
theta := -theta;
phi := phi + PI;
end;

if theta > PI then
begin
theta := PI - (theta - PI);
phi := phi + PI;
end;

{$IF False}
v[2] := tmpParams * sin(theta) * cos(phi); // x' -> z
v[0] := tmpParams * sin(theta) * sin(phi); // y' -> x
v[1] := tmpParams * cos(theta); // z' -> y

theta := ArcTan2(sqrt(v[0] * v[0] + v[1]*v[1]), v[2]);

phi := ArcTan2(v[1], v[0]);

x_src := tmpParams * theta * cos(phi);
y_src := tmpParams * theta * sin(phi);
{$IFEND}
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 := tmpParams * ArcTan2(r, s * cos(phi));

x_src := theta * v[0] / r;
y_src := theta * v[1] / r;
end;

记得 uses Math
 
OK 具体的指针怎么用啊
 
接受答案了.
 
后退
顶部