I am trying to use the function inpolyhedron shown here: https://www.mathworks.com/matlabcentral/fileexchange/37856-inpolyhedron-are-points-inside-a-triangulated-volume-
However, I am having trouble creating the polyhedron the way the function wants it defined (a structure with fields 'vertices' and 'faces'). The raw data I have is a matrix of points x y z that are inside the polyhedron. So far, I have been using boundary() and trisurf() to plot the polyhedron.
Dependant on what kind of polyhedron you want, you can use alphashape, delaunay triangulation or convhull. So for example:
shp=alphaShape(x,y,z);
h=plot(shp);
You can access faces and vertices then like:
h.Vertices
h.Faces
It works the same way for trisurf:
tri=delaunay(x,y,z)
t=trisurf(tri,x,y,z)
To see which information is stored, you can use get(t).
For faces and vertices it is the same thing as before:
t.Vertices
t.Faces
Related
I have an adjacency matrix without coordinates that I would like to represent nicely using gplot.
I am able to get it to show as a biograph object with a good spacing between all the nodes, so I was wondering if there was a way to extract the coordinates from the biograph object to then use with gplot?
EDIT:
I got some negative feedback (with no comments) about this question for some reason, so I will try to elaborate further.
The data I am using is for a graph represented as a weighted adjacency matrix. I would like to be able to display it using the gplot function in MATLAB, however gplot requires cartesian coordinates for each vertex, information that I haven't been given.
I don't really want to have to go to the trouble of using a force directed graph algorithm to calculate the coordinates in order to display the graph, because that would be overkill, I just want a way to display the graph so that the vertices aren't completely randomly distributed.
An easy way to do this is to use the biograph function like so:
G = <adjacency matrix>
ids = <vertex labels>
bg = biograph(G,ids,'ShowArrows','off','ShowWeights','on',...
'EdgeType','straight','LayoutType','equilibrium');
h=view(bg);
which displays a reasonable looking representation of the graph, however I would like it if I didn't have to use the biograph environment and I could use the gplot one instead.
The MATLAB documentation says that to find the x-y coordinates of node 3 (for example) I can use:
bg.nodes(3).Position
to query the position of the node; however when do that it returns [ ]
strangely though, if I double click on a node in the graphical representation I can access this information in the pop up window, so I am sure it exists somewhere..
Does anyone have any idea of how I can extract this information from a biograph object? I just need a n*2 matrix with the x and y coordinates for each vertex.
Sorry if my original question was too vague, I hope this is better
For anyone who is looking for the answer to this question, the original biograph object does not contain the position information, this is only calculated once the object is viewed - so in order to find the information you need to reference the figure handle, not the original object. This can be done using:
h.nodes(3).Position
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?
Can anyone tell me how to generate a 3D surface model like CAD in Matlab ?
1.Input: Input is a collection of points with (x,y,z) where surface is present for an object(I'm using this for a 3D scanner where my inputs are (x,y,z) of surface)
2.Points should be displayed as a surface using some smooth interpolation.
3.More like surface generation from data points.
Thanks you.
In order to plot surfaces, you can use patch function. However, you need along with the points the faces information. In patch a surface consists of polygons that is specified using 3 point, which is the face information.
1
Since it seems like you will be inputting discrete points located on the surface of the object, you will first want to create a Nonconvex Polygon based on the data using Matlab's boundary function.
https://www.mathworks.com/help/matlab/ref/boundary.html
You can then use the trimesh function to create the figure
This question shows the input data and what was produced using this method: How do I create a 3D polygon/mesh over data points?
I have 3 vectors of data: latitudes, longitudes, and elevations of specific locations. Each vector (lat, lon, elev) is a column vector with about 63 elements where element 1 of each represents a given location. What I want to do is create a topological map, or heatmap (whichever you want to call it) to map out these locations. I can plot them (like lon vs lat) no problem, but I'm not sure where to look to create a topological map. I've looked at using the surf function, but the elevations need to be a 2-D matrix for that and that would result in a lot of missing data that I just don't have.
Can someone give me some guidance here?
You can use TriScatteredInterp to interpolate your data onto a regular grid, which you then can use to plot the surface using surf, or a heatmap using contourf.
The example in the linked documentation of TriScatteredInterp will do exactly what you need, all you need to do is replace x, y, and z by your data and define the appropriate limits for meshgrid.
Is there any subroutine, in MATLAB, that takes in a list of points, and return me a good mesh that I can use to show to my colleagues, such as this?
Actually, all I need is just a simple 2D mesh generator that takes in a series of X, Y coordinates (that defines the boundary of the area), and give me back a list of elements that can mesh that area well. I can do the rest by using MATLAB command to interpolate the Z value.
Edit : I am not interested to use MATLAB to produce the above looking plot. I am interested in using a MATLAB library to obtain a list of elements so that when I plot those element myself (not in MATLAB itself; but in my own C# program), I can obtain this meshed surface.
PS: I know there is this DistMesh, but I am looking for something simpler - something built-in direct in MATLAB perhaps. And no, meshgrid is not mesh generation.
It sounds like you want to create a finite element mesh, starting with a set of points defining a boundary of a region and then generating a triangular mesh that creates more points within that region. I don't think there's a "simple" solution for this problem.
The closest "built-in" solution would probably be the Partial Differential Equation Toolbox, specifically some of the Geometry Algorithms like INITMESH and REFINEMESH.
The link you gave to DistMesh appears to be another good solution. There are also a few submissions on the MathWorks File Exchange that you could take a look at:
MESH2D by Darren Engwirda
Finite Element Toolbox 2.1 by Rasmus Anthin
That picture looks exactly like the one from the griddata documentation. The example in there looks like what you want.
SFTOOL will easily make the picture that you show.
A thin-plate spline, e.g., TPAPS, should also do the job.
I think the user-created 'gridfit' is the best I've come across for a single surface, much better/prettier than griddata.
Mesh generation as in Delaunay Triangulation + Steiner Points? There is a builtin Delaunay function in MATLAB.
If your surface is the z=f(x,y) form you can use:
http://www.advancedmcode.org/how-to-plot-a-coloured-surface-from-3d-scatter.html
If your surface is concave look for surface reconstruction on the same website.