Create a line of particular length and orientation

4 ビュー (過去 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 Center および File ExchangeSpectral Measurements についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by