Mathematica中的插值/平滑运算使用图形功能

3

我正在尝试使我在点之间绘制的路径更加平滑。

请考虑以下事项:

 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个回答

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]

结果:

平滑曲线


谢谢您的回答。我留了一点空间,看看其他专家是否受到启发,但这解决了我的问题! - 500

5
这里还有另一种方法:
Show[Graphics[{Red, PointSize[0.02], Point /@ lesPoints}], 
     ListLinePlot[lesPoints, InterpolationOrder -> 4]]

输入图像描述

编辑

另外(更简单的方法)

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

编辑

通过使用这个优秀的软件包,您可以获得:

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

这里输入图片描述

编辑

最后一个啦 :)

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


如果您有位置和时间,您也可以动画移动! - Dr. belisarius
哇哦,谢谢您。我已经有时间了,肯定想要实现那些美丽的路径!我必须说我现在感到困惑,我认为我需要修改我构建眼动分析主程序的方式,我没有使用Show函数,而是将所有内容放在一个大的图形中。这正在创建麻烦,我只能通过使用一些Plot函数来暂时解决问题。而现在这些警报又响起了。 - 500
谢谢。我会尽力让问题简单化并向您提问。这是论坛的最大好处之一!通常,在将问题抽象化以提问时,我会在途中解决它! - 500
@500,我不知道这是否有帮助,但是Mathematica中的普通2D绘图函数(例如ListLinePlotParametricPlot)会产生形式为Graphics[{primitives}, options]的内容。因此,如果您不想为曲线创建单独的绘图并使用Show(看着您的文件,我可以理解为什么:-)),您可以将类似于ListLinePlot[...] [[1]]的内容直接放入您的Graphics中以获取曲线路径。 - Heike
@Heike,谢谢您的关注!我会尝试的! - 500
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接