Calculating the parameter of a 3d curve consituted of a 100 points
1 view (last 30 days)
Show older comments
Hello, I am a beginner to matlab and I'm trying to calculate the parameter of a sphere like curve constituted of 100 points, the following is a picture of the curve:
Can anyone provide a sample code or instructions on how to do such thing, much appreciated!
1 Comment
Dyuman Joshi
on 1 Aug 2023
Edited: Dyuman Joshi
on 1 Aug 2023
For a simple polygon, Perimeter can be defined the sum of distances of each connected pair i.e. sum of distance between 1&2, 2&3, 3&4, ..., n-1&n, n&1.
You can apply this logic to write a code to get the perimeter.
Answers (1)
John D'Errico
on 1 Aug 2023
Edited: John D'Errico
on 28 Sep 2023
Um, I'm not sure the question is about estimating the perimeter of the curve, or a parameter, perhaps the radius, that together with the center of the sphere, that defines the sphere.
As it is though, the simple sum of distances between pairs of consecutive points will not truly give a good measure of the distance around that curve! The probem is, on a noisy curve as we see here, that piecewise sum will give a greatly exaggerated distance measure, Think of it in terms of fractals. That curve could be viewed as sort of a fractal thing. For example:
t = linspace(0,2*pi,100);
x0 = cos(t); x = x0 + randn(size(t))/20;
y0 = sin(t); y = y0 + randn(size(t))/20;
x(end) = x(1); % insure the first and last points are the same.
y(end) = y(1); % insure the first and last points are the same.
plot(x0,y0,'b-',x,y,'r-')
legend('Basic curve(no noise)','Curve with noise added')
So we see a moderately noisy curve, that SHOULD represent a circle. As such, the distance around that curve should be 2*pi.
D0 = sum(sqrt(diff(x).^2 + diff(y).^2))
Yet had the same computation been done for the same curve without any noise added in at all. we would see a much smaller distance, that should be slightly less than 2*pi=6.28...
D0 = sum(sqrt(diff(x0).^2 + diff(y0).^2))
The difference between the two can be viewed as a measure of the fractal dimension of that curve. In this case, it is merely caused by the random noise I added on, which while seemingly not that huge, actually almost doubled the measured distance around that curve. A similar problem arises if we try to measre the length of coastline around an island. If you do that by looking at the coastline in depth, thus measuring around every rock, every pebble, every grain of sand on every beach, the measured distance will be huge. Instead, a surveyor might establish a set of fixed points, and approximate that distance as the sum of distances between consecutive pairs of points.
Anyway, if the question is about estimating the parmaters that define a sphere, there are sphere fitting tools on the file exchange, though not all I would really consider good tools. (You get what you pay for.) If the question is about estimating the length of that curve, then it might be best to perform some sort of smoothing operator on the curve first, to reduce the apparent noise. You should see that as in the example I gave above, if you do try to compute the length of that curve directly from the data itself without any smoothing, it will always significantly overestimate the true length of the curve, as you would get after smoothing has been applied.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!