How do i put a center of surface in [0 0] coordinates

10 views (last 30 days)
Hi,
I made a 3d surface graph from matrice. I already count a center of this surface, but how do i shift the center of the surface to (0 0) coordinates ? I want to keep z coordinate as it is. Bassicily the origin of x and y must be in the center of surface.
%% Nacteni dat
[Zmeas, dx, wl]= ReadXYZ(measurementFile ,dataFolder);
%Vypocet teziste masky
sizeX = size(Zmeas,2);
sizeY = size(Zmeas,1);
%Vypocet stredu
Zshape = ~isnan(Zmeas);
centerX = 0;
centerY = 0;
cnt = 0;
for m=1:sizeY
for n=1:sizeX
if (Zshape(m,n))
centerX = centerX + n;
centerY = centerY + m;
cnt = cnt + 1;
end
end
end
centerX = int32(centerX/cnt);
centerY = int32(centerY/cnt);
%Odecteni offsetu a naklonu [piston tip tilt power]
[Zmeas, dx, wl] = RemoveZernikes(Zmeas, Zshape, [1 1 1], centerX, centerY);
%graf
figure
sl=mesh(wl);
colormap("jet");
xlabel("x"); ylabel("y"); zlabel("z");
title("Odchylky povrchu");
zlim([-.5 .5]);
ylim([0 600]);
xlim([0 600]);
view([135 30]);
%movegui('center');
colorbar
daspect([100 100 1])
  2 Comments
Mathieu NOE
Mathieu NOE on 13 Jan 2023
Hello
simply retrieve the center coordinates to your data X,Y coordinates (where are they in your code ?)
X = X - centerX;
Y = Y - centerY;
Karel Schindler
Karel Schindler on 13 Jan 2023
I already figured it out thank you. It was:
val1=-centerX:centerX-1;
val2 = 20-centerY:centerY-1-20;
[xmesh, ymesh] = meshgrid(val1,val2);
sl=mesh(xmesh, ymesh,wl)

Sign in to comment.

Answers (1)

Sarthak
Sarthak on 7 Mar 2023
Hi,
To shift the center of the surface to (0,0), you need to subtract the coordinates of the center point from all the x and y coordinates of the surface points.
Refer to the code and documentation on meshgrid below-
x = ((1:sizeX)-centerX)*dx;
y = ((1:sizeY)-centerY)*dx;
[X,Y] = meshgrid(x,y);
Documentation:

Community Treasure Hunt

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

Start Hunting!