How to obtain a function through 3d points

조회 수: 24 (최근 30일)
fralab
fralab 2023년 8월 1일
댓글: fralab 2023년 8월 3일
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
fralab
fralab 2023년 8월 3일
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 :)

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

답변 (3개)

John D'Errico
John D'Errico 2023년 8월 1일
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
John D'Errico
John D'Errico 2023년 8월 2일
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.
fralab
fralab 2023년 8월 3일
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

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


Matt J
Matt J 2023년 8월 1일
편집: Matt J 2023년 8월 1일
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
fralab
fralab 2023년 8월 1일
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

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


Image Analyst
Image Analyst 2023년 8월 1일
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
Image Analyst
Image Analyst 2023년 8월 3일
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.
fralab
fralab 2023년 8월 3일
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!

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

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by