Simple ExamplesΒΆ

Let us triangulate a simple square

import triangle
import triangle.plot
from numpy import *
import matplotlib.pyplot as plt

A = dict(vertices=array(((0,0), (1,0), (1, 1), (0, 1))))
B = triangle.triangulate(A)
triangle.plot.compare(plt, A, B)
plt.show()

(Source code, png, hires.png, pdf)

_images/ex1.png

In order to set maximum area of the triangles, we set the maxarea keyword

import triangle
import triangle.plot
from numpy import *
import matplotlib.pyplot as plt

A = dict(vertices=array(((0,0), (1,0), (1, 1), (0, 1))))
B = triangle.triangulate(A, 'qa0.1')
triangle.plot.compare(plt, A, B)
plt.show()

(Source code, png, hires.png, pdf)

_images/ex2.png

If we want to decrease the area even further

import triangle
import triangle.plot
from numpy import *
import matplotlib.pyplot as plt

A = dict(vertices=array(((0,0), (1,0), (1, 1), (0, 1))))
B = triangle.triangulate(A, 'qa0.01')
triangle.plot.compare(plt, A, B)
plt.show()

(Source code, png, hires.png, pdf)

_images/ex3.png

To do the same with a circle

import triangle
import triangle.plot
from numpy import *
import matplotlib.pyplot as plt

theta = linspace(0, 2*pi, 33)[:-1]
pts = vstack((cos(theta), sin(theta))).T
A = dict(vertices=pts)
B = triangle.triangulate(A, 'q')
triangle.plot.compare(plt, A, B)
plt.show()

(Source code, png, hires.png, pdf)

_images/ex4.png
import triangle
import triangle.plot
from numpy import *
import matplotlib.pyplot as plt

theta = linspace(0, 2*pi, 33)[:-1]
pts = vstack((cos(theta), sin(theta))).T
A = dict(vertices=pts)
B = triangle.triangulate(A, 'qa0.05')
triangle.plot.compare(plt, A, B)
plt.show()

(Source code, png, hires.png, pdf)

_images/ex5.png