File Exchange

image thumbnail

Triangular Mesh Refinement

version (9.53 KB) by Dirk-Jan Kroon
This function will refine a triangular mesh with 4-split spline interpolation


Updated 16 Feb 2010

View License

This function "refinepatch" can refine any triangular mesh surface ( patch) with 4-split spline interpolation, see screenshot.

The spline interpolation of the face edges is done by the Opposite Edge Method, described in: "Construction of Smooth Curves and Surfaces from Polyhedral Models" by Leon A. Shirman

How it works:
The tangents (normals) and velocity on the edge points of all edges are calculated. Which are later used for b-spline interpolation when splitting the edges.
A tangent on an 3D line or edge is under defined and can rotate along the line, thus an (virtual) opposite vertex is used to fix the tangent and make it more like a surface normal.
B-spline interpolate a half way vertices between all existing vertices using the velocity and tangent from the edge points. After splitting a new face list is constructed with 4 times as many faces.

Some Matlab files are also available as MEX files to allow quick refinement of large meshes.

Please Leave a comment, if you find a bug, like the code or know improvements.

Cite As

Dirk-Jan Kroon (2020). Triangular Mesh Refinement (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (13)

Ali Afzali

Dear Dirk-Jan,
your code doesn't work!!!!! could you help me to run it?
The error is: make_halfway_vertices (line 42)
Any idea of what it could be?

Thanks in advance


Hey, I have a question if someone can help me
is there is any way to refine just portion (a certain number of faces) only not the complet mesh
Thank you

I need some help.
It generates an error at line 42 of the make_halfway_vertices saying : "
Error in make_halfway_vertices (line 42)
Any idea of what it could be?

I'm using Matlab 2015a

Thnaks Andrea


Great work yet again, Dirk!


Dear Dirk-Jan, this code has worked for some .ply files I am using, but there are a handful which are not working in your refinepatch method.

Are there certain criteria that must be met for this to work on a given triangulation?

Specifically I am using Sumner's camel-reference.obj file from the folder "camel poses from Figure 1"

The mex file throws an error which causes Matlab to exit. Has anyone else ran into this problem? Maybe the file does not have a certain necessary property for the method? Thanks


This is an excellent file that does exactly what it says it does. It worked the first time. I don't know why someone else gave it a bad rating - I think it's perfect as is.

ivan scardanzan

it refines patches as claimed !
and given that
a)matlab does not have a better alternative tool
b) the functionality is important
it deserves a good rating

Duane Hanselman

This code produces pretty pictures, but is poorly documented and poorly written. It needs improvement--thus the reason for a 2=Needs Improvement ranking.

Can the input variables be defined differently?
%[V,F] = Refine_Mesh(V,F)
% The variable V is a list of vertices xyz coordinates
% The variable F is a list of faces described by indices of the vertices.

How do these correspond to MATLAB triangulation function arguments?, e.g., from TRIMESH
%TRIMESH(TRI,X,Y,Z,C) displays the triangles defined in the M-by-3 face matrix TRI as a mesh. A row of TRI contains indexes into the X,Y, and Z vertex vectors to define a single triangular face.

Your code was written using R2007a, but you still use obsolete structure functions getfield and setfield. Why? For example, Eb=getfield(Et,['F' num2str(Pneig(j)) 'T' num2str(i)]);
Perhaps it would be better to not use structures at all? That is, avoid
Et=struct(); % Edge tangents
Vt=struct(); % Edge velocity
The use of structures seems to make the code very cumbersome.

The H1 line is not informative and it would be good to describe the general algorithm in the text file so folks do not have to find the journal article to get the general idea of what is being done.

There is no use of vectorization, but clearly much of this code could be vectorized.

In MATLAB new lines are free, so there is no need to cram multiple MATLAB statements on a single line. Doing so makes it difficult to follow the code and may impede the JIT accelerator.

I am willing to change my rating if the code is revised.

Dirk-Jan Kroon

Oops, i forgot that little function val_even:

function bin=val_even(val)

hazem wannous

To compile your code, i need to the function 'val_even' which is undefined.
can you send me this function.


Fixed NaN bug in case of all neighbor vertices
Fixed Crash bug in case of vertex not present in face-list.

Know also c-code files are available, and mesh no longer have to be closed.

Matlab code used an unknown function val_even , to determine even or odd value..

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux