No BSD License  

Highlights from
gridtrimesh

5.0

5.0 | 10 ratings Rate this file 24 Downloads (last 30 days) File Size: 72.58 KB File ID: #14646
image thumbnail

gridtrimesh

by Willie Brink

 

13 Apr 2007 (Updated 13 Apr 2007)

Fits a square grid surface of the form z = f(x,y) to a triangular mesh surface.

| Watch this File

File Information
Description

The function GRIDTRIMESH fits a surface of the form Z = F(X,Y) to a given triangular mesh. Inputs X and Y are assumed to be produced by something similar to MESHGRID and the result could then be visualized by a simple SURF(X,Y,Z).

The triangular mesh on which this function operates should be defined in the usual way by two matrices F and V. MATLAB functions that use similar representations include TRIMESH, TRISURF and REDUCEPATCH. The included example file BEETHOVEN.MAT contains two such matrices.

A main advantage that this function has over the internal function GRIDDATA is that it operates not only on the set of vertices but also on the given triangulation. GRIDDATA first performs a Delaunay triangulation on the projected data points and subsequently always yields a surface that has a convex domain in the xy-plane. Another major drawback of GRIDDATA is that it handles surfaces that are not so-called 2.5D poorly (a "2.5D" surface has the property that for any xy-pair there exists at most one z-value on the surface, e.g. any function z = f(x,y)). This is because GRIDDATA projects all points to the xy-plane and then triangulates them without considering their original positions in 3-space. GRIDTRIMESH, on the other hand, considers all intersections that the ray through a particular gridpoint makes with the surface in 3D and then picks the maximum z-value. This emulates the idea of dropping a piece of cloth over the surface from above (i.e. from somewhere on the positive z-axis).

Another favourable trait of this function is its speed. I've tested it on the well-known Stanford bunny that consists of approximately 70,000 triangles. For a 100-by-100 grid (which is 10,000 points to be sampled) the function executes in about 2.4 seconds.

For those requiring more speed a MEX version of the function, called MXGRIDTRIMESH, is also supplied. This function may be used in exactly the same manner and produces exacly the same answer as GRIDTRIMESH. But since MXGRIDTRIMESH was written in C and then compiled with MEX it performs better. It required about 0.2 seconds for the Stanford bunny on a 100-by-100 grid and only about 2 seconds for a 1,000-by-1,000 grid (a million points!!).

The attached zip-file also includes an example script called DEMONSTRATION which can be run directly (you may need to recompile MXGRIDTRIMESH first, however).

CAUTION: at this stage the inputs X and Y must be generated by meshgrid(x,y) where x and y are monotonically increasing vectors. The function might go into an infinite loop if this is not the case!!

MATLAB release MATLAB 7.0.4 (R14SP2)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (11)
14 Apr 2007 Ali Özgül

More thanks, very nice application and documentation.

16 Apr 2007 Luther Terblanche

Mooi stukkie werk Willie. Trots op jou!

10 May 2007 Michael Bernailtks

Excellent program and good documentation

14 Jan 2008 Matthias Krueger

Thank you very much for this function! Works efficiently and yields very good results!

28 Apr 2008 Frank Omar

Hola que tal necesito intersecar una esfera de Fermi fcc con un octaedro

05 Sep 2008 Leilei Chen

Thank you very much for your Excellent program and good documentation ! It Works efficiently and yields very good results!
However I'd like to point out a small bug which can be easily modified in MXGRIDTRIMESH.C . That is you considered rcond(A) problem in GRIDTRIMESH.M but not in MXGRIDTRIMESH.C . I hope you can update it when you are free :)

25 Nov 2008 David Gingras

Very nice and fast!
This function takes care of non-convex surface with holes.
Good job!

14 May 2009 Johannes Korsawe

Really good. Nice. Fast. With C support. Great.

19 Jun 2009 Óscar J. Rubio Martín  
30 Jul 2009 piao lin

wonderful function!

11 Dec 2010 Emma Brazel

Great function! This function emulates the idea of dropping a piece of cloth over the surface from above...I was just wondering how to go about doing the same but from below, so that you end up with a grid of the bottom half of the 3D mesh surface. New to this forum so any replies appreciated. Thanks!

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
approximation Willie Brink 22 Oct 2008 09:09:15
interpolation Willie Brink 22 Oct 2008 09:09:16
square Willie Brink 22 Oct 2008 09:09:16
grid Willie Brink 22 Oct 2008 09:09:16
fitting Willie Brink 22 Oct 2008 09:09:16
triangular Willie Brink 22 Oct 2008 09:09:16
surface Willie Brink 22 Oct 2008 09:09:16
mesh Willie Brink 22 Oct 2008 09:09:16
face yuli zhang 04 May 2011 05:12:43
grid iae 07 Jul 2011 09:33:43
fitting iae 07 Jul 2011 09:33:55
face iae 07 Jul 2011 09:34:06
face Haosong 23 Jul 2011 03:07:12

Contact us at files@mathworks.com