简体   繁体   中英

Interpolation/smoothing in Mathematica using Graphics

I am trying to smooth the path I draw between points.

Please consider:

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

Those are the real eye fixations coordinates I use to trace the temporal path.

This is the way I plot them now:

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]]]}]

在此处输入图像描述

I could not get anything right in my attempt to use interpolation.

Would it be a good way to smooth the path, what would be an alternative?

What about something like this

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]}]]

The path then becomes something like

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

Result:

平滑曲线

Here is another way:

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

在此处输入图像描述

Edit

Also (easier)

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

Edit

By using this beautiful package you can get:

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

在此处输入图像描述

Edit

last one:)

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}]]

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM