matlab画直线,指定斜率与x坐标范围

闲话不说,直接上代码与图的效果!

 


AngleD=59; %[-90 90]
c=20:80;
centralPoint=[50 50]';
image=zeros(100,100);
image(25:74,25:74)=ceil(abs(rand(50,50).*10));


if abs(AngleD)==90,
    fprintf(1,'no single line for the x area\n');
elseif AngleD==0,
    r=centralPoint(1).*ones(size(c,2),1);
else
    k=tand(AngleD);
    b=centralPoint(1)-k*centralPoint(2);
    r=k.*c+b;
end

imagesc(image);
hold on
plot(c,r,'r-');
hold off;
colormap gray;
axis equal

 

posted @ 2015-12-13 16:59  wenglabs  阅读(2004)  评论(0编辑  收藏  举报