How can I create a fine contour from set of points?

6 ビュー (過去 30 日間)
ttopal
ttopal 2018 年 9 月 27 日
回答済み: ttopal 2018 年 9 月 28 日
Hi,
I am creating different contours using (x,y) coordinate of points.
Say if i want to create a triangle I would use
x1=(0,0)
x2=(8,-4)
x3=(8,4)
x4=(0,0)
giving me this contour:
But, i need more points on this contour, especially near the edges:
which for various contours i calculate manually.
Now I want to automate this, and add those points near the edges with a given length.
Should I write a for loop, calculate the distance between neighboring points, divide by given length, and use to get the additional points and repeat?
Or is there a better way?

採用された回答

KSSV
KSSV 2018 年 9 月 27 日
x1=[0,0] ;
x2=[8,-4] ;
x3=[8,4] ;
x4=[0,0] ;
P = [x1 ; x2 ; x3 ; x4] ;
plot(P(:,1),P(:,2)) ;
N = 10 ;
t = linspace(0,1,N)' ;
L = cell(3,1) ;
for i = 1:3
L{i} = [P(i,1)+(P(i+1,1)-P(i,1))*t P(i,2)+(P(i+1,2)-P(i,2))*t] ;
end
L = cell2mat(L) ;
hold on
plot(L(:,1),L(:,2),'.r')
  1 件のコメント
ttopal
ttopal 2018 年 9 月 28 日
Thank you for your time, i thought of linspace too, but the issue is, i need this additional points to be close to edges, sometimes i would have to take N=100 and say if i have shape like this:
i would end up with hundreds of points which increases the System size for later steps dramatically. That's why i am trying to give a predefined size and add points only close to the edges.

サインインしてコメントする。

その他の回答 (1 件)

ttopal
ttopal 2018 年 9 月 28 日
Using @KSSV answer this works a treat:
x1=[0,0] ;
x2=[8,-4] ;
x3=[8,4] ;
x4=[0,0] ;
P = [x1 ; x2 ; x3 ; x4] ; % set of points
plot(P(:,1),P(:,2)) ;
N = size(P,1)-1 % number of lines
ratio = 0.04 %how close to the edges you need the points to be added
t = [0+ratio;1-ratio]; % find both ends of the line
L = cell(N,1) ;
for i = 1:N
L{i} = [P(i,1)+(P(i+1,1)-P(i,1))*t P(i,2)+(P(i+1,2)-P(i,2))*t] ;
end
L = cell2mat(L) ;
hold on
plot(L(:,1),L(:,2),'.r')

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by