Create a line of particular length and orientation

3 visualizaciones (últimos 30 días)
Ramesh Bala
Ramesh Bala el 24 de Jul. de 2019
Comentada: Ramesh Bala el 25 de Jul. de 2019
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') ;

Respuesta aceptada

darova
darova el 24 de Jul. de 2019
Draw line in 45 degree approximately at [25,25]
x = [0 5]+rand+25;
y = [0 5]+rand+25;
plot(x,y)
  9 comentarios
darova
darova el 25 de Jul. de 2019
Editada: darova el 25 de Jul. de 2019
What am i supposed to do with it?
Ramesh Bala
Ramesh Bala el 25 de Jul. de 2019
I'm interested to know whether the 25,25 line can make such bisection points to be used

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Spectral Measurements en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by