# Making a triangular plot

In MATLAB there is a function `triplot` (2-D triangular plot - MATLAB triplot) which can be used to make a triangular plot given a connectivity matrix and the corresponding `(x, y)` values. Is there a similar function in Julia for this purpose? and similarly e.g. for `trimesh` / `trisurf`.

I did see https://github.com/pazner/Triplot.jl previously, although it no longer seems to compile on the current version of Julia.

There is one (and probably more) topic about this matter here in the forum (did a quick search but couldn’t find it/them). But see GMT example here.

1 Like

I think the OP is talking about triangle mesh plots.

@legola18 take a look at Meshes.jl and MeshViz.jl if you are interested in triangulations and visualizations of these results. Voronoi-Delaunay triangulations are on the roadmap, but you have other packages out there that generate the connectivities.

2 Likes

Ok, then in GMT that is done by the triangualate function. Have no example on its usage but would be

``````G = triangulate(data, region=(...), spacing=...)
``````

where `data` is Mx3 matrix or a `GMTdataset` type and `G` the output grid.

2 Likes

Thanks @juliohm, this was the simplest for me to understand. It’s quite easy to implement with these packages actually (for `triplot`, anyway), e.g:

``````"""
triplot(T, x, y)

Generates and plots a `SimpleMesh` object for a triangulation with triangle connectivity matrix `T`
and points defined by vectors `x` and `y`. The first output is the `SimpleMesh object, and the
second plot is the scene containing the plot.
"""
function triplot(T, x, y)
# Convert into vector of tuples of points
points = Meshes.Point2[(x[i], y[i]) for i in 1:length(x)]
# Connect the points using the provided connectivity matrix T
connec = Meshes.connect.([(T[i, 1], T[i, 2], T[i, 3]) for i in 1:size(T, 1)])
# Mesh
mesh = Meshes.SimpleMesh(points, connec)
h = MeshViz.viz(mesh, showfacets = true)
return mesh, h
end
mesh, h = triplot(elements, nodes[:, 1], nodes[:, 2])
``````
1 Like