Shape Interpolation from csv

12 visualizzazioni (ultimi 30 giorni)
Sam Hill
Sam Hill il 21 Ago 2020
Modificato: Stephan il 21 Ago 2020
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.

Risposte (2)

Walter Roberson
Walter Roberson il 21 Ago 2020
File Exchange, John D'Errico, "interparc"
  1 Commento
Sam Hill
Sam Hill il 21 Ago 2020
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));

Accedi per commentare.


Stephan
Stephan il 21 Ago 2020
Modificato: Stephan il 21 Ago 2020
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.

Categorie

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

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by