Find closest point between two sets of points
3 views (last 30 days)
Show older comments
Hello I have a matrix A=[x,y,c] in which there are around 10^5 points stored. There are 10^5 rows and 3 columns. Columns x,y define the coordinates of a point and column c has a value stored.
The points stored in the matrix define a numerical mesh and the value C is the value in that mesh point. The matrix A is not ordered, but the grid consists of concentric discrete circles of different radius. Transforming Matrix A into polar coordinates makes a lot of sense and i have done so using the cart2pol function. Resulting in A2=[theta,radius,c]. Now i have a second solution matrix B2=[theta,radius,c] from a different solution time and i want to do an average between both solution steps A2 and B2. The mesh [x,y] is the same in both cases, My problem is that the solution in Matrix B has been rotated by Phi degrees. So first i want to rotate B by Phi radians, and then i want to match the new positions of the mesh points from B to the positions of the mesh points in A. and then do the average between both solutions
for example i have
A=[theta,radius,c]=[0,0,1; 0,1,2; 0,2,3] and B = [theta,radius,c]=[0,0,7; 0,1,8; 0,2,9; 1,0,1.1; 1,1,2.1; 1,2,3.1]
Now i rotate B by -1 degree back so that its mesh overlaps with the mesh from Solution A
A=[theta,radius,c]=[0,0,1; 0,1,2; 0,2,3] and B = [theta,radius,c]=[-1,0,7; -1,1,8; -1,2,9; 0,0,1.1; 0,1,2.1; 0,2,3.1]
Now elements 4,5 and 6 of B overlap with elements 1, 2 and 3 of A, but of course my code doesnt know that
I want to find which elements(indices) of B correspond to which elements(indices) of A in order to do a simple average between A and B
and get my correct result
A_averaged=[0,0,1.05; 0,1,2.05; 0,2,3.05]
I think the first step would be to order A2. How can i do this? I am thinking about something like A2= [theta1,radius1,c;theta1,radius2,c;theta1,radiusn,c;theta2,radius1,c;theta2,radius2,c;.....]
Rotating B is easy, i would just use a rotation matrix
R = [cos(angle) -sin(angle); sin(angle) cos(angle)];
to rotate the x,y values stored in B. But this operations results in A(1) no longer having the same x,y coordinates as B(1) so i would need to sort B again? or find which point in B is nearest to A(1)? Any help is appreciated, i dont know how to sort a matrix nor what solution path is more effcient and surely there are paths i havent thought about.
3 Comments
Matt J
on 4 Jan 2022
Using scattered interpolation has worked pretty good i think
If you are content with it, please Accept-click the answer.
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!