使用Graphics在Mathematica中进行插值/平滑

时间:2011-07-16 18:22:57

标签: graphics wolfram-mathematica interpolation

我试图平滑我在点之间绘制的路径。

请考虑:

 lesPoints = {{41, 26}, {42, 29}, {41, 31}, {46, 30}, {48, 30}, 
              {40, 30}, {43, 30}, {47, 30}, {48, 26}, {47, 20}}

这些是我用来追踪时间路径的真实眼睛坐标。

这是我现在绘制它的方式:

Graphics[{
         Table[Arrow[{lesPoints[[i]], lesPoints[[i + 1]]}], 
              {i,Length[lesPoints] - 1}], 
         MapThread[Text[Style[#1, Large, FontFamily -> "Impact"], {#2, #3}] &, 
         PrependTo[Transpose[lesPoints], Range[1, Length@lesPoints]]]}]

enter image description here

在尝试使用插值时,我无法做任何事情。

这是一条平滑路径的好方法,还有什么选择呢?

2 个答案:

答案 0 :(得分:6)

这样的事情

lesPoints = {{41, 26}, {42, 29}, {41, 31}, {46, 30}, {48, 30}, 
          {40, 30}, {43, 30}, {47, 30}, {48, 26}, {47, 20}}

interpolation = Interpolation[Table[{i, lesPoints[[i]]}, {i, Length[lesPoints]}]]

然后路径变成类似

的路径
plot = ParametricPlot[interpolation[t], {t, 1, Length[lesPoints]}];
Show[plot, Graphics[{Red, PointSize[0.02], Point /@ lesPoints}], Axes -> False]

结果:

smooth curve

答案 1 :(得分:5)

这是另一种方式:

Show[Graphics[{Red, PointSize[0.02], Point /@ lesPoints}], 
     ListLinePlot[lesPoints, InterpolationOrder -> 4]]

enter image description here

修改

另外(更容易)

ListLinePlot[lesPoints, InterpolationOrder -> 4, Mesh -> Full,  Axes -> None]

修改

使用this beautiful package,您可以获得:

Show[Graphics[{Red, PointSize[0.015], Point /@ lesPoints}], 
 ListLinePlot[lesPoints, InterpolationOrder -> 4, Oriented     -> True, 
                                                  HowManyArrows -> 5]]

enter image description here

修改

最后一个:)

Show[
  ListLinePlot[
     lesPoints, InterpolationOrder -> 4, 
     Epilog -> (MapIndexed[Inset[Style[Text@First@#2, Medium], #1 + {-.2, .4}] &, 
               lesPoints]), 
     PlotRangePadding -> 1, Oriented -> True, Axes -> False, 
     PlotStyle -> Directive[Arrowheads[.015]]], 
 Graphics[{Red, PointSize[0.008], Point /@ lesPoints}]]

enter image description here