mat*_*ath 8 algorithm geometry line sampling
我有一个l_1点系列给出的线p_1,...,p_n.我现在想要一个新的生产线l_2有k两点:q_1,...,q_k.但对于所有i \in {1,...,k-1}: abs( q_i - q_i+1 ) = const,意味着段l_2是等距或制服.
k >= 2p_1和p_n应该在l_2.abs( p_i - p_i+1 ) 不是常数一种解决方案是使用样条近似一条线,然后再次对其进行二次采样,以获得均匀的长度段.我可以做得更好吗?那有什么C++代码吗?
啊,我错过了一个具体的细节:那些q_i应该在l_1,这意味着它们是在线段l_1或它们是样本点l_1.
您可以定义分段参数函数:
f[t_] := Piecewise[
When x[i] <= t <= x[i + 1]
f[t]= (y[i+1]-y[i]) (t - x[i]) / (x[i+1]-x[i]) + y[i],
For {i, 1 ... N};
Run Code Online (Sandbox Code Playgroud)
然后选择你的点q,理想情况下间距小于最小p [i + 1] -p [i]
最后以相等的t间隔对f [q]进行采样.
样本结果:
在这里,您可以看到原始样本中将区间大小从最大值减小到最小值的效果:

您可以评估近似的优点,将原始曲线和重新采样曲线之间的区域(积分)相加:

如果您绘制不同间隔大小的积分,您可以决定什么是良好的采样:

仅供记录,Mathematica中的代码是:
a = 0;
p = Table[{ a = a + RandomReal[], RandomReal[]}, {10}];
f[t_, h_] := Piecewise[Table[{(h[[i + 1, 2]] - h[[i, 2]]) (t - h[[i, 1]]) /
(h[[i + 1, 1]] - h[[i, 1]]) + h[[i, 2]],
h[[i, 1]] <= t <= h[[i + 1, 1]]},
{i, 1, Length[h] - 1}]];
minSeg[h_] := Min[Table[Norm[h[[i, 1]] - h[[i + 1, 1]]], {i, Length[h] - 1}]];
newSegSize[h_] := (h[[Length@h, 1]] - h[[1, 1]])/
Ceiling[(h[[Length@h, 1]] - h[[1, 1]])/minSeg[h]]
qTable = Table[{t, f[t, p]}, {t, p[[1, 1]], p[[Length@p, 1]], newSegSize[p]}];
Run Code Online (Sandbox Code Playgroud)
编辑:回答你的评论
评论pgm代码:
a = 0; (* Accumulator to ensure an increasing X Value*)
p = Table[{a = a + RandomReal[],
RandomReal[]}, {10}]; (*Generates 10 {x,y} Rnd points with \
increasing x Value*)
f[t_, h_] := (* Def. a PWise funct:
Example of resulting function:
f[t,{{1,2},{2,2},{3,4}}]
Returns teh following function definition:
Value for Range
2 1<=t<=2
2+2*(-2+t) 2<=t<=3
0 True
*)
Piecewise[
Table[{(h[[i + 1, 2]] -
h[[i, 2]]) (t - h[[i, 1]])/(h[[i + 1, 1]] - h[[i, 1]]) + h[[i, 2]],
h[[i, 1]] <= t <= h[[i + 1, 1]]},
{i, 1, Length[h] - 1}]];
minSeg[h_] := (* Just lookup the min input point separation*)
Min[Table[Norm[h[[i, 1]] - h[[i + 1, 1]]], {i, Length[h] - 1}]];
newSegSize[h_] := (* Determine the new segment size for having
the full interval length as a multiple of the
segment size *)
(h[[Length@h, 1]] - h[[1, 1]])/
Ceiling[(h[[Length@h, 1]] - h[[1, 1]])/minSeg[h]]
qTable = (*Generates a table of points using the PW function *)
Table[
{t, f[t, p]},
{t, p[[1, 1]], p[[Length@p, 1]],newSegSize[p]}];
ListLinePlot[{qTable, p}, PlotStyle -> {Red, Blue}] (*Plot*)
Run Code Online (Sandbox Code Playgroud)