How can i save two points with lambda in a vector ?
3 views (last 30 days)
Show older comments
i have four coordinates and my formula is that i want from two points for example P1(-1|1) and P2(1|1) many points on this "connection or line". I have P3(1|-1) and P4(-1|-1)
so vector for two points is v = P1 + Lambda + (P2 -P1) for Lambda is [0:0.2:1] so i can make more points for this points and connected them.
But how can i transform this in matlab with a for-loop ?
I want only rectangle so the connection and calculation is possible for P1 and P2, P2 and P3, P3 and P4.
------------------------
index
for i =1:4
for Lambda = 0:0.25:1;
v(index) = x(i),y(i) + Lambda * ( x(i+2),y(i+2) - (x(i),y(i)))
index=index+1;
end
i tried this but i don't think that is right
0 Comments
Answers (1)
Dimitris Kalogiros
on 18 Oct 2019
Edited: Dimitris Kalogiros
on 18 Oct 2019
Run this:
clear; clc; close all;
%input points
Points=[1 1; -1 1; -1 -1; 1 -1 ];
% make 'Points' to represent an closed line
Points=[Points; Points(1,:)];
% plot rectangular, using a loop
figure(1); hold on;
numPoints=size(Points,1);
for n=1:numPoints-1
n_start=n;
n_end= 1+n;
figure(1); plot(Points(n_start:n_end,1), Points(n_start:n_end,2),'-b*', 'linewidth', 1);
zoom on; grid on;
end
% make figure looking better
axis([min(Points(:,1))-1 max(Points(:,1))+1 min(Points(:,2))-1 max(Points(:,2))+1]);
ax=gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
See Also
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!