I have the coordinates of the above two shapes imported from a CAD software, however when I plot the shape the points are not in order. Is there a method to order the coordinates so that points on the perimeter of the shape that are side by side are next to each other in the matrix.
If there is any mathematical method that would help me, I am willing to understand it and code it myself. Thank you

댓글 수: 6

KSSV
KSSV 2022년 5월 24일
When you extract it from CAD, you can extract into a stl file right?
Attach your data, there are some methods which can be tried. Read about boundary
Ahmed Abdulla
Ahmed Abdulla 2022년 5월 24일
I attached the sample data for the anchor shape, i tried boundary but for some reason it skips some points ans changes the shape :(
Ahmed Abdulla
Ahmed Abdulla 2022년 5월 24일
Thanks @KSSV, This is the result of using boundary with a shrink factor of 1, however a few points get ignored. Is there a way of using all points?
Walter Roberson
Walter Roberson 2022년 5월 24일
use a different shrink factor?
Ahmed Abdulla
Ahmed Abdulla 2022년 5월 24일
@Walter Roberson Here I am using a shrink factor of 1 which is the highest I can go :(
DGM
DGM 2025년 7월 10일
I can't imagine there exists any CAD software which represents polygons (internally or externally) using no information other than a list of unordered vertices. Depending on the file, the object might not be represented as a simple polygon, but at some point, this became a polygon.
That's not to say that these vertices have no order. They're sorted by their x-value -- which is precisely what would happen to the vertex list if you imported an STL using FEX #51200, or if you imported it using any other FEX decoder and then used unique() to prune the vertex list without using the 'stable' flag. These vertices would never appear in an STL file in this order. Granted, I'm guessing it's an STL, but all we could ever do is guess what the file was.
My point is that if you want connectivity information, it's probably worth trying to go back to the source, instead of trying to inaccurately and inconsistently regenerate information that (at some point) you already had.

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

답변 (1개)

KSSV
KSSV 2022년 5월 24일

0 개 추천

load('A.mat') ;
x = A(:,1) ; y = A(:,2) ;
n = length(x) ;
iwant = zeros(n,2) ;
i = 1 ;
iwant(i,:) = [x(i) y(i)] ;
x(i) = [] ; y(i) = [] ;
while ~isempty(x)
i = i+1;
idx = knnsearch([x y],iwant(i-1,:));
iwant(i,:) = [x(idx) y(idx)] ;
x(idx) = [] ; y(idx)= [];
end
iwant(end+1,:) = iwant(1,:) ;
plot(iwant(:,1),iwant(:,2))

댓글 수: 3

Ahmed Abdulla
Ahmed Abdulla 2022년 5월 24일
Thank you @KSSV for your amazing effort. If you notice in the bottom left there is distorion where the code miss chose the points. I tried with several of my shapes and the problem persists :(
KSSV
KSSV 2022년 5월 24일
편집: KSSV 2022년 5월 24일
Lets randomize the points and run the code.
load('A.mat') ;
x = A(:,1) ; y = A(:,2) ;
n = length(x) ;
idx = randperm(n,n) ;
x = x(idx) ; y = y(idx) ;
iwant = zeros(n,2) ;
i = 1 ;
iwant(i,:) = [x(i) y(i)] ;
x(i) = [] ; y(i) = [] ;
while ~isempty(x)
i = i+1;
idx = knnsearch([x y],iwant(i-1,:));
iwant(i,:) = [x(idx) y(idx)] ;
x(idx) = [] ; y(idx)= [];
end
iwant(end+1,:) = iwant(1,:) ;
plot(iwant(:,1),iwant(:,2))
Ahmed Abdulla
Ahmed Abdulla 2022년 5월 24일
Thank you @KSSV for your efforts I really appreciate it. Unfortunately this doesnt work every time and I am trying to make a generalised function that will work for any shape and at all times

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

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

2022년 5월 24일

댓글:

DGM
2025년 7월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by