Fitting a curve (not a surface) for set of 3d points

1 回表示 (過去 30 日間)
PASUNURU SAI VINEETH
PASUNURU SAI VINEETH 2022 年 5 月 6 日
コメント済み: Star Strider 2022 年 5 月 7 日
We have a set of 3d points but could only generate a best fit surface using curve fitting tool. Is there a way to get the best fit curve? After obtaining such curve, how does one extract the sample points between the end points of the original data?
  2 件のコメント
Riccardo Scorretti
Riccardo Scorretti 2022 年 5 月 6 日
Can you share the data?
PASUNURU SAI VINEETH
PASUNURU SAI VINEETH 2022 年 5 月 6 日
x y z
-27.9887180593615 -1340.75546563430 -2467.65439789032
-28.1559650942894 -1264.59303658420 -2404.50824038076
-29.7919277205741 -1193.39703512010 -2300.00965848429
-31.3981715714723 -1120.17736318384 -2235.27618908221
-31.5451983267780 -1051.10973092073 -2140.30777056763
-32.8491580387443 -984.646322264197 -2063.56414843781
-33.2796553901372 -916.991538791753 -1996.11865926438
-35.8395784569732 -852.031242733576 -1911.15081465986
-37.1566640499132 -790.346389117523 -1815.82738997354
-38.3204915465027 -730.214519353841 -1746.18203218839
-40.1649399572649 -673.409308255575 -1674.26444109182
-41.3035654666637 -620.400594024487 -1587.01503697274
-42.1747052709711 -566.984092840253 -1500.55643509168
-46.1774120240010 -510.506804241280 -1356.63240367480
-46.8217316506543 -465.341776809379 -1312.21258689622
-48.1823821035027 -419.235048839213 -1236.80682112429
-46.8035473839173 -379.332398226134 -1160.38961081556
-50.4447955974995 -332.367954503435 -1049.62531161825
-51.6744777763725 -299.816833129747 -985.059960723105
-53.7621363830258 -263.954442877378 -898.073182985995
-57.1994027666078 -225.149444101340 -777.496668735717
-56.6340768082701 -199.990460428311 -708.719962466197
-58.8969572639191 -165.998414537714 -571.734657662908
-59.2922728658662 -147.613479302020 -529.946182294136
-63.0658812601543 -122.123656702184 -427.943227983156
-64.9755480437970 -102.744870160475 -328.893225669812
-64.7611060843518 -85.0805137022426 -223.268913127146
-66.8461254640729 -72.8327833085849 -156.365146230629
-68.9474184651645 -60.7799766280343 -50.0131596499198

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2022 年 5 月 6 日
I have no idea what model you want to fit to the data.
This does a linear regression —
A = [-27.9887180593615 -1340.75546563430 -2467.65439789032
-28.1559650942894 -1264.59303658420 -2404.50824038076
-29.7919277205741 -1193.39703512010 -2300.00965848429
-31.3981715714723 -1120.17736318384 -2235.27618908221
-31.5451983267780 -1051.10973092073 -2140.30777056763
-32.8491580387443 -984.646322264197 -2063.56414843781
-33.2796553901372 -916.991538791753 -1996.11865926438
-35.8395784569732 -852.031242733576 -1911.15081465986
-37.1566640499132 -790.346389117523 -1815.82738997354
-38.3204915465027 -730.214519353841 -1746.18203218839
-40.1649399572649 -673.409308255575 -1674.26444109182
-41.3035654666637 -620.400594024487 -1587.01503697274
-42.1747052709711 -566.984092840253 -1500.55643509168
-46.1774120240010 -510.506804241280 -1356.63240367480
-46.8217316506543 -465.341776809379 -1312.21258689622
-48.1823821035027 -419.235048839213 -1236.80682112429
-46.8035473839173 -379.332398226134 -1160.38961081556
-50.4447955974995 -332.367954503435 -1049.62531161825
-51.6744777763725 -299.816833129747 -985.059960723105
-53.7621363830258 -263.954442877378 -898.073182985995
-57.1994027666078 -225.149444101340 -777.496668735717
-56.6340768082701 -199.990460428311 -708.719962466197
-58.8969572639191 -165.998414537714 -571.734657662908
-59.2922728658662 -147.613479302020 -529.946182294136
-63.0658812601543 -122.123656702184 -427.943227983156
-64.9755480437970 -102.744870160475 -328.893225669812
-64.7611060843518 -85.0805137022426 -223.268913127146
-66.8461254640729 -72.8327833085849 -156.365146230629
-68.9474184651645 -60.7799766280343 -50.0131596499198];
figure
stem3(A(:,1), A(:,2), A(:,3), 'p')
grid on
xlabel('X')
ylabel('Y')
zlabel('Z')
title('Original Data')
DM = [A(:,[1 2]) ones(size(A(:,1)))]; % Design Matrix
B = DM \ A(:,3); % Linear Regression
fprintf('\nRegression Coefficients:\n\tB(1) = %10.3f\n\tB(2) = %10.3f\n\tB(3) = %10.3f\n',B)
Regression Coefficients: B(1) = -47.407 B(2) = 0.322 B(3) = -3333.979
Zhat = DM * B; % Fitted 'Z' Values
ResidNorm = norm(A(:,3)-Zhat) % Norm Of Residuals
ResidNorm = 205.0220
figure
scatter3(A(:,1), A(:,2), A(:,3), 'p', 'filled')
hold on
plot3(A(:,1), A(:,2), Zhat, '-r')
hold off
grid on
legend('Data','Linear Regression', 'Location','best')
xlabel('X')
ylabel('Y')
zlabel('Z')
title('Data & Fitted Linear Regression')
The regress function and fitlm provide statistics on the parameters and linear fit. To do a nonlinear regression (with an appropriate model), use fitnlm.
.
  4 件のコメント
