How to do a spline and divide the spline into points of equal distance?

조회 수: 25 (최근 30일)
Hey everybody,
I have a problem concerning my bachelors Thesis and I don't really know what I have to do here...
The task is the following: I want to create a cubic spline through a couple of points, lets say 4 points and have the spline in hundred points of equal distance.
I don't know how to do this, but is there a possibility to to it with one of these functions?
So task is the following:
  • 4 points
  • 100 points inbetween the first and the last one and have them written in an excel file
I need that to do some automatic positioning stuff in a project.
Big thank you for your help in advance!
Johnny
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 7월 17일
See file exchange, John D'Errico interp_arc
Image Analyst
Image Analyst 2020년 7월 17일
John's program gives points equidistant along the actual curve itself, whereas my code below gives points sampled equidistant along the independent axis. Which you want to do really depends on your use case. What do your x and y represent? And why are your samples not equidistant now, and why do you want equidistant sampling?

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2020년 7월 14일
See attached demos.
spline_demo
spline_3d_curve
  댓글 수: 2
Jonathan Babitsch
Jonathan Babitsch 2020년 7월 14일
Thanks a lot for your work! I accepted your answer but honestly it wasn't exactly what I was searching for... I have four points and only want to calculate 100 points through these four points!
These 100 points should be written into an excel file because I need them for my further work!!
Would be great if you could help me out once again.
I don't need the points plotted at all!
Just the 100 points in x,y and z coordinates.
Thanks again!
Image Analyst
Image Analyst 2020년 7월 14일
편집: Image Analyst 2020년 7월 14일
I thought it would be easy for you to adapt. Everything has descriptive variable names and is well commented. So all you had to do was change two numbers. Anyway, here is I guess what you (hopefully) finally got:
% Demo to show spline interpolation.
% Clean up / initialize
clc;
close all;
clear all;
workspace; % Display workspace panel.
% Create the original knot points.
lengthX = 4;
x = 1:lengthX;
y = rand (lengthX,1);
% Plot it and show how the line has sharp bends.
plot(x, y, '-sr', 'LineWidth', 2);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
% Use splines to interpolate a smoother curve,
% with 25 times as many points (100 total),
% that goes exactly through the same data points.
samplingRateIncrease = 25;
newXSamplePoints = linspace(1, max(x), lengthX * samplingRateIncrease);
smoothedY = spline(x, y, newXSamplePoints);
% Plot smoothedY and show how the line is
% smooth, and has no sharp bends.
hold on; % Don't destroy the first curve we plotted.
plot(newXSamplePoints, smoothedY, '-ob');
title('Spline Interpolation Demo', 'FontSize', 20);
legend('Original Points', 'Spline Points');

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by