High Performance Interpolation of 3D grid data
Info
This question is closed. Reopen it to edit or answer.
Show older comments
Hello everybody,
currently working on a project in which magnetic field (grid) data is rotated and shifted in 3 dimensions and afterwards evaluated at specific points in the COS.
So, what I have, is x-, y-, z- Coordinates with the corresponding values for Bx, By, Bz (magnetic induction vector components) data of a round shaped magnet.
First, I arranged my data in a meshgrid and then I performed some matrix operations ("transformations") to rotate and shift the magnetic field data (which works well and really fast).
But nooooow, I need to evaluate the Bx, By, Bz component values at specific points in my global COS. As example: I grid my data with a meshsize of 0.5 mm. The problem is that after rotation about for example 30 ° about z-axis there is no grid point at [0.5 0.5 0.5] anymore and I can't evaluate the B field data there.
I can bring my transformed field data back to a grid using griddata and interpolate the B values on the 0.5 mm meshsize to evaluate at this point... But this is inconceivably slow......
Does anyone have a better way to interpolate my transformed magnetic field data back to the original meshgrid OR to do the mentioned evaluation on any other way?
Many thanks in advance! I spent my whole last 2 days trying things like scatteredInterpolant (which is also not really faster) and griddedInterpolant, which seems to be fast, but can't handle my rotated field data....
11 Comments
darova
on 15 Apr 2020
If i understood you correctly you want to extrapolate your data
Is this correct?

Oliver Vogt
on 15 Apr 2020
darova
on 15 Apr 2020
Is it possible to make a simple drawing or sketch? I still don't get what is going on
Oliver Vogt
on 16 Apr 2020
Oliver Vogt
on 16 Apr 2020
darova
on 16 Apr 2020
I saw your codes. They are long, i don't want to spend a whole day to trying understand it
1 question: do you do you calculations on one matrix a few times? Or one matrix (pointcloud) - one set of calculations?
My point is: can you griddata once and then use interp2 ?
Oliver Vogt
on 16 Apr 2020
Oliver Vogt
on 16 Apr 2020
Oliver Vogt
on 16 Apr 2020
darova
on 16 Apr 2020
What if transformate point location?
You are transformating data (mesh) all time. But what if transformate positions of points. You can then use your original mesh

Oliver Vogt
on 16 Apr 2020
Answers (2)
darova
on 16 Apr 2020
Here is an example. It's just a surface in 3D. I rotated X and Y and found new Z
See script and try to calculate value of point with your method (griddata)

clc,clear
n = 20;
[X,Y] = meshgrid(linspace(0,5,n));
Z = 10-X.^2-10*Y.^2; % some random data
a = 30; % angle of rotation
R = @(a)[cosd(a) sind(a);-sind(a) cosd(a)]; % rotation matrix
P = [4 1]; % original point
P1 = R(-a)*P'; % rotate point (backward)
PP = [P(:) P1(:)]';
PP(:,3) = interp2(X,Y,Z,PP(:,1),PP(:,2)); % get Z data for points
V = R(a)*[X(:) Y(:)]'; % rotate data (forward)
X1 = reshape(V(1,:),[n n]); % restore size
Y1 = reshape(V(2,:),[n n]); % resotre size
Z1 = Z; % Z is the same (only X and Y changed)
cla
plot3(PP(:,1),PP(:,2),PP(:,3),'or');
h1 = surface(X,Y,Z,'facecolor','b');
h2 = surface(X1,Y1,Z1,'facecolor','r');
set([h1 h2],'edgecolor','none')
alpha(0.3)
axis vis3d
view(2)
I don't understand why do you interpolate magnetic values here? I thought you calculating them using griddata?
BxByBz1 = [...
GridMagnetData.Bx(:), ...
GridMagnetData.By(:), ...
GridMagnetData.Bz(:), ...
ones(numel(GridMagnetData.Bx),1)];
rotBxByBz1 = BxByBz1 * R_z';
- Then I would need a really fine grid at the beginning right?
Not really, usual grid
5 Comments
Oliver Vogt
on 17 Apr 2020
darova
on 17 Apr 2020
- I actually just do the matrix operation here?
You can't apply geometrical transformation with magnetic field. You transformate your XYZ matrix and then calculate magnetic field in new position using griddata or interp2(whatever)
Oliver Vogt
on 20 Apr 2020
darova
on 20 Apr 2020
Can i close this question?
Oliver Vogt
on 20 Apr 2020
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!