我正在尝试计算复曲面上光线入射的路径长度,但是我收到以下错误信息
“无法从sym转换为逻辑。”
“cal_path中的错误(第188行) 如果Const> Const_Prev“ 有人可以建议一种方法来帮助解决这个错误吗? 实际代码在
之下 %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
答案 0 :(得分:0)
Dir = [0 0 1]
在if
- 语句的一部分进行评估之前,Const
具有以下值:
Const =
abs(z)
这可以通过使用调试器并放置breakpoint。
z
尚未被替换。在定义subs
,F_x
和F_y
时使用F_z
,但在定义F1
时,仍使用z
}。相反,使用:
F1=Z-G/(1+sqrt(1-Cx*G));
现在,Const
应该采用一个值并且没有符号表达式。