mikolalysenko / alpha-shape

Any dimensional alpha shapes
https://mikolalysenko.github.io/alpha-shape
MIT License
74 stars 11 forks source link

How to use alpha-shapes with GeoJSON #3

Open nikolauskrismer opened 8 years ago

nikolauskrismer commented 8 years ago

The demo you provided looks great. Good work!

I tried to use your code to generate an alpha-shape around geographical coordinates, but here I am a bit stuck on how to use your return value. My code uses GeoJSON, so I first extracted points to calculate the alpha-shape from.

I am not sure what the returned value means, but first I thought that the returned array will contain coordinates as well. That's obviously not the case, since the values returned are far off the coordinates given (my coordinates are around 11.35 and 46.50, the values returned are often above 100). So I thought that the actual coordinates need to be read from the input value (that the returned array references the values in the input array). Using the parameter this way works somehow, but does not deliver anything near to the result I expected.

I created a JSFiddle 1 with the input array and the expected result: http://jsfiddle.net/Niko_K/weqfy733/ Could you please elaborate a bit on how to use your function's return value and how to exactly use you code to create an alpha-shape that is near the exact solution given in the JSFiddle (and not the red one that I get when calling your function with an alpha value of 10)?

asmarcz commented 5 years ago

Were you able to figure out the meaning of the return value? I'm struggling with it even with the example in README.

nikolauskrismer commented 5 years ago

No I was not able to figure out what the return value means. Sorry...

Sc222 commented 2 years ago

@nikolauskrismer, @asmarcz

I analyzed demo code and figured out that return values are indices of original points array.

https://github.com/mikolalysenko/alpha-shape/blob/master/viewer.js#L45-L57

alphaHull is the return value of the algoritm here. points is the original array of points.

And to get array of calculated contours you can simply use this code:

for(let i=0; i<alphaHull.length; i++) {
    let cell = alphaHull[i]; // cell is calculated contour (there can be many of them)
    for(var j=0; j<cell.length; j++) {
      console.log(points[cell[j]]); // cell[j] contains index of contour point in original array, so we should use points[cell[j]] to get coordinates
    }
  }
asmarcz commented 2 years ago

Thank you, random stranger, I've completely forgotten, what is the purpose of the library and barely remember where I've used it. I will definitely check it out later tho!