我正在尝试计算复曲面上的射线事件的路径长度,但我收到以下错误消息
“从 sym 转换为逻辑是不可能的。”
“如果 Const>Const_Prev,cal_path 中的错误(第 188 行)”有人可以建议一种方法来帮助解决此错误吗?实际代码如下
%Conic Toriodal surface
%This calculates the path length of a ray from a point to the surface
P=[0 0 40];
X=P(1); % define the start point
Y=P(2);
Z=P(3);
Dir=Dir/norm(Dir);
S_o=-P(3)/Dir(3);
S_f=0;
S_Prev=-100;
S=0;
k=1;
X=X+S_o*Dir(1); % define the point intersect with the z=0 plane
Y=Y+S_o*Dir(2);
Z=Z+S_o*Dir(3); % here Z=0
X_1=X;
Y_1=Y;
Z_1=Z;
Cx=1/25; % Curvature of surfaces, 1-by-(j-2) vector, c=1/R
Cy=1/10;
syms x y z
f=z-(Cx*x^2+Cy*y^2+(k*Cy-Cx)*(Cy*y^2./(1+sqrt(1-k*Cy^2*y^2)))^2)/(1+sqrt(1- Cx*(Cx*x^2+Cy*y^2+(k*Cy-Cx)*(Cy*y^2./(1+sqrt(1-k*Cy^2*y^2)))^2)));
%the function of the surface F(x,y,z)=0%
diff(f,x); % calculate the differential of x
diff(f,y); % calculate the differential of y
diff(f,z); % calculate the differential of z
N=0;
while abs(S-S_Prev)>=0.0000000001
N=N+1;
Const_Prev=abs(S-S_Prev);
S_Prev=S;
F_x=subs(diff(f,x),[x,y,z],[X,Y,Z]); % the coordinate x of the normal vector of the surface at P
F_y=subs(diff(f,y),[x,y,z],[X,Y,Z]); % the coordinate y of the normal vector of the surface at P
F_z=subs(diff(f,z),[x,y,z],[X,Y,Z]); % the coordinate z of the normal vector of the surface at P
q=(Cy*Y^2./(1+sqrt(1-k*Cy^2*Y^2)));
G=(Cx*X^2+Cy*Y^2+(k*Cy-Cx)*q^2);
F1=z-G/(1+sqrt(1-Cx*G));
F2=F_x*Dir(1)+F_y*Dir(2)+F_z*Dir(3);
S=S-F1/F2;
Const=abs(S-S_Prev);
if Const>Const_Prev
path='Out';
return
end
X=X_1+Dir(1)*S;
Y=Y_1+Dir(2)*S;
Z=Z_1+Dir(3)*S;
abs(S-S_Prev)
if ~(isreal(S_f))
path='Out';
return
end
end