Create a line of particular length and orientation
조회 수: 9 (최근 30일)
이전 댓글 표시
I found a code which creates line in arbitrary space and e verywhere,I couldn't control it's position as randi is used.
Let's say I want the line in 45 degree and at my desired x,y mostly at centre (25,25)?how to do it ?
clear all;clc;close all
hf1=figure(1);grid on
ax1=hf1.CurrentAxes;
ax1.DataAspectRatio=[1 1 1];
hold all
x_span=50;y_span=50; % half size of [0 0] centred workspace
x_res=.1 ; % spatial resolution,on both x ad y
x_range=(0:x_res:x_span); % test area
y_range=(0:x_res:y_span);
plot([x_range(1) x_range(end) x_range(end) x_range(1) x_range(1)],[y_range(1) y_range(1) y_range(end) y_range(end) y_range(1)],'LineWidth',2,'Color','b')
ax1.XTick = (x_range(1):10*x_res:x_range(end));
ax1.YTick = (y_range(1):10*x_res:y_range(end));
Nd = randi([3 25],1,1);
d_ang_res=2*pi/360;
d_ang_range=[0:d_ang_res:2*pi-d_ang_res];
d_ang_target=d_ang_range(randi(numel([d_ang_range]),1,1));
x_d=x_range(randi(numel(x_range),1,1));
y_d=y_range(randi(numel(y_range),1,1)) ;
plot([x_d-Nd*x_res x_d+Nd*x_res],[y_d-Nd*x_res y_d+Nd*x_res], 'LineWidth',1, 'Color','k') ;
댓글 수: 0
채택된 답변
darova
2019년 7월 24일
Draw line in 45 degree approximately at [25,25]
x = [0 5]+rand+25;
y = [0 5]+rand+25;
plot(x,y)
댓글 수: 9
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!