Effacer les filtres
Effacer les filtres

How can I create a 2D array of 3D points

9 vues (au cours des 30 derniers jours)
kz pg
kz pg le 26 Juil 2020
The purpose is to render 2D image of gestner waves
So I think these equations add Offset not only in vertical direction, but also squeeze points horizontally to make crests choppy
I know that meshgrid can create a group of evenly distributed grid points and we can assign a vertical values to each of the (x,y) discrete locations.
But this is far from drawing gestner waves.
I need to create a 2D array of points. Each element of the array is a point (or a point's 3D-location), and then I can offset each of these points and then visualize the surface.
If I write this code: points will be a 16384*3 array. Just storing 3d points in a row vector for 16384 times. I cannot access them via x,y,z index. How can I do that?
vector_of_x = 1:128;
vector_of_y = 1:128;
[X, Y] = meshgrid(vector_of_x, vector_of_y);
Z=zeros(128,128);
surf(X,Y);
points = [X(:), Y(:), Z(:)];
ptCloud = pointCloud(points);%%case

Réponses (1)

Jeremy Perez
Jeremy Perez le 28 Août 2020
Hi,
Read this:
What you want is creating a pxyt array with 3 pages.
Each page contains the values at each step t.
The code you know:
n = 128;
vector_of_x = 1:n;
vector_of_y = 1:n;
[X, Y] = meshgrid(vector_of_x, vector_of_y);
Z=zeros(n,n);
Your surface at t0:
pxyt = zeros(n,n);
pxyt(:, :, 1) = X(:, :);
pxyt(:, :, 2) = Y(:, :);
pxyt(:, :, 3) = Z(:, :);
Your surface at t:
% pxyt = myfunctionP(pxyt)
pxyt(:, :, 3) = rand(n,n);
X = pxyt(:, :, 1);
Y = pxyt(:, :, 2);
Z = pxyt(:, :, 3);
%figure()
%surf(X,Y,Z);
Your point at t:
p = [0;0;0];
kx = 1; % index x
ky = 1; % index y
p(:) = pxyt(kx, ky, :);
Hope it helps,

Catégories

En savoir plus sur Lighting, Transparency, and Shading dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by