andrewRowlinson / mplsoccer

Football pitch plotting library for matplotlib
MIT License
405 stars 82 forks source link

Implement Delaunay Tessellation #36

Closed stats94 closed 2 years ago

stats94 commented 3 years ago

Implemented Delaunay Tessellation using the scipy method mentioned in issue #12

I do have a slight concern that with other methods using polygon makes a bit more sense than here - given it is solely the edges that seem to matter here, but I'm not sure how important that is!

Screenshot 2021-06-09 at 15 55 34

andrewRowlinson commented 3 years ago

Thanks @stats94 for the contribution. On the comment about the polygons, it looks like scipy uses ax.triplot to visualise this:

https://github.com/scipy/scipy/blob/ac3b21908adc937c42d99bd67b177723d484a101/scipy/spatial/_plotutils.py#L37

This might work better than polygons. I think you could implement it as a triplot method in a similar way to plot (https://github.com/andrewRowlinson/mplsoccer/blob/6fefbe008181459665bc23d518eb35c09b2c9566/mplsoccer/_pitch_plot.py#L27). However, you might need to format Delaunay to return x & y for inputs to triplot.

Please could you also add an example python file to this directory: https://github.com/andrewRowlinson/mplsoccer/tree/master/examples/pitch_plots

The filename needs to start with "plot_". Have a look at the other examples for inspiration. The format auto-creates the docs. When making the example remember you can say it's contributed by you too and link your details, e.g. Twitter profile. There is more information on formatting the examples here: https://sphinx-gallery.github.io/stable/syntax.html.

Thanks again!

stats94 commented 3 years ago

If I use triplot it actually makes the Delaunay method a little redundant, because it will automatically use Delaunay triangulation by default. i.e. the below are equivalent. Should I keep the Delaunay method and make it a bit more explicit and in keeping with other methods such as ConvexHull/Voronoi, or is the implicit way preferred?

ax.triplot(x, y)

from scipy.spatial import Delaunay
coords = np.vstack([x, y]).T
delaunay = Delaunay(coords)
ax.triplot(x, y, delaunay.simplices)

Edit: Have made it so that both are possible. Guess it depends on whether it should be the default to go via the Delaunay method as to whether triangles should be the third or fourth parameter in triplot to make it a tad easier to plot; but that's relatively minor I would have thought!