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?
- bスプライン曲線を作成するために使用している4つのポイントがあります
- 円曲線も描いてます
- 交差関数は、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
寛大に感謝します!