平滑2D曲线

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了平滑2D曲线相关的知识,希望对你有一定的参考价值。

我试图从提取的3D网格边界获得一条曲线。我执行以下操作来提取边界:

1-将3d网格划分为区域。

2-提取每个区域的边界

3-将3D边界转换为X-Y平面

4-划分边界

下图显示了生成的边界

坐标点的例子

X            Y
0.24628 1.49185
0.26724 1.49886
0.26145 1.49709
1.09528 1.21106
0.24628 1.49185
0.26724 1.49886
0.26854 1.49843
0.26145 1.49709
0.27626 1.50001
0.28379 1.50117
0.28052 1.49995
0.29360 1.50299
0.30082 1.50435
0.31017 1.50628
0.31869 1.50840
0.31892 1.50806
0.31310 1.50721
0.32771 1.50982
0.32776 1.50974
0.32273 1.50908
0.33226 1.51077
0.33587 1.51100
0.33716 1.51156
0.35389 1.51406
0.34641 1.51295
0.35603 1.51355
0.36336 1.51487
0.35952 1.51450
0.37433 1.51553
0.37424 1.51531
0.36849 1.51516
0.37762 1.51612
0.39076 1.51885
0.38323 1.51721
0.39896 1.52063
0.39360 1.51947
0.40832 1.52167
0.39940 1.52079
0.40585 1.52160
0.41145 1.52172
0.41705 1.52184
0.44010 1.51656
0.43655 1.51850
0.43308 1.52038
0.42088 1.52166
0.42924 1.52165
0.45349 1.51545
0.44314 1.52105
0.44609 1.51949
0.44128 1.52194
0.44346 1.51851
0.43612 1.52077
0.43352 1.52161
0.45740 1.51952
0.45362 1.52152
0.45902 1.51864
0.45718 1.51776
0.44799 1.52223
0.45641 1.52190
0.45276 1.52210
0.46447 1.52093
0.46262 1.52249
0.45878 1.52173
0.47343 1.52308
0.46783 1.52254
0.48399 1.52349
0.51303 1.50714
0.51572 1.50538
0.52216 1.50146
0.47684 1.52328
0.51830 1.50370
0.56776 1.48180
0.49813 1.52070
0.50241 1.51843
0.50621 1.51529
0.50965 1.51151
0.49087 1.52312
0.49571 1.52185
0.51155 1.51048
0.51743 1.50665
0.51595 1.50950
0.52167 1.50431
0.52152 1.50752
0.60742 1.46625
0.60089 1.46988
0.59427 1.47344
0.58765 1.47702
0.52324 1.50821
0.53034 1.50552
0.53514 1.50419
0.54106 1.49936
0.54553 1.49744
0.55001 1.49553
0.55442 1.49351
0.57071 1.48188
0.57622 1.48183
0.58207 1.47688
0.55988 1.48783
0.56496 1.48702
0.55865 1.49114
0.56980 1.48577
0.65251 1.44821
0.64822 1.45052
0.63995 1.45493
0.62263 1.46408
0.63582 1.45711
0.63266 1.45877
0.62757 1.46143
0.66556 1.44139
0.65897 1.44477
0.64444 1.44978
0.65149 1.44698
0.61362 1.46728
0.62044 1.46407
0.60674 1.47039
0.67856 1.44030
0.67426 1.44258
1.08037 1.21854
1.08367 1.21654
1.08742 1.21428
1.09026 1.21255
0.64367 1.45327
0.67167 1.44238
0.80349 1.37805
0.83693 1.35981
0.70140 1.43402
0.69392 1.43810
0.69163 1.43933
1.07434 1.22838
0.83009 1.36350
0.68492 1.44079
1.07049 1.22964
1.07401 1.22600
1.07766 1.22044
1.08714 1.21527
1.09326 1.21187
1.09528 1.21106
0.75771 1.40927
0.75171 1.41250
0.82535 1.37218
0.81628 1.37709
0.82059 1.37477
0.78098 1.39647
0.79159 1.39056
0.78660 1.39332
0.76986 1.40262
0.76715 1.40411
0.76388 1.40590
0.75928 1.40841
0.75789 1.40840
0.74587 1.41221
0.73972 1.41662
0.84214 1.35978
0.83556 1.36343
0.84109 1.36350
0.82945 1.36790
0.82338 1.37248
0.81674 1.37601
0.80968 1.37878
0.78124 1.39398
0.77590 1.39922
0.78676 1.38842
0.79204 1.38798
0.79777 1.38182
0.80297 1.38219
0.70403 1.43426
0.70939 1.43395
0.69775 1.43844
0.70302 1.43797
0.72189 1.42546
0.72809 1.42115
0.73366 1.42121
0.71565 1.42973
1.02362 1.26324
1.02790 1.25927
1.03297 1.25290
1.03732 1.25075
1.03167 1.25609
1.03570 1.25336
1.07091 1.23630
1.07433 1.23212
1.04194 1.24911
1.04686 1.24801
1.05225 1.24701
0.89862 1.33866
0.88048 1.34835
0.87569 1.35094
0.88905 1.34370
0.88686 1.34488
0.88223 1.34740
0.87377 1.35197
0.99367 1.28666
1.00647 1.27936
0.74504 1.41621
0.88074 1.34740
0.87411 1.35094
0.88826 1.33991
0.88732 1.34374
0.84792 1.36006
0.85374 1.36074
0.86725 1.35408
0.86039 1.35723
1.01659 1.26882
1.02050 1.26590
1.01152 1.27520
1.01537 1.27215
1.05677 1.24591
1.06151 1.24448
1.06584 1.24230
1.06970 1.23928
0.92078 1.33298
0.91777 1.33456
0.91618 1.33539
0.91196 1.33758
0.90920 1.33893
0.97498 1.30304
0.91081 1.33406
0.90963 1.33746
0.90193 1.33908
0.89438 1.34089
0.89976 1.34070
0.99758 1.28554
1.00174 1.28305
0.97934 1.29917
0.99152 1.29012
0.98521 1.29424
0.99577 1.28780
0.93860 1.32947
0.95180 1.32233
0.94649 1.32523
0.95703 1.31941
0.95579 1.32010
0.96171 1.31675
0.94571 1.32566
0.94042 1.32850
0.93912 1.32861
0.93204 1.33136
0.92474 1.33369
0.91717 1.33555
0.92264 1.33544
0.91508 1.33731
0.96647 1.31145
0.97034 1.30845
0.97396 1.30499
0.95091 1.32440
0.95694 1.31976
0.96123 1.31751
0.95508 1.32193
答案

