Giter Site home page Giter Site logo

hakanseven12 / delaunator-python Goto Github PK

View Code? Open in Web Editor NEW
48.0 48.0 5.0 117 KB

Fast Delaunay triangulation of 2D points implemented in Python.

License: GNU Lesser General Public License v2.1

Python 100.00%
2d algorithm computational-geometry delaunator delaunay fast mapbox python triangulation

delaunator-python's People

Contributors

hakanseven12 avatar stormsurge95 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

delaunator-python's Issues

Python 3.12 warning

Delaunator.py:276: SyntaxWarning: invalid escape sequence '\ '
apparently it doesn't like the comment in _legalize

Divide by Zero (again)

So, like others, I've been experiencing a divide by zero error in the circumradius function; however, it's not due to duplicate points.

My error is due to a set of three points that are in a straight line with each other.

The points in particular that are causing my error are: (137, 525), (137, 509), and (137, 392).

Divide by zero encountered in true_divide

I get a divide by zero error if I run the below:

Python 3.9.2 (default, Feb 24 2021, 13:30:36)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> from Delaunator import Delaunator
>>> points = np.random.randint(1,1677.7215,size=(10000,2))
>>> triangles = Delaunator(points).triangles
/Users/jamie/Downloads/Delaunator.py:427: RuntimeWarning: divide by zero encountered in true_divide
  d = 0.5/(dx * ey - dy * ex)

Am I doing something wrong?

Divide by Zero Error

Hi,

When I run the starter code, I get a divide by zero error:

from Delaunator import Delaunator
points = [[168, 180], [168, 178], [168, 179], [168, 181], [168, 23], [168, 23]]

triangles = Delaunator(points).triangles
print(triangles)

and the output is:

aryamansharda@Aryamans-MacBook-Pro Delaunay % python3 LowPolygonArt.py
Traceback (most recent call last):
  File "LowPolygonArt.py", line 19, in <module>
    triangles = Delaunator(points).triangles
  File "/Users/aryamansharda/Downloads/Delaunay/Delaunator.py", line 19, in __init__
    triangles = self.constructor(coords)
  File "/Users/aryamansharda/Downloads/Delaunay/Delaunator.py", line 41, in constructor
    triangles = self.update(coords)
  File "/Users/aryamansharda/Downloads/Delaunay/Delaunator.py", line 100, in update
    r = circumradius(i0x, i0y, i1x, i1y, coords[2 * i], coords[2 * i + 1])
  File "/Users/aryamansharda/Downloads/Delaunay/Delaunator.py", line 427, in circumradius
    d = 0.5/(dx * ey - dy * ex)
ZeroDivisionError: float division by zero

performance

Hey all, Thanks for the useful program! Do the input point sets need to be integers for the code to be optimally performant? I'm thinking of using this routine in a Lloyd smoothing/mesh generation code written in Python, but it requires float points for the point sites.

Overall, is the performance anticipated to be similar to that of the javascript implementation?

Thanks.

ask for advice

What an interesting show! And I'd like to ask,how to use your code to triangulate an image ?
thank you

IndexError: list assignment index out of range

Hello, When I run test.py, it has a problem. Could you solve this problem? Thank u

Traceback (most recent call last):
  File ".\Test.py", line 12, in <module>
    triangles = Delaunator(points).triangles
  File "D:\Workplace\bigdata\Delaunator-Python-master\Delaunator.py", line 19, in __init__
    triangles = self.constructor(coords)
  File "D:\Workplace\bigdata\Delaunator-Python-master\Delaunator.py", line 41, in constructor
    triangles = self.update(coords)
  File "D:\Workplace\bigdata\Delaunator-Python-master\Delaunator.py", line 237, in update
    t = self._addTriangle(q, i, e, -1, self.hullTri[e], self.hullTri[q])
  File "D:\Workplace\bigdata\Delaunator-Python-master\Delaunator.py", line 361, in _addTriangle
    self._triangles[t] = i0
IndexError: list assignment index out of range

Library doesn't work for random points

I randomly distributed a bunch of points and the result was triangulation that was completely wrong, with various edges overlapping/criss-crossing each other (and to be clear, not connecting at any vertex), I suspect the following warnings might be relevant:

Delaunator.py:419: RuntimeWarning: overflow encountered in long_scalars
dy * (ex * cp - bp * fx) +
Delaunator.py:420: RuntimeWarning: overflow encountered in long_scalars
ap * (ex * fy - ey * fx) < 0
Delaunator.py:418: RuntimeWarning: overflow encountered in long_scalars
return dx * (ey * cp - bp * fy) -\

The issue happens every time except for when I provide a set of trivial points, i.e 5 points with 4 at the corners and 1 in the middle or just 4 at the corners will triangulate perfectly but a bunch of randomly generated points just fails to triangulate at all.

So to clarify, the triangulation seems to be failing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.