Create a line of particular length and orientation

조회 수: 9 (최근 30일)
Ramesh Bala
Ramesh Bala 2019년 7월 24일
댓글: Ramesh Bala 2019년 7월 25일
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') ;

채택된 답변

darova
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
darova
darova 2019년 7월 25일
편집: darova 2019년 7월 25일
What am i supposed to do with it?
Ramesh Bala
Ramesh Bala 2019년 7월 25일
I'm interested to know whether the 25,25 line can make such bisection points to be used

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by