3D curve line fitting
Show older comments
Hi all,
My basic question is this. I have a set of data in 3D space that makes an approximate ellipse ring, with a few bends and noise. Is there an easy way to connect the points in a smooth way to make a nicely connected ring?
I created this simple code to represent what my data may look like.
%Create X and Y based on ellipse equation
x = -2:.1:2;
xnoise = (rand(1,81)-0.5)/10;%Generate small noise in x
y = sqrt(1-((x.*x)/4));
ynoise = (rand(1,81)-0.5)/10;%Generate small noise in y
x = [x(1:end-1) flipdim(x,2)];
x = x+xnoise;
y = [-y(1:end-1) y];
y = y+ynoise;
%Create Z using sine
s = 0:2*pi/80:2*pi;
z = sin(s);
znoise = (rand(1,81)-0.5)/10;%Generate small noise in z
z = z+znoise;
%Plot data field
plot3(x,y,z,'o')
Keep in mind that my knowledge of Matlab is limited and I would like a solution that can be utilized in coding as opposed a toolbox function. Thanks in advance!
Answers (1)
I asked the same question and get a nice answer though it has past a year since you ask it might help others to post the answer here.
just append the following at the end
hold on;
d= [x;y;z]';
[th, r, z] = cart2pol(d(:,1),d(:,2),d(:,3));
[sr, idx] = sort(th);
sd = d(idx,:);
plot3(sd(:,1), sd(:,2), sd(:,3))
Categories
Find more on Correlation and Convolution in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!