Coder Social home page Coder Social logo

holes in triangulation about triangle HOT 4 CLOSED

drufat avatar drufat commented on August 30, 2024
holes in triangulation

from triangle.

Comments (4)

mdsumner avatar mdsumner commented on August 30, 2024

Triangle itself can accept a "seed point" for each hole, and it will cull them out from the inside - but otherwise get the centroids of the resulting triangles and classify them by in-polygon test with your inputs and cull from that.

The interface accepts these seed points, search for "hole" here: http://dzhelil.info/triangle/

from triangle.

mikedh avatar mikedh commented on August 30, 2024

Thanks for looking- I am passing holes (an (n,2) array of seed points) in the example above. I think the data isn't making it where it needs to go in this wrapper, as the same logic works properly in the meshpy.triangle wrapper.

from triangle.

mdsumner avatar mdsumner commented on August 30, 2024

Ah, sorry about that - reacted too fast! It's great to have an example to follow - I'm keen to learn Python.

from triangle.

mikedh avatar mikedh commented on August 30, 2024

Actually, this was the result of my segments not being closed, when that was fixed it worked fine:

import triangle
import triangle.plot
import matplotlib.pyplot as plt

import numpy as np


if __name__ == '__main__':
    ### generate a circle with a hole in it                         
    theta = np.linspace(0.0, np.pi * 2, 25)
    circle = np.column_stack((np.cos(theta),
                              np.sin(theta)))

    # exterior plus interior                                        
    vertices = np.vstack((circle, circle * .5))
    segments = np.column_stack((np.arange(0, len(circle) - 1),
                                np.arange(1, len(circle))))
    # make sure segments are closed
    segments %= len(circle) - 1
    
    # add the interior                                              
    segments = np.vstack((segments,
                          segments + len(circle) + 1))
    
    # the hole is in the middle. like a doughnut                    
    holes = np.array([[0,0]], dtype=np.float64)

    # args to pass to triangulate                                   
    args = {'segments': segments,
            'vertices': vertices,
            'holes':    holes}

    t = triangle.triangulate(args, 'pq0D')
    triangle.plot.plot(plt.axes(), **t)
    plt.show()

In testing, triangle.triangulate was pretty much exactly twice as fast as meshpy.triangle and has a nicer API. After testing, I changed the default in trimesh to use triangle.triangulate- thanks for the great package!

from triangle.

Related Issues (20)

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.