I have a 3D matrix (250x3x7) where the 1st dimension are the data points, 2nd dimension the x,y,z coordinates, and 3rd dimension the slice location. This 3D matrix are the contours at each slice location and these contours are not parallel to each other. I wish to interpolate these contour onto some planes in 3D space. These planes are parallel to each other. I have the x,y,z coordinates of each pixel of these plane. The example in images below will explain it better. I want to interpolates those contours on those grey colour planes.
Image1: contours and plane
Image: The few slices of contours and a few number of plane
I tried using interp3 to interpolate the contours with meshgrid, but I'm not sure how to interpolate it to a specific location (plane) in 3D space. Hope someone can help me with this. Do let me know if my question is not clear. Thanks!
Related
I have a workspace containing a polyhedral shape so I sliced the workspace into different 3D circles. For each circle, it is either there occurs an intersection with the polyhedral or not. Is it possible to determine if the circle intersects with the polyhedron in MATLAB and if yes, how can I determine the polygon formed by the intersection of a 3d circle with a polyhedral shape?
NB: 3D circle is a circular shaped object in the 3D space. For ease of understanding, I have attached a MATLAB plot:
There are 3 circles and four polyhedral shapes in the plot.
Any help will be appreciated
Basically, I have a many irregular circle on the ground in the form of x,y,z coordinates (of 200*3 matrix). but I want to fix a best circle in to the data of x,y,z coordinates (of 200*3 matrix).
Any help will be greatly appreciated.
I would try using the RANSAC algorithm which finds the parameters of your model (in your case a circle) given noisy data. The algorithm is quite easy to understand and robust against outliers.
The wikipedia article has a Matlab example for fitting a line but it shouldn't be too hard to adapt it to fit a circle.
These slides give a good introduction to the RANSAC algorithm (starting from page 42). They even show examples for fitting a circle.
Though this answer is late, I hope this helps others
To fit a circle to 3d points
Find the centroid of the 3d points (nx3 matrix)
Subtract the centroid from the 3D points.
Using RANSAC, fit a plane to the 3D points. You can refer here for the function to fit plane using RANSAC
Apply SVD to the 3d points (nx3 matrix) and get the v matrix
Generate the axes along the RANSAC plane using the axes from SVD. For example, if the plane norm is along the z-direction, then cross product between the 1st column of v matrix and the plane norm will generate the vector along the y-direction, then the cross product between the generated y-vector and plane norm will generate a vector along the x-direction. Using the generated vectors, form a Rotation matrix [x_vector y_vector z_vector]
Multiply the Rotation matrix with the centroid subtracted 3d points so that the points will be parallel to the XY plane.
Project the points to XY plane by simply removing the Z-axes from the 3d points
fit a circle using Least squares circle fit
Rotate the center of the circle using the inverse of the rotation matrix obtained from step 5
Translate back the center to the original location using the centroid
The circle in 3D will have the center, the radius will be the same as the 2D circle we obtained from step 8, the circle plane will be the RANSAC plane we obtained from step 3
I am wondering if there is a way to build a random 3D surface from only one (top-down) 2D image of this surface. The fact is that the 3D surface needs the z-coordinates (the heights and the depths) and the 2D (top-down) image gives only the x and y coordinates.
I believe that the main problem is that we can't get the real ranges of the dimensions (x,y,z) of the surface from one 2D (top-down) image but we can get some kind of normalized scaling which is not the real one (it's just similar).
For example:
If we have an image with a surface (2D) and we want 3D of this surface (x,y,z) we can have easily the x and the y coordinates from the image. We can't have the real range of the amplitude (z coordinate) in each point of the surface but only the gray-tones scaling. Is there any ideas on how could we take the real sizes of the amplitudes of a surface from one 2D (top-down) image?
Left is a sample of 2D top-down image and Right is a surface which created by the 2D
http://www.sendspace.com/file/9wzx0u
p.s.
I can't post an image because of my reputation, so I uploaded one on sedspace.com.
Read in the image:
A = imread(filename)
Plot the surface plot using the magnitude of the value read in for each x and y from the file:
surf(A)
I'm trying to compute 2d projections of a 3d mesh from different views using matlab.
The solution I m using now, is to plot the 3d mesh, rotate it, and make a screenshot.
I would like to know if there is any matlab internal functions or any other solution that allow me, given a set of vertices and triangles, to compute the projections without having to plot the 3D mesh
Thanks
You can use the view command to rotate the axes and change the viewpoint. The azimuth and elevation are given in degrees (ref. documentation for more info). Here's a small example:
ha=axes;
[x,y,z]=peaks;
surf(x,y,z);
xlabel('x');ylabel('y');zlabel('z')
%#projection on the X-Z plane
view(ha,[0,0])
%#projection on the Y-Z plane
view(ha,[90,0])
%#projection on the X-Y plane
view(ha,[0,90])
This is what it looks like:
Projections on different 2D planes
X-Z
Y-Z
X-Y
I have a large (~60,000) set of triplet data points representing x,y, and z coordinates, which are scattered throughout a Cartesian volume.
I'm looking for a way to use Matlab to visualize the non-convex shape/volume described by the maximum extent of the points.
I can of course visualize the individual points using scatter3, but given the large number of points the details of the shape are obscured by the noise of the dots.
As an analogy, imagine that you filled a hour glass with spheres of random sizes such as BBs, ping pong balls, and kix and then were given the coordinates of the center of each of each object. How would you take those coordinates and visualize the shape of the hour glass containing them?
My example uses different sized objects because the spacing between data points is non-uniform and effectively random; it uses an hourglass because the shape is non-convex.
If your surface enclosing the points can be described as a convex polyhedron (i.e. like the surface of a cube or a dodecahedron, without concave pits or jagged pointy parts), then I would start by creating a 3-D Delaunay triangulation of the points. This will fill the volume around the points with a series of tetrahedral elements with the points as their vertices, and you can then find the set of triangular faces that form the outer shell of the volume using the convexHull method of the DelaunayTri class.
Here's an example that generates 200 random points uniformly distributed within the unit cube, creates a tetrahedral mesh for these points, then finds the 3-D convex hull for the volume:
interiorPoints = rand(200,3); %# Generate 200 3-D points
DT = DelaunayTri(interiorPoints); %# Create the tetrahedral mesh
hullFacets = convexHull(DT); %# Find the facets of the convex hull
%# Plot the scattered points:
subplot(2,2,1);
scatter3(interiorPoints(:,1),interiorPoints(:,2),interiorPoints(:,3),'.');
axis equal;
title('Interior points');
%# Plot the tetrahedral mesh:
subplot(2,2,2);
tetramesh(DT);
axis equal;
title('Tetrahedral mesh');
%# Plot the 3-D convex hull:
subplot(2,2,3);
trisurf(hullFacets,DT.X(:,1),DT.X(:,2),DT.X(:,3),'FaceColor','c')
axis equal;
title('Convex hull');
You could treat your data as a sample from a three-dimensional probability density, and estimate that density on a grid, e.g. via a 3d histogram, or better a 3d kernel density estimator. Then apply a threshold and extract the surface using isosurface.
Unfortunately, hist3 included in the Statistics Toolbox is (despite its name) just a 2d histogram, and ksdensity works only with 1d data, so you would have to implement 3d versions yourself.