how to Differentiate 3D points

Hi guys,
I have some 3D points of a 3D surface in x, y and z format. You can get the points here: http://textuploader.com/?p=6&id=EjEtc
Assuming 'M' is my 3D surface (i.e. made up of the 3D points), I would like to get the derivative of M with respect to the 'x' direction and the 'y' direction. That is, I want to differentiate M wrt to the x and y coordinates (i.e. gradient in x and y directions).
My data is not a uniform grid. Any ideas how to do this in Matlab ?

 Respuesta aceptada

dpb
dpb el 11 de Oct. de 2013

0 votos

See
doc gradient
maybe? Look at alternate syntax with spacing inputs not just minimum case.

7 comentarios

Kurt
Kurt el 11 de Oct. de 2013
dpb,
To get a better undetanding of my problem. Here is my code which does the desired differentiation, but on a uniform XYZ grid. I have no idea how to adapt this for the non-grid 3D data I posted in the 1st post.
function Run_Differentiate_3D()
clc;clear all;close all
% Generate data
[X2,Y2] = meshgrid(-2:.2:2, -2:.2:2);
% surf(X,Y,Z)
X2= X2(:);
Y2 = Y2(:);
Z2 =zeros(size(X2),1) ;
% data here is a Grid
Surface_3D = [X2 Y2 Z2];
% Cx is derivative wrt to x coordinates, likewise Cy for y coords.
[Cx,Cy]=SurfaceGrad3D(Surface_3D);
end
function [Cu,Cv]=SurfaceGrad3D(x)
r=size(x,1);
c=size(x,2);
Cu=spalloc(r*c,r*c,r*c*2);
Cv=spalloc(r*c,r*c,r*c*2);
for j=1:c-1
for i=1:r
Cu((c-1)*r+i,(c-1)*r+i)=1;
Cu((c-1)*r+i,(c-2)*r+i)=-1;
Cu((j-1)*r+i,(j-1)*r+i)=-1;
%
Cu((j-1)*r+i,(j)*r+i)=1;
%Cu((c-1)*r+i,(c-2)*r+i)=-1;
% Cu((j-1)*r+i,(j-2)*r+i)=-1;
%Cu((j-1)*r+i,(j)*r+i)=1;
end;
end;
for i=1:r-1
for j=1:c
Cv((j-1)*r+r,(j-1)*r+r)=1;
Cv((j-1)*r+r,(j-1)*r+r-1)=-1;
Cv((j-1)*r+i,(j-1)*r+i)=-1;
Cv((j-1)*r+i,(j-1)*r+i+1)=1;
%Cv((j-1)*r+i,(j-1)*r+i-1)=-1;
% Cv((j-1)*r+i,(j-1)*r+i+1)=1;
end;
end;
end
dpb
dpb el 11 de Oct. de 2013
Perhaps interp2 the data to a uniform grid and do the gradient there and then back to the sampled points?
What's the end result to be for?
Kurt
Kurt el 12 de Oct. de 2013
dpb,
Please see the following link for what I am trying to do and my end result:
Essentially, I want to compute the Equation 1, Es(M). Where M is my 3D surface points. According to the code I posted above, I get dM/du and dM/dv, so the 3 differential terms of Equation 1 can easily be computed. But again, it assumes my 3D data is grid.
Assuming I given non-grid XYZ data, I want to compute Es(M). I dont really want to manipulate my original data by adding extra points through interpolation. Please let me know of any ideas.
thank you
dpb
dpb el 12 de Oct. de 2013
If you can't generate a regular grid it's pretty difficult to envision how you'd do just a numerical difference. I guess I'd be for looking to fit a spline and do the gradients analytically, then.
Kurt
Kurt el 12 de Oct. de 2013
dpb,
can you tell me a bit more on fitting the spline an analytical grad? thanks
Kurt
Kurt el 12 de Oct. de 2013
dpb
dpb el 12 de Oct. de 2013
Editada: dpb el 13 de Oct. de 2013
Dunno--give it a go and see...you'll have to see what its assumptions are on data ordering, etc., ...
On the spline, if the data are a (relatively) smooth surface, the idea is that a piecewise cubic poly should be a good representation of same. Since it's a poly of low order, one can analytically compute the derivatives from the coefficients.
For globally-smooth data, response surfaces are often used as well for the same purpose or to reduce high-complexity models to simply-evaluated RSMs for such purposes as MC simulation where the actual evaluation would be excessively costly.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 11 de Oct. de 2013

Comentada:

dpb
el 12 de Oct. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by