[Matplotlib-users] Matplotlib with invalid triangulations
Pat Prodanovic
pprodano at gmail.com
Sat Nov 19 07:24:12 EST 2016
Hello,
I am using JR Shewchuk's Triangle to create triangulations for use in
floodplain modeling. I am using a city's digital terrain model with
hundreds of thousands of breaklines that constrain where triangles can
form in the triangulations (streets, rivers, etc). Triangle does this
very efficiently.
Sometimes the input topology I am using has bad inputs which makes
Triangle create zero area elements. When I import these triangulations
to Matplotlib I get the error that such triangulations are invalid (when
using the LinearTriInterpolator() method). I understand the trapezoid
map algorithm implemented requires only valid triangulations. So far, so
good.
The option of cleaning the input topology before using Matplotlib
exists, but it is really cumbersome. Rather than topology cleaning, am I
am able to somehow throw out the zero area elements from the call to
LinearTriInterpolator() method, and still use the triangulation in
Matplotlib? My other alternative is to use something other than
trapezoidal map algorithm, but this is just not computationally efficient.
I've reproduced the following example that illustrates the problem in a
small code snippet. Any suggestions?
Thanks,
Pat Prodanovic
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
import matplotlib.tri as mtri
import numpy as np
# manually construct an invalid triangulation having a zero area element
x = np.array([0.0, 1.0, 1.0, 1.0, 2.0])
y = np.array([1.0, 0.0, 2.0, 1.0, 1.0])
z = np.zeros(5)
triangles = np.array( [[0, 1, 2], [1, 3, 2], [1, 4, 2], [0, 4, 1]])
# create a Matplotlib Triangulation
triang = mtri.Triangulation(x,y,triangles)
# to perform the linear interpolation
interpolator = mtri.LinearTriInterpolator(triang, z)
m_z = interpolator(1.0, 1.0)
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
More information about the Matplotlib-users
mailing list