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)

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)

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)

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)

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)
