MATLAB Answers

How can i save two points with lambda in a vector ?

조회 수: 2(최근 30일)
Jan  Nabo
Jan Nabo 2019년 10월 18일
댓글: Jan Nabo 2019년 10월 22일
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

답변(1개)

Dimitris Kalogiros
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';
  댓글 수: 1
Jan  Nabo
Jan Nabo 2019년 10월 22일
function out = Randerzeugen(xwert,ywert,X,Y,isInside,block1,randdicke)
sz_x=size(xwert,1);
out=false(size(X));
if (~isInside == true)
Points=[xwert(:) ywert(:)];
Points=[Points;Points(1,:)];
numPoints=size(Points,1);
Lambda= 0:0.25:1;
for n=1:numPoints-1
out = out | (Points(n,1)+Lambda *( Points(n,2)-Points(n,1))) <= randdicke*2;
end
elseif (isInside == true)
block1=~block1;
for i=1:sz_x
out=out | (((X-xwert(i)).^2)+((Y-ywert(i)).^2) <= randdicke*2);
end
out= and(out,block1);
end
end
the problem is... i have to save the points from the calculation and compare it with my logical "out" you can see that in if(~isInside == true) there i want to save the points and compare it later with the logical out. it will be a 3D-Object. But how can i use my formula to calculate each points.

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by