Comme @Nzbuu a dit, il est difficile de savoir à quoi vous voulez que votre ligne ondulée ressemble. La fonction suivante va tracer une sinusoïde sur votre figure actuelle entre les 2 points, avec des périodes et des amplitudes spécifiées. Si votre définition d'ondulation est différente de la mienne, changez simplement xx
et yy
pour décrire votre ligne ondulée entre [0,0]
et [1,1]
.
function wavyline(pt1, pt2)
% first, create a "unit" wavy line segment
xx = [0:.01:1];
reps = 5 % how many periods of sine you want
widthRatio = 0.2 % height of peaks/lenght of line
yy = (widthRatio/2)*sin(reps*xx*2*pi);
% stretch our unit wavy line to be the proper length
dx = pt2(1) - pt1(1);
dy = pt2(2) - pt1(2);
len = sqrt(dx*dx+dy*dy);
xx = len*xx;
% now rotate it
th = atan2(dy, dx);
R = [cos(th), -sin(th); sin(th), cos(th)];
rotatedPts = R * [xx;yy];
% finally, shift it to start at pt1, and plot
shiftedPts = rotatedPts + [pt1(1); pt1(2)] * ones(size(xx));
plot(shiftedPts(1,:), shiftedPts(2,:),'k')
end
Merci! C'est ce que j'avais en tête. – omarshammas