필터 지우기
필터 지우기

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

조회 수: 9 (최근 30일)
kz pg
kz pg 2020년 7월 26일
답변: Jeremy Perez 2020년 8월 28일
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

답변 (1개)

Jeremy Perez
Jeremy Perez 2020년 8월 28일
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,

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by