How would I be able to have 2 lines moving apart at a given rate? For example, 2 lines (L1 and L2) both starting at (0,0) and then moving apart incrementally to L1=x=1, L2=x=-1; then L1=x=2 L2=x=-2 and so on.

댓글 수: 5

Geoff Hayes
Geoff Hayes 2016년 6월 12일
Conrad - what is the y-coordinate as the two lines move apart? What is the end-point of each line (since the origin for both is (0,0))? Please provide more details.
Conrad Suen
Conrad Suen 2016년 6월 15일
Would the y coordinate matter? If the y coordinate helps give a bounds for the line, then any y value could be used. Essentially I was wondering how I could code 2 arbitrary lines spreading apart.
KSSV
KSSV 2016년 6월 15일
I don't think you would be able to draw two lines with the give information. One more condition must be specified like the angle between the two lines, which helps in calculating the slopes of each lines.
Conrad Suen
Conrad Suen 2016년 6월 15일
The lines would be vertical (simply x=constant). There is no way to plot lines moving apart from one another? I attached a picture to possibly help. I can restrict the y coordinate to whatever value needed (ie y cannot be greater than 10)
I want to do something like this except each line needs to be the same length.
t = 0;
last = 10;
step = 0.1;
while t <= last
k=0
i=5
k=0
% x=[k+t,k-t]
% y=[5,-5]
x=[t,t]
y=[-k+t,k-t];
plot (x,y)
drawnow
t = t+step;
hold on
end

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

 채택된 답변

Vidya Viswanathan
Vidya Viswanathan 2016년 6월 16일

0 개 추천

Hi Conrad,
Is this what you are looking for?
x=[-2:0.1:2];
y=[-10 10];
x=repmat(x,[2 1]);
plot(x,y)
This code snippet gives the following figure:
In this case, I have considered only two points in the y-axis. If you need multiple points between your required limit (say -10 and 10), you can modify the code in the following manner:
y=[-10:0.1:10];
x=[-2:0.1:2];
x=repmat(x,[length(y) 1]);
plot(x,y)
You'll basically get the same figure but will multiple data points in each straight line. I hope this helps.
Regards,
Vidya Viswanathan

댓글 수: 1

Almost! I figured it out after some tinkering throughout the day; here's what I came up with:
close all
clear
clc
t = 0;
last = 10;
step = 0.1;
while t <= last
x=[t,t];
z=[-t,-t];
y=[5,-5];
plot (x,y)
plot (z,y)
drawnow
t = t+step;
axis equal
hold on
end
hold on

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2016년 6월 12일

댓글:

2016년 6월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by