PASUNURU SAI VINEETH
PASUNURU SAI VINEETH 2022 年 5 月 7 日
Thanks for the response. Here are 2 observations which I wanted to bring to your notice.
1) The suggested linear regression approach doesn't provide a smooth fit if observed from a different view than in the original response. Since it's of the form z=B1*x+B2*y+B3 where B1,B2 and B3 are constants for the whole curve, I expected the fit to be smooth.
2) Based on the physics of the problem (ball flight), a parabola would be a more appropriate fit. So, I went ahead with the following form for Design Matrix
DM = [ax.*ax ay.*ay ax.*ay ax ay ones(size(az))];
Data = readmatrix('data1.csv','NumHeaderLines',1);
x=0.001*Data(:,2);
y=0.001*Data(:,3);
z=0.001*Data(:,4);
[i]=find(y==min(y));
ax=x(i+1:end,:);
ay=y(i+1:end,:);
az=z(i+1:end,:);
DM = [ax.*ax ay.*ay ax.*ay ax ay ones(size(az))];
B = DM \ az;
Zhat = DM * B; % Fitted 'Z' Values
ResidNorm = norm(az-Zhat) ; % Norm Of Residuals
scatter3(ax,ay,az,'o')
hold on
grid on
plot3(ax, ay,Zhat, '-r')
xlabel('X')
ylabel('Y')
zlabel('Z')
Unfortunately, even this fit isn't smooth (despite being second degree in x and y). Can you please suggest a way to get a smooth non-linear fit and also the points sampling?
Star Strider
Star Strider 2022 年 5 月 7 日
My linear regression was simply a demonstration because no model or other description of the data or problem was provided.
That appears to be essentially an exact fit.
A simpler model works as well:
DM = [ax.^2 ay.^2 ones(size(az))];
I doubt that it is possible to improve it, or to smooth it significantly, other than by interpolating ‘DM’ to a matrix with fewer points.
.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by