Every point on 2D surface is being transformed by unknown function. How to interpolate coordinates of any point on 2D surface knowing few of them.

2 visualizzazioni (ultimi 30 giorni)
Hello,
there is unknown nonlinear function transformating points of the 2D surface. We have set of known points in the format:
[X,Y,X',Y'] %X coordinate before transfomation, Y coordinate before transformation, X coordinate after transfomation, Y coordinate after transformation
So we know coordinates of point before and after transfomation. What we need is a method to calculate coordinates after transformation for any X and Y. I tried two methods already. First one is using Lagrange polynomial interpolation using complex numbers in a way that
From there there was 10 random known points chosen to form 10-th order polynomial. Process was repeated 50 times and average interpolating polynomial was received. Unfortunately this method was giving very inacurrate results. I am posting this section of code.
A = importdata('basegridX.txt'); %121base grid X values
B = importdata('basegridY.txt'); %121base grid Y values
C = importdata('transgridX.txt');%121 shifted grid X values
D = importdata('transgridY.txt');%121 shifted grid Y values
E=complex(A,B);
F=complex(C,D);
syms z
M=0;
for i=1:50
msize = numel(E);
rng(i)
G=E(randperm(msize, 10));
rng(i)
H=F(randperm(msize, 10)); %choose semi random element 50 times
z1=G(1,1);
z2=G(2,1);
z3=G(3,1);
z4=G(4,1);
z5=G(5,1);
z6=G(6,1);
z7=G(7,1);
z8=G(8,1);
z9=G(9,1);
z10=G(10,1);
f1=H(1,1);
f2=H(2,1);
f3=H(3,1);
f4=H(4,1);
f5=H(5,1);
f6=H(6,1);
f7=H(7,1);
f8=H(8,1);
f9=H(9,1);
f10=H(10,1);
L1=((z-z2)*(z-z3)*(z-z4)*(z-z5)*(z-z6)*(z-z7)*(z-z8)*(z-z9)*(z-z10))/((z1-z2)*(z1-z3)*(z1-z4)*(z1-z5)*(z1-z6)*(z1-z7)*(z1-z8)*(z1-z9)*(z1-z10))*f1;
L2=((z-z1)*(z-z3)*(z-z4)*(z-z5)*(z-z6)*(z-z7)*(z-z8)*(z-z9)*(z-z10))/((z2-z1)*(z2-z3)*(z2-z4)*(z2-z5)*(z2-z6)*(z2-z7)*(z2-z8)*(z2-z9)*(z2-z10))*f2;
L3=((z-z1)*(z-z2)*(z-z4)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z-z8)*(z-z9))/((z10-z1)*(z10-z2)*(z10-z3)*(z10-z4)*(z10-z5)*(z10-z6)*(z10-z7)*(z10-z8)*(z10-z9))*f10;
L=L1+L2+L3+L4+L5+L6+L7+L8+L9+L10;
M=M+L;
i=i+1;
end
M=M/50; %average polynomials sum
Second idea was to divide surface to smallest possible triangles and treat every transformation as linear transformation and use corresponding linear function to transform points placed inside this elementary triangle. This method yielded better results yet still not precise enough. This is section of code calculating linear functions for elementary triangle.
if mod(i,2)==1
f(i,1)=0.1*(x2-x1)*w+0.1*(x3-x1)*z+x1-0.1*(x2-x1)*w1-0.1*(x3-x1)*z1;
f(i,2)=0.1*(y2-y1)*w+0.1*(y3-y1)*z+y1-0.1*(y2-y1)*w1-0.1*(y3-y1)*z1;
else
f(i,1)=-0.1*(xa2-xa1)*w-0.1*(xa3-xa1)*z+xa1+0.1*(xa2-xa1)*wa1+0.1*(xa3-xa1)*za1;
f(i,2)=-0.1*(ya2-ya1)*w-0.1*(ya3-ya1)*z+ya1+0.1*(ya2-ya1)*wa1+0.1*(ya3-ya1)*za1;
%if checks triangle type, there are two types of triangles with slightly different equation
%x1,x2,x3,y1,y2,y3 are coordinates of triangle vertexes after transfomation - so X' Y' from lagrange example
%w1,z1 are coordinates of triangle right angle vertex before transformation - so X, Y from lagrange example
%w,z are unknowns - coordinates of point we are looking for
%xa1,ya1,wa1 are corresponding coordinates in triangles of second type
%0.1 are hypotenuses length in triangles before transfomation so basically w2-w1, w3-w1 etc
I would be very thankfull if someone sees holes in my reasoning or can propose more accurate methods of interpolation that would work with that type of data.
  2 Commenti
Jan Jan
Jan Jan il 15 Giu 2019
grids.png
Red points are grid crossections before transformation, green are corresponding points after transformation, coordinates of both red and green points are known. We are searching for coordinates after transformation for any points (yellow ones).
Maybe may wording was confusing but basically 'that kind of data' refers to pairs of 2D coordinates.

Accedi per commentare.

Risposte (1)

Matt J
Matt J il 15 Giu 2019
If you have a model of the transformation the best approach would be to do a surface fit.
  2 Commenti
Jan Jan
Jan Jan il 15 Giu 2019
Modificato: Jan Jan il 15 Giu 2019
I do not really understand what you mean by 'model of transformation'.
Anyway I just tried this approach using cftool I set X and Y values as coordinates of red dots from picture above, but now it doesn't allow me to add green dots in complex form as Z values. ("Using only the real component of complex data.")
I worked around the issue and tried to do it separately for X and Y values, I tried every fit method and all of them are giving too inaccurate methods. Linear fit gave exactly the same results as one of my previous version, best seemed to be spline interpolant but still errors above 10%.
Matt J
Matt J il 16 Giu 2019
I do not really understand what you mean by 'model of transformation'.
I mean you haven't said what the mathematical form of the final surface is. If you know the mathematical form, you should try to fit the unknown parameters in that model using cftool or similar.
but still errors above 10%.
How are you making that assessment? You would have to know the correct interpolated values in advance to be able to say how big the errors are.

Accedi per commentare.

Categorie

Scopri di più su Interpolation in Help Center e File Exchange

Prodotti


Release

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by