尝试此代码并将输入与您的输入进行比较。

% Generate Noisy coordinates of a circle
h = viscircles([0,0],100);
x_noisy = h.Children(1).XData + randn(1,182);
y_noisy = h.Children(1).YData + randn(1,182);

% Smooth the coordinates
x_smooth = smoothdata(x_noisy,'gaussian',20);
y_smooth = smoothdata(y_noisy,'gaussian',20);

% Display the results 
plot(x_noisy, y_noisy)
hold on
plot(x_smooth, y_smooth)
hold off
axis image
legend('Noisy', 'Smoothed')
另一答案

这是我在评论中的意思的一个例子。我们的想法是使用极坐标对点进行排序,独立平滑坐标并转换回笛卡尔坐标。如果曲线中有循环,这将无法正常工作!

% Transform in polar coordinates
[theta , rho] = cart2pol(x,y);

% Sort data by angle
data = sortrows([theta , rho]);
theta = data(:,1);
rho = data(:,2);

% Smooth coordinates
theta = smooth(theta);
rho = smooth(rho , 10); % More aggressive smoothing for rho. You might
                        % have to adapt the type of smoothing to the 
                        % actual data of course.

% Transform back in cartesian coordinates
[X , Y] = pol2cart(theta , rho);

% Plot original and smooth result
plot(x,y,'b.')
hold on;
plot(X,Y , 'r-')

以上是关于平滑2D曲线的主要内容,如果未能解决你的问题,请参考以下文章

如何跟踪触摸时的手指运动以绘制平滑曲线?

GLSL片段着色器 - 绘制简单的粗曲线

GLSL片段着色器-绘制简单的粗曲线

python 路径平滑贝塞尔曲线优化

python 路径平滑贝塞尔曲线优化

python 路径平滑贝塞尔曲线优化