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