set of points form a polygon?

2 Ansichten (letzte 30 Tage)
kai
kai am 24 Aug. 2020
Kommentiert: kai am 24 Aug. 2020
Hello,
Is there a way to tell if a set of vertices can form a closed polygon or not in genear or in matlab ?
Example:
[1,1], [3,1],[2,2] form a triangle when connected.
How do you conclude that these points can form a polygon.
Is there any algorithm to follow ?.
Thank you.
  2 Kommentare
KSSV
KSSV am 24 Aug. 2020
Always more than two non-collinear points can form a polygon. If they are on striaght line/ collinear they cannot and this can be obtained by using area; you can use polyarea to get the area. If area is zero then they are collinear. If you have a value they can form polygon.
kai
kai am 24 Aug. 2020
Thank you KSSV for you answer
it helped me.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Bruno Luong
Bruno Luong am 24 Aug. 2020
Bearbeitet: Bruno Luong am 24 Aug. 2020
If your list of points are ordered of the boundary of the polygonal, you can detect if the list of points self intersect thus NOT represent a valid polygonal by using polyshape, catch the warning or get the number of regions, if it's larger than 1 it's not valid:
EDIT: you can also use ISSIMPLIFIED function
>> x=rand(1,5)
x =
0.1419 0.4218 0.9157 0.7922 0.9595
>> y=rand(1,5)
y =
0.6557 0.0357 0.8491 0.9340 0.6787
>> issimplified(polyshape(x,y,'Simplify',false))
ans =
logical
0 % <= NOT VALID
  1 Kommentar
kai
kai am 24 Aug. 2020
Thank you Bruno Luong for commenting the question and helping me.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Elementary Polygons finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by