I have matlab programming below. It too long and repeated when I want to use while loops. So there have any ideas how to simplify this programming?
- 有 4 个点用于创建 b 样条曲线
- 还有画圆曲线
- 交集函数用于识别b样条曲线和圆曲线之间是否有任何交集
- 如果发生,该程序将 P2 和 P3 的轴增加 0.01,以确保不发生相交
% CONTROL POINTS OF B-SPLINE CURVE
P1 = [0,0];
P2 = [40,25];
P3 = [60,25];
P4 = [100,0];
% ADDITIONAL CONTROL POINTS FOR COMPLETING THE SEGMENTS
P0x = (2*P1(1,1))-P2(1,1);
P0y = (2*P1(1,2))-P2(1,2);
Z1 = [P0x, P0y];
P5x = (2*P4(1,1))-P3(1,1);
P5y = (2*P4(1,2))-P3(1,2);
Z2 = [P5x, P5y];
global Vx1 Vy1 Vx2 Vy2 Vx3 Vy3
for cc = 0;
Vx1 = [Z1(1,1) P1(1,1) P2(1,1) P3(1,1)]';
Vy1 = [Z1(1,2) P1(1,2) P2(1,2) P3(1,2)]';
[C1 C2] = mybspline (Vx1, Vy1);
Vx2 = [P1(1,1) P2(1,1) P3(1,1) P4(1,1)]';
Vy2 = [P1(1,2) P2(1,2) P3(1,2) P4(1,2)]';
[C3 C4] = mybspline (Vx2, Vy2);
Vx3 = [P2(1,1) P3(1,1) P4(1,1) Z2(1,1)]';
Vy3 = [P2(1,2) P3(1,2) P4(1,2) Z2(1,2)]';
[C5 C6] = mybspline (Vx3, Vy3);
end
%
A=[C1',C2';C3',C4';C5',C6']; %Red points - curve segment
B=[Vx1,Vy1;Vx2,Vy2;Vx3,Vy3]; %Blue points - control points
%--------------------------------------------------------------------------
%CIRCLE
Xc = 50; %Center for x
Yc = 0; %Center for y
R = 25; %R, radius of circle
x = 0:0.01:1; %x vector
y = 0:0.01:1; %y vector
C = Xc+R*cos(pi*x)';
D = Yc+R*sin(pi*y)';
Point_circle = [C D];
E = A(:,1); % x axis data of B-Spline curve
F = A(:,2); % y axis data of B-Spline curve
%--------------------------------------------------------------------------
% FIND INTERSECTION BETWEEN CURVE
[intersect_x,intersect_y] = curveintersect(A(:,1),A(:,2),C,D);
intersect = [intersect_x, intersect_y];
figure(101)
plot(A(:,1),A(:,2),'k',C,D,'b',intersect_x,intersect_y,'ro')
abc = isempty (intersect);
while abc == 0
P2(1,2) = P2(1,2)+0.01;
P3(1,2) = P3(1,2)+0.01;
% ADDITIONAL CONTROL POINTS FOR COMPLETING THE SEGMENTS
P0x = (2*P1(1,1))-P2(1,1);
P0y = (2*P1(1,2))-P2(1,2);
Z1 = [P0x, P0y];
P5x = (2*P4(1,1))-P3(1,1);
P5y = (2*P4(1,2))-P3(1,2);
Z2 = [P5x, P5y];
global Vx1 Vy1 Vx2 Vy2 Vx3 Vy3
for cc = 0;
Vx1 = [Z1(1,1) P1(1,1) P2(1,1) P3(1,1)]';
Vy1 = [Z1(1,2) P1(1,2) P2(1,2) P3(1,2)]';
[C1 C2] = mybspline (Vx1, Vy1);
Vx2 = [P1(1,1) P2(1,1) P3(1,1) P4(1,1)]';
Vy2 = [P1(1,2) P2(1,2) P3(1,2) P4(1,2)]';
[C3 C4] = mybspline (Vx2, Vy2);
Vx3 = [P2(1,1) P3(1,1) P4(1,1) Z2(1,1)]';
Vy3 = [P2(1,2) P3(1,2) P4(1,2) Z2(1,2)]';
[C5 C6] = mybspline (Vx3, Vy3);
end
%
A=[C1',C2';C3',C4';C5',C6']; %Red points - curve segment
B=[Vx1,Vy1;Vx2,Vy2;Vx3,Vy3]; %Blue points - control points
[intersect_x,intersect_y] = curveintersect(A(:,1),A(:,2),C,D);
intersect = [intersect_x, intersect_y];
figure(101)
plot(A(:,1),A(:,2),'k',C,D,'b',intersect_x,intersect_y,'ro')
abc = isempty (intersect);
if abc == 1;
break
end
end
谢谢你的慷慨!