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!