Shape Interpolation from csv

12 次查看(过去 30 天)
Sam Hill
Sam Hill 2020-8-21
编辑: Stephan 2020-8-21
I have a shapes in terms of cartesian coordinates read from a csv file and want to interpolate the shape to increase the number of points I have. CSV has three columns (X, Y, Z) and each row is on point. All the documentation I have found (meshgrid, datagrid, ect) works by using vectors to create a grid of points, I already have the points but matlab will not let me manipulate the data while in 'double' format. How can I read in the data and interpolate the points to increae the density of my meshes?
%Read in file data
a=csvread('r1.csv');
%convert m to mm
X=a(:,1)/1000;
Y=a(:,2)/1000;
Z=a(:,3)/1000;
Then I want to interpolate between data points to increase the number of points I have.
Any help will be greatly appreciated.

回答(2 个)

Walter Roberson
Walter Roberson 2020-8-21
File Exchange, John D'Errico, "interparc"
  1 个评论
Sam Hill
Sam Hill 2020-8-21
a=csvread('r1.csv')
a1=a(:,1)/1000;
a2=a(:,2)/1000;
a3=a(:,3)/1000;
ra=interparc(0.5, a1, a2, a3)
returns the error:
Error using chckxy (line 50)
The first input must contain unique values.
Error in spline (line 72)
[x,y,sizey,endslopes] = chckxy(x,y);
Error in interparc (line 316)
spl{i} = spline(cumarc,pxy(:,i));

请先登录,再进行评论。


Stephan
Stephan 2020-8-21
编辑:Stephan 2020-8-21
If the curvature is small enough compared to the distance between the original points, a little bit of analytical geometry might help:
% Some data to play with - an arbitrary line in 3D
x = [1 2 3 4];
y = [-1 5 2 7];
z = [0 1 2 6];
% Concatenate vectors of x, y, z to one matrix
A = [x; y; z];
% Calculate Coordinates of the bisector to get query points
B = (A(:,1:end-1) + A(:,2:end)) ./ 2;
% Extract the single vectors
xq = B(1,:);
yq = B(2,:);
zq = B(3,:);
% plot the line that connects all original points
plot3(x,y,z)
hold on
% plot the original points in blue
scatter3(x,y,z,'ob','filled')
% plot the new interpolated points in red
scatter3(xq,yq,zq,'or','filled')
hold off
You could repeat this process (for example by using a function) if you need more points.

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by