Examples¶

Let us triangulate a simple square

```import matplotlib.pyplot as plt
import numpy as np

import triangle as tr

A = dict(vertices=np.array(((0, 0), (1, 0), (1, 1), (0, 1))))
B = tr.triangulate(A)
tr.compare(plt, A, B)
plt.show()
``` In order to set maximum area of the triangles, we set the maxarea keyword

```import matplotlib.pyplot as plt
import numpy as np

import triangle as tr

A = dict(vertices=np.array(((0, 0), (1, 0), (1, 1), (0, 1))))
B = tr.triangulate(A, 'qa0.1')
tr.compare(plt, A, B)
plt.show()
``` If we want to decrease the area even further

```import matplotlib.pyplot as plt
import numpy as np

import triangle as tr

A = dict(vertices=np.array(((0, 0), (1, 0), (1, 1), (0, 1))))
B = tr.triangulate(A, 'qa0.01')
tr.compare(plt, A, B)
plt.show()
``` To do the same with a circle

```import matplotlib.pyplot as plt
import numpy as np

import triangle as tr

theta = np.linspace(0, 2 * np.pi, 33)[:-1]
pts = np.vstack((np.cos(theta), np.sin(theta))).T
A = dict(vertices=pts)
B = tr.triangulate(A, 'q')
tr.compare(plt, A, B)
plt.show()
``` ```import matplotlib.pyplot as plt
import numpy as np

import triangle as tr

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