How to obtain a function through 3d points

Hi, I would like to obtain the function of a 3D curve (in my case, a helix) that fits a list of points of (x, y, z) coordinates, so that I can feed this function into a CAD program and obtain a swept extrusion. I'm trying this route so that I can obtain a customizable helix (edit: the points' coordinates have been generated through matlab as already belonging to a helix, just not a regular helix).
I have already taken a look at plotting 3D splines but I don't really need the Matlab plot, I need the function's expression so that I can draw it in CAD.
I haven't been able to find anything like so yet, I would be glad if anyone could point me in the right direction (even just the right documentation page would be fine). Thanks

1 Comment

I think it might be better to just make the CAD software create the spline through the points I have. Thanks to everyone who replied and helped :)

Sign in to comment.

Answers (3)

Obtaining the general "function" of some arbitrary set of points as a curve is essentially impossible to know, as there are infinitely many curves that will pass through any set of points. You can try to use curve fitting techniques, but you need to know the appropriate model.
I would strongly suggest that you are not looking to fit some general helix function to a set of points. Instead, I think you just need to understand how to create a helix, that has some desired set of properties.
A simple helix is easy to build. First, how do you create a circle? WORK IN POLAR COORDINATES.
t = linspace(0,2*pi);
x = cos(t);
y = sin(t);
Clearly, the pairs (x,y) represent points on the perimeter of a circle. Had I made t go further out, a circle is periodic. So the points would just keep on wrapping around. Trig functions are periodic, after all.
But now introduce a z-component, and I will go out further.
t = linspace(0,10*pi);
r = 1;
c = [0,0];
h = 3;
x = c(1) + r*cos(t);
y = c(2) + r*sin(t);
z = t/h;
plot3(x,y,z,'-o')
axis equal
grid on
box on
As you can see, I have created a simple helix. Changing the values of r and h will correspondingly change the general look of that curve, or translate it around, in the case of c. It is just as easy to create a heliz with varying properties along the z axis. For example, an elliptical helix that grows as z increases? Easy peasy.
rx = @(t) t;
ry = @(t) 2*t;
x = c(1) + rx(t).*cos(t);
y = c(2) + ry(t).*sin(t);
h = 0.5;
z = t/h;
plot3(x,y,z,'-o')
axis equal
grid on
box on
Anyway, I think what you need to understand is how to build a heix that does what you want.

5 Comments

I have already played with what you are suggesting, though I need an helix function quite more general than that, to satisfy varying design parameters. Another option would be a piecewise-defined helix, though it would be best to have smooth transitions between each subfunction. Thanks for your reply
The problem is, when you say you need something more general, that tells me there will be no simple functional form you can write down, and then encode into a function you can use.
You CAN use splines, but splines are not something you can write down any function for them. (That is a common request, and then answer is always sorry, but no.)
And a piecwwise helix, hey, feel free, do as you want, but as you already understand making things connect up smoothly at the join points becomes the domain of splines.
So sadly, there is probably no simple tool you can use, unless you want to get into the theory of splines, sufficiently so that you can write what you need. And even then, it will be a mess trying to get into the software you want to use.
Could you be able to use a scheme that would interpolate the points, replacing the perhaps too spare set, into a more densely sampled set? That would allow all of the interpolation to be done in MATLAB, resulting in a very finely spaaced curve. I'm not sure that would help you of course.
As you might guess I'm not an expert on this matter so of course I'm just interested in whatever model works the best, I don't necessarily need splines but they were the first thing to come up. For sure connecting a piecewise helix has issues regarding curvature at the joints, and that's why I'm trying to avoid it.
I'm the one generating the points' set so it can be as dense and regular as I want (it's just a variable pitch helix after all). I think the best thing I could hope for would be some sort of polinomial function to feed into the CAD program that interpolates the helix points I fed into MATLAB, but of course I don't really know if it's doable.
I understand and find everything you're telling me really interesting anyway, thanks
Ok, I'm a little confused. If you are using something to generate the helix points, then implicitly you have a function that generates them. It should not be necessary to build some polynomial, or anything. So where do they come from, and how do you control that tool? You do say you can control the density of the points.
The xyz points come from a simple MATLAB script which prints the coordinates of points belonging to the customizable helix, let's say, each 0.1*pi. I'm hoping that finding an interpolating function through these points might let me avoid a piecewise helix, for which I don't know how to make the transitions smooth (yet).
The finite amount of xyz points is just an excuse to have MATLAB do the work for me (until I find a better solution, of course), I understand it might be a little confusing

Sign in to comment.

Matt J
Matt J on 1 Aug 2023
Edited: Matt J on 1 Aug 2023
I would like to obtain the function of a 3D curve (in my case, a helix) that fits a list of points of (x, y, z) coordinates
Then, it is a data-fitting problem? If so, I would recommend first using cylindricalFit() from this FEX download,
This will let you fit the cylinder on which the helix is wound, and so determine its radius and 3D axis, assuming both are unknown. A direct example of this can be found under the Examples tab, Section Post-Sampling a Cylinder Fit.
Once you have fit the cylinder, you can perform a coordinate rotation so that the helix is parallel to the z-axis Once, you've done that you can solve for the pitch, c, by solving the over-determined parametric equations for an upright helix,

1 Comment

I'm sorry if I have used the wrong terminology, it's not really a data fitting problem but it's more of an interpolation of points belonging to the desired curve. I will have a look at your suggestion anyway, thanks

Sign in to comment.

Like John and Matt have been saying, you need to parameterize your curve, like have x, y, and z all be a function of the same parameter t. So if you have that -- 3 vectors of the same length, one for x, one for y, and one for z and they're all synced up (meaning x(1) goes with y(1) and z(1) and so on), then you can just interpolate each x, y, ans z independently to get the curve. Here's one of my canned, prior demos (which may not do exactly what you want but you could adapt it). It does spline interpolation.

7 Comments

Thanks for your demo, I will look into it. I find the 3 vectors approach really interesting, though I'm afraid its purpose is not to extract the interpolated function's expression, which is what I really need. Thanks anyway for your explanation
To fit the data to a model, you have to have a model in mind. Then you can use something like fit or fitnlm. Do you have an equation in mind that you think the data fit?
I'd use a MATLAB script to generate a finite amount of (x,y,z) coordinates points belonging to a helix. Hence the points are exactly on the helix, just not a regular one since I'd want to be able to change for example the pitch where I want. Hopefully, something like a helix with smaller pitch at the ends is described by a simple enough unique function. fitnlm looks quite intense but interesting, I will have a look at that too, thanks
Sure, you can fit a parameterized helix on x, y, and z independently. Just go ahead and use fitnlm. If you can't figure it out, see some of the attached demos or attach your actual data.
That's very kind of you! Thanks, I will update you if I have something useful to add
I think you might also have to built into the model how you expect the radius to change as it rises. For example, is the radius expected to be constant with z, or increate linearly or quadratically with z? If it's not constant, then it could get pretty tricky.
Being able to also change the helix radius along the way would be nice as generality is concerned but it's not a priority. I will look into everything since it's quite interesting, though as I investigate more I'm starting to think that making the CAD software itself produce the spline through the xyz points without having to feed a function into it might be the better option. Thanks again for your help!

Sign in to comment.

Categories

Products

Release

R2023a

Asked:

on 1 Aug 2023

Commented:

on 3 Aug 2023

Community Treasure Hunt

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

Start Hunting!