creating 3D mesh for some points in space

조회 수: 182 (최근 30일)
lala
lala 2013년 2월 10일
답변: Shivam Anand 2022년 5월 11일
So I have these points, A, B, C, ... in 3D. Their coordinates are denoted by x, y, z. For example point A has these coordinates: if x=2.5 and y=12, then z is 3, and B is x=4, y=3, and z=15; and so on.
So i created three arrays to show my points:
x=[2.5 4 6 18 9]; y=[12 3 7.5 1 10]; z=[3 15 16 8 11.5];
and i want to create a 3D mesh from my points (A, B, ...). There are total of 9 points.
I am able to create plot3 and/or scatter3 but not mesh :(
Ive spent already a full week on this and read many tutorials and such but i just get more confused and dont get it. Please help! Thanks!
lala-
  댓글 수: 1
Kaixiang Wang
Kaixiang Wang 2017년 1월 30일
A mesh for only nine points? And z is not a function of x and y? What sort of visual result are you expecting?

댓글을 달려면 로그인하십시오.

답변 (9개)

Patrick Kalita
Patrick Kalita 2013년 2월 13일
trimesh is probably what you want to use. You can also use delaunay to generate the triangulation matrix that trimesh requires.
x=[2.5 4 6 18 9];
y=[12 3 7.5 1 10];
z=[3 15 16 8 11.5];
tri = delaunay(x, y);
trimesh(tri, x, y, z);
  댓글 수: 1
lala
lala 2013년 2월 18일
Thanks. This is good but i think a smoother sruface like like surface mesh is what im looking for. Something to show at x and y coordinates, what is the z (distance.) I have about 9 z distances and basically want to find a good visual way. But thanks again.
L-

댓글을 달려면 로그인하십시오.


Parker Hinton
Parker Hinton 2017년 5월 26일
Yes all, there is a solution, it has been stated. "Use griddata() or TriScatteredInterp to interpolate a grid of data from your points; then you can create a mesh from that."

Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 10일
편집: Azzi Abdelmalek 2013년 2월 10일
You can't use mesh with your data. You will need more data. for example
x=[2.5 4 6 18 9];
y=[12 3 7.5 1 10];
[X,Y]=meshgrid(x,y)
% and for example
Z=X+Y
mesh(X,Y,Z)
% To understand, to create a mush plot with x=[1 2], and y=[ 10 20], you need
x=1,y=10
x=1,y=20,
x=2,y=10,
x=2,y=20
%to obtain these combinations we use
x=[1 2],
y=[ 10 20]
[X,Y]=meshgrid(x,y)
% find the corresponding z to each point
Z=cos(X+Y) % for example
mesh(X,Y,Z)
  댓글 수: 1
lala
lala 2013년 2월 18일
Thanks for explanation. But since my Z is not a function of X and Y, i guess mesh and meshgrid could not be useful.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2013년 2월 11일
Use griddata() or TriScatteredInterp to interpolate a grid of data from your points; then you can create a mesh from that.
Or you may wish to create a trimesh() once you have done a triangulation.

Benoit Botton
Benoit Botton 2014년 12월 4일
Lala,
did you ever find a solution? I have the same issue

Bhuvan Varugu
Bhuvan Varugu 2015년 4월 14일
I have the same issue. Please share some knowledge on this if you can?

fauer781
fauer781 2017년 1월 7일
Hi, I am in the same situation. Is there a solution?

Jaco Verster
Jaco Verster 2017년 7월 6일
I had a similar problem - found a great solution here: https://www.mathworks.com/matlabcentral/fileexchange/8998-surface-fitting-using-gridfit

Shivam Anand
Shivam Anand 2022년 5월 11일
x=[32 20 67 1 98 34 57 65 24 82 47 55 8 51 13 14 18 30 37 39 10 33 21 26 38 81 83 60 95 22 17 5 72 46 99 52 12 25 96 29 70 85 43 69 19 78 97 31 89 53 2 91 48 71 61 15 36 84 94 50 11 80 6 7 49 74 9 88 40 79 27 68 73 64 63 59 86 23 35 58 45 28 100 42 93 87 16 90 41 66 54 92 77 4 62 76 75 56 3 44];
y=[96 75 24 9 83 49 27 77 3 23 17 31 40 13 7 52 51 21 98 47 64 79 78 91 44 16 15 100 84 99 63 68 70 30 54 76 97 73 33 5 88 8 71 66 62 25 60 42 72 45 18 11 28 59 89 65 10 55 69 81 12 26 20 95 87 41 74 50 93 22 43 90 14 34 82 35 56 38 80 32 1 57 6 36 37 61 29 58 2 48 4 46 67 53 92 86 94 19 39 85];
z=[55 31 11 45 83 36 86 49 15 57 42 46 8 94 88 47 54 81 98 41 32 35 56 85 9 89 37 60 23 62 67 100 78 76 73 80 10 20 68 34 77 93 1 63 53 12 22 99 91 40 84 24 33 3 43 19 92 97 6 82 64 25 26 79 95 4 44 58 5 21 70 29 65 87 96 90 51 14 18 2 72 28 71 39 52 7 27 59 50 61 48 30 66 69 17 13 74 16 75 38];
xlin = linspace(min(x), max(x), 100);
ylin = linspace(min(y), max(y), 100);
[X,Y] = meshgrid(xlin, ylin);
% Z = griddata(x,y,z,X,Y,'natural');
% Z = griddata(x,y,z,X,Y,'cubic');
Z = griddata(x,y,z,X,Y,'v4');
mesh(X,Y,Z)
axis tight; hold on
plot3(x,y,z,'.','MarkerSize',15)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by