Skip to content
Advertisement

Find boundary points of xy coordinates

I have a text file with xy-coordinates called xy.txt.

JavaScript

I read the file using

JavaScript

and I can plot the points with

JavaScript

Visually the data looks as follows:

enter image description here

I want to retrieve the xy-coordinates of the points that form the boundary of the shape. Answers on similar questions suggest to use Concave Hull. With the help of this blog I write the following code:

JavaScript

The output looks like

enter image description here

Clearly the red points are not the boundary points. Some are enclosed by other points and they all are different from the original points. How do I define the boundary points in terms of the original points? Please advice

Advertisement

Answer

When I try to reproduce your code the convexHull function works perfectly. I changed your code so that the positions of black and red circles are rounded in the same way. And I reduced the radius of the red circles so you can better see if everything fits.

JavaScript

Result:

enter image description here

Update: If you need the concave parts of the boundary, too, you can use the python package alphashape instead and calculate the alpha shape. The points in your test data are very close, so I had to normalize the coordinates and adjust the alpha value to get reasonable results.

JavaScript

Result:

enter image description here

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement