How can i save two points with lambda in a vector ?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Dimitris Kalogiros
2019-10-18
编辑:Dimitris Kalogiros
2019-10-18
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';
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!