Create a line of particular length and orientation
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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') ;
0 comentarios
Respuesta aceptada
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
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!