I need to interpolate scattered data on a model represented by a 3D surface in Matlab. I tried it using "scatteredInterpolant", but the results were quite bad. This function only allows to specify the query points but not the 'ConnectivityList' because internally it performs its own Delaunay triangulation from the specified point set. However, I perfectly know not only the points but also the 'ConnectivityList', so I can create a Matlab 'triangulation representation' using "triangulation".
So my question is the following. Is there any way to give a predefined 'triangulation' to "scatteredInterpolant"? If it is not possible, is there any other Maltab function or class able to perform data interpolation on a previously triangulated 3D surface instead of performing its own triangulation from the query points?
I'd like to plot grouped data in a scatter plot with marginal histograms using Matlab. There is a function to do just that: scatterhist.
However, I'm dealing with some visualization issues: I have a large number of data points and many points are printed one over another (changing marker type and marker size doesn't help).
Therefore, I'd prefer to substitute individual points from each group with their convex hull; i.e., if I have 5 groups, the plot would show 5 convex hulls and keep marginal histograms generated from the original data points. Do you know if there is an easy way to do this or if this has already been implemented?
In the end, I came up with the following:
Use scatterhist to create the scatter plot with marginal histograms.
hold on
Use convhull to get the convex hull for each group of points.
Use fill to draw the convex hull.
I want to know how griddata uses linear interpolation.
Does it just consider like four neighbor points of the point where we want to find the value or uses the whole convex hull?
The docs for griddata will guide you in this. Essentially, it does a delaunay triangulation of your point set, then for any new point, determine which simplex the point falls in. Interpolation within a simplex is linear. Thus in 2 dimensions, three points define a triangle, and 3 points determine a locally planar model for z(x,y).
Given a point set (i.e a 3XN array of vertices), how can I triangulate it using matlab?
Assuming the point set does represent some surface of an object, and does not contain any noise.
EDIT:
The chosen answer gives a way to create the tetrahedrons of a mesh. I was looking for triangulation; for my specific case of a convex shape, the convex hull (using convhulln as suggested in the answer's comments) was enough.
To create a Delaunay triangulation, you can use the class DELAUNAYTRI:
You create a triangulation object by calling
DT = DelaunayTri(coordinates);
where coordinates is a N-by-3 (or 2) array of vertex coordinates.
To access the triangulation, call
tri = DT.triangulation;
To plot, call e.g.
patch('Vertices',DT.X,'Faces',DT.triangulation)
use delaunay3 and convert the tetrahedral mesh into a triangular one
http://www.mathworks.com/matlabcentral/fileexchange/5355-toolbox-graph/content/toolbox_graph/tet2tri.m
I have a polyhedron, with a list of vertices (v) and surfaces (s). How do I break this polyhedron into a series of tetrahedra?
I would particularly like to know if there are any built-in MATLAB commands for this.
For the convex case (no dents in the surface which cause surfaces to cover each other) and a triangle mesh, the simple solution is to calculate the center of the polyhedron and then connect the three corners of every face with the new center.
If you don't have a triangle mesh, then you must triangulate, first. Delaunay triangulation might help.
If there are holes or caves, this can be come arbitrarily complex.
I'm not sure the OP wanted a 'mesh' (Steiner points added) or a tetrahedralization (partition into tetrahedra, no Steiner points added). for a convex polyhedron, the addition of Steiner points (e.g. the 'center' point) is not necessary.
Stack overflow will not allow me to comment on gnovice's post (WTF, SO?), but the proof of the statement "the surfaces of a convex polyhedron are constraints in a Delaunay Tesselation" is rather simple: by definition, a simplex or subsimplex is a member in the Delaunay Tesselation if and only if there is a n-sphere circumscribing the simplex that strictly contains no point in the point set. for a surface triangle, construct the smallest circumscribing sphere, and 'puff' it outwards, away from the polyhedron, towards 'infinity'; eventually it will contain no other point. (in fact, the limit of the circumscribing sphere is a half-space; thus the convex hull is always a subset of the Delaunay Tesselation.)
for more on DT, see Okabe, et. al, 'Spatial Tesselations', or any of the papers by Shewchuk
(my thesis was on this stuff, but I remember less of it than I should...)
I would suggest trying the built-in function DELAUNAY3. The example given in the documentation link resembles Aaron's answer in that it uses the vertices plus the center point of the polyhedron to create a 3-D Delaunay tessellation, but shabbychef points out that you can still create a tessellation without including the extra point. You can then use TETRAMESH to visualize the resulting tetrahedral elements.
Your code might look something like this (assuming v is an N-by-3 matrix of vertex coordinate values):
v = [v; mean(v)]; %# Add an additional center point, if desired (this code
%# adds the mean of the vertices)
Tes = delaunay3(v(:,1),v(:,2),v(:,3)); %# Create the triangulation
tetramesh(Tes,v); %# Plot the tetrahedrons
Since you said in a comment that your polyhedron is convex, you shouldn't have to worry about specifying the surfaces as constraints in order to do the triangulation (shabbychef appears to give a more rigorous and terse proof of this than my comments below do).
NOTE: According to the documentation, DELAUNAY3 will be removed in a future release and DelaunayTri will effectively take its place (although currently it appears that defining constrained edges is still limited to only 2-D triangulations). For the sake of completeness, here is how you would use DelaunayTri and visualize the convex hull (i.e. polyhedral surface) as well:
DT = DelaunayTri(v); %# Using the same variable v as above
tetramesh(DT); %# Plot the tetrahedrons
figure; %# Make new figure window
ch = convexHull(DT); %# Get the convex hull
trisurf(ch,v(:,1),v(:,2),v(:,3),'FaceColor','cyan'); %# Plot the convex hull