Matlab 矩阵的斜坐标到直角坐标的基变换

Matlab 矩阵的斜坐标到直角坐标的基变换,matlab,vectorization,coordinate-systems,coordinate-transformation,Matlab,Vectorization,Coordinate Systems,Coordinate Transformation,我将2D数据存储在[K,K]矩阵中。索引表示斜坐标系中的坐标(q_1,q_2),斜坐标系由其应变-0.5定义。最好的方法是使用meshgrid创建点网格,使用变换使网格变形,然后使用interp2在这些位置对原始图像进行采样 % Desired output range [xx,yy] = meshgrid(-3:0.01:3, -3:0.01:3); % Transform these X and Y coordinates to q1 and q2 coordinates q1 = xx;

我将2D数据存储在
[K,K]
矩阵中。索引表示斜坐标系中的坐标
(q_1,q_2)
,斜坐标系由其应变
-0.5定义。最好的方法是使用
meshgrid
创建点网格,使用变换使网格变形,然后使用
interp2
在这些位置对原始图像进行采样

% Desired output range
[xx,yy] = meshgrid(-3:0.01:3, -3:0.01:3);

% Transform these X and Y coordinates to q1 and q2 coordinates
q1 = xx;
q2 = yy + gamma*q1;

% Sample the original image using these coordinates where q1range and q2 
% range and the q1 and q2 values corresponding to each element in the image qdata
output = interp2(q1range, q2range, qdata, q1, q2);
% Oblique-to-rectangular coordinate transformation
K = 10; % number of pixels
gamma = 0.37; % some arbitrary strain position range (-0.5; 0.5)
Koffset = (1-(-1).^(K-1))/4; % =0.5 when K is even, =0.0 when K is odd

% Mock data
S0 = rand(K,K); % data collected in the oblique coordinate system

qindex = -ceil((K-1)/2) : floor((K-1)/2); % all the possible q-values, with the zero'th element in the middle. Must be in this order to comply with FFT's convention

S = zeros(K,K); % data to be transformed to the rectangular coordinate system

% let indices (i,j) run through all the positions of the oblique matrix
for i=1:K
    for j=1:K
        % obtain the q-values corresponding to the current matrix position (i,j)
        q1 = qindex(i);
        q2 = qindex(j);

        % apply the coordinate transformation to get the q-values in the rectangular system
        qx = round(q1);
        qy = round(q2-gamma*q1);

        % apply periodic boundary condition
        qy = qy - K*round((qy+Koffset)/K); % should be a unique value in the range of qindex

        % find out the indices in the rectangular system
        ii = i;
        jj = find(qindex == qy);

        % add the element
        S(ii,jj) = S(ii,jj) + S0(i,j); 
    end
end
% Desired output range
[xx,yy] = meshgrid(-3:0.01:3, -3:0.01:3);

% Transform these X and Y coordinates to q1 and q2 coordinates
q1 = xx;
q2 = yy + gamma*q1;

% Sample the original image using these coordinates where q1range and q2 
% range and the q1 and q2 values corresponding to each element in the image qdata
output = interp2(q1range, q2range, qdata, q1, q2);