How to draw the normals at many points in a surface? - matlab

X,Y and Z are the matrices contain the coordinates of points in the surface.
Xnormal,Ynormal and Znormal are the matrices contain the normals at these points.
How can I draw all these normals at their position?
Thanks!

Look at this Mathworks documentation for the quiver3 command.

Related

How to extract surface vertices coordinate in fimplicit3 function?

Is it possible to extract the coordinate of surface vertices in the fimplicit3 function in Matlab?
Couldn't found how to do with fimplicit3, but it easier to extract vertices and faces from a surface using isosurface function.
One can follow this tutorial: Implicit curves and surfaces sith Isosurface

Interpolates 3D contours onto parallel 3D planes

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!

Patching Delaunay Triangles

I have a number of 2D points x and y, and I need to color delaunay triangles, which have edges that exceed a certain limit. However I can't figure out how to write it down so that it would compare each edge of each triangle and add it to a vector of triangles that need to be patched. The end result is supposed to be a 3D surface, where color depends on the Z coordinate, except for the triangles that have been patched white. Any help would be great!
You can try a contour plot. With your triangles and z values find the average of each triangle.

I need to fit a best circle to the 3D data in matlab

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

How to draw a sphere in matlab and patch it in a 3D plot?

I have a 3D plot and I want to put a sphere in a designed position. How can I create a sphere? I expected to use patch? Can anyone help me to do this please?
You can follow this:
Consider the center is at [c1,c2,c3]. The number of faces as r.
[x,y,z] = sphere(r);
surf(x+c1, y+c2, z+c3)
These two lines of code are enough to plot a sphere using the surf command.
For instance, if C=[2,2,2] and r=30 the result is as follows:
This is a sphere of radius 1 centered at [2,2,2]. To have a sphere with an arbitrary radius R, you should multiply the [x,y,z] values by R before adding the center.