Interpolating 3D points from input points corresponding to a closed surface - matlab

I have a list of scattered 3D points similar to the one below:
Using MATLAB, I want to interpolate further points from the surface that those original points correspond to, in order to obtain a more complete scatter. Note that there are no particular slices defined on this scattered data. That is, the z values of the point cloud are not discrete, so it's not possible to interpolate slice by slice.
I think that the ideal way to achieve this would be to somehow obtain the smooth closed surface which best matches the scattered data, and then sample it. But I have found no straightforward way to achieve this.

The scatterinterpolant class could be a simple option.
Use scatteredInterpolant to perform interpolation on a 2-D or 3-D
Scattered Data set. For example, you can pass a set of (x,y) points
and values, v, to scatteredInterpolant, and it returns a surface of
the form v = F(x, y). This surface always passes through the sample
values at the point locations. You can evaluate this surface at any
query point, (xq,yq), to produce an interpolated value, vq.
http://au.mathworks.com/help/matlab/math/interpolating-scattered-data.html
Scattered data consists of a set of points X and corresponding values
V, where the points have no structure or order between their relative
locations. There are various approaches to interpolating scattered
data. One widely used approach uses a Delaunay triangulation of the
points.

Related

interpolate velocity for a curved mesh

'x','y' and 'u' are 2D matrices for the x-coordinate, y-coordinate, and velocity of each node of the below mesh (figure). and I want to interpolate for (x_q,y_q) to find u_q for an arbitrary point(q).
My mesh is not rectangular and "interp2" error is: "Input grid is not a valid MESHGRID".
Any Ideal what can I do?
Thanks.
minimal reproducible example:
x=[0.0482114583977891,0.0482201588072998,0.0482288592168105;0.0513027685854806,0.0512573490659834,0.0512119412024664;0.0550957532853860,0.0550195888619688,0.0549437786953572;0.0589706773586289,0.0589051888951395,0.0588397004316502];
y=[-0.0481475644832381,-0.0450026617243515,-0.0418577589654650;-0.0454644879533678,-0.0426002662557475,-0.0397360636257961;-0.0434988768053532,-0.0408400599208391,-0.0381819554721181;-0.0414343539900984,-0.0389341351227583,-0.0364339162554183];
u=[1.52583130467469,14.3816671073665,58.5433654462735;108.677373003789,124.842139940676,145.468567077514;110.206733380171,111.157308056414,111.709609403516;135.414711548714,138.843419308648,147.988201447309];
xq=0.065;
yq=0.035;
uq = interp2(x,y,u,xq,yq,'cubic',0);
The interp2 function needs a regular grid (for instance something that was createed by meshgrid). In your case you have scattered data, in which case it you'd have to use griddata for interpolation:
uq = griddata(x,y,u,xq,yq, 'nearest');
(Note that in your MCVE your query point is way outside of the defined input points, so only 'nearest' will really work as a method.)
Per Matlab documentation for the interp2 function, the requirements for cubic spline interpolation are:
Grid must have uniform spacing in each dimension, but the spacing does not have to be the same for all dimensions
Requires at least four points in each dimension
In the case of your code, neither of these conditions is met.
You would need to make sure that the x and y points are evenly spaced, ideally using meshgrid to generate the points and you would need to make the specified points, which are currently 3x4, at least 4x4.
Documentation for the function is found here: https://www.mathworks.com/help/matlab/ref/interp2.html
There is a response to a similar question here: https://www.mathworks.com/matlabcentral/answers/866695-input-grid-is-not-a-valid-meshgrid

Finding intersections of curves that cannot be represented as y=f(x)

I have two pairs of data sets, x1 vs y1 and x2 vs y2. x1, y1, x2, y2 all have uneven distribution of data represented by the following images:
My problem is to determine the intersection of the two pairs of data sets, x1/y1 and x2/y2, shown in following image:
I tried interpolating the data points to have even spacing, but due invalid regions of x1/y1 where there are multiple solutions for the same x value.
Here is a zoom in of the x1/y1 and x2/y2 relationship, showing that there are knots within the data set that cannot be interpolated in any orientation:
It seems that x2/y2 is a smooth curve, so you should be able to interpolate it piecewise with polynomials, and get decent results. Of course you will not want to do this with x1/y1, as your data is crazy. I will refer to the independent variable in the last two images as t. You can use the matlab spline function to do this interpolation from arrays of t and x2/y2 values. Your t value array in this case should be the same size as your set of x2/y2 values. Then you could loop over your x1/y1 points, using the interpolation to estimate x2/y2 at the same value of t. Then you could subtract these values. When the sign of this value changes for two consecutive x1/y1 points, you have a point of intersection between them. Then perform a linear interpolation between those two x1/y1 points and find the intersection of that line with your interpolated x2/y2 function. The code may get a little messy, but it should work. You will want to look at the MATLAB spline documentation.

Finding global minimum of complicated nonlinear function within the range of Earth's surface (MATLAB)

I am struggling with finding the global (or at least local minimum) of nonlinear 3-variable function S(t,x,y) defined as following with MATLAB 2016b:
Given function requires x_i, y_i, d_i, v as input variables and x, y, t are variables to be actually changed in certain range.
I found out that the MATLAB function fminsearch is quite useful when finding the local minimum, but I couldn't find the solution to find global minimum of such complicated function in the web.
The range of (x, y) is the every coordinate in the surface of Earth and t varies within short interval with the gap of approximately 100. Also, the function S is designed to take the input variables as Cartesian coordinates, not latitudes or longitudes.
I have another relevant question. Actually I have variables x_i, y_i as the form of latitudes and longitudes, not Cartesian coordinates. Thus, it is necessary that I should change those locations to Cartesian coordinates. Since four locations are concentrated in narrow region (within the latitude and longitude range less than 1 degree), I want to convert them to the Cartesian coordinates in plane by approximating that curvature is almost 0. However, I find it difficult because of lack of geometrical ability. Thus, I would be appreciated if someone could help me with this problem as well.
The following are four locations with latitudes and longitudes which I should input in S:
[lat_1, long_1]=(40.326800,-124.949200),
[lat_2, long_2]=(40.381200,-124.785300),
[lat_3, long_3]=(40.438700, -124.808500),
[lat_4, long_4]=(40.495500, -124.591800)
Currently, I wrote the function S in function_handle form like the following:
S=#(x)(((x(1)+sqrt((x(2)-m1(2,1))^2+(x(3)-m1(3,1))^2)/v)-m1(1,1))^2+((x(1)+sqrt((x(2)-m2(2,1))^2+(x(3)-m2(3,1))^2)/v)-m2(1,1))^2+((x(1)+sqrt((x(2)-m3(2,1))^2+(x(3)-m3(3,1))^2)/v)-m3(1,1))^2+((x(1)+sqrt((x(2)-m4(2,1))^2+(x(3)-m4(3,1))^2)/v)-m4(1,1))^2);
where m1,m2,m3,m4 are column vectors in the form of (t,x,y)

Regridding data from 2D grid to another

i'm working on a project involving netcdf data analisys. To correctly process the data i need to regrid it to a coarser level. The matrix is in fact multidimensional, but i only need spatial regridding, so basically i have to work with a lat/lon matrix.
The process i had in mind would consist, giving a source 2d grid (the one retrived from the netcdf) and a destination grid ( the one that i need for my calculations) the second of wich is coarser(have less points),in calculating a sort of weight matrix that contains the coefficients needed to compute each point of destination grid.
This will be helpful because i have a bunch of variables laying on the same grid, so if i calculate a weight matrix, the problem is reduced in a sequence of matrices multiplications.
basically what i need is a function f(lat_source,lon_source,lat_dest, lot_dest) that given the coords of the source/destinaiton grids return a matrix of weights that maps the dest lat/lon onto the source one.
is there something already implemented ? Or some reads that could point me in the right direction ?
I know there are different interpolation methods that could be used, but, for the sake of the argument, let's suppose a linear interpolation.

Interpolation of scattered scalar values in 3D volume

I have an unknown scalar fonction defined into a partial space (a pyramid portion), for this function, I have several measurements points into the coordonates mesurePoints, where the mesure mesure is known :
size(mesurePoints) = [n 3]
size(mesure) = n
I also have my space discretized into a clood of equidistant points wich I'll call interpolPoints,
I would like to obtain interpolated values interp_mesure on the points interpolPoints based on my measurements mesure on the points mesurePoints.
I tried to use interp3,
interp_mesure = interp3(...
mesurePoints(:,1),mesurePoints(:,2),mesurePoints(:,2),...
mesure,...
interpolPoints(:,1),interpolPoints(:,2),interpolPoints(:,3));
but I get the error that V (mesure) should be a 3D array, but I am confuse, my data isn't 3D, it is 3D dependant, but it's a scalar data, how can I proceed? Is interpol3 not adapted to my problem?
Edit 1 : Here is a similar problem to illustrate mine : how do you interpolate temperature in a volume if you have some temperature measurements in this volume?
Edit 2 : as no matlab solution have come to mind yet, I use a hand-made interpolation weighted by inverse distance with a power factor, the result is good close to points but as my points are quite scattered, the result is not good in empty areas.
I'm having trouble understanding exactly what is your data, but I get the impression that maybe interp1 or interp2 would be better suited to your needs, as your data isn't organized as a 3-D array