通过预定点的 SVG 曲线

bar*_*rej 7 math svg curve-fitting

我是 SVG 的初学者。

我需要一条穿过点列表的 SVG 曲线。它是一个用 C++ 计算的数学函数,输出结果应该写入 SVG 文件中。我的问题是pathSVG 中的标签没有穿过所有点。相反,它会在中间跳过其中一些,而只是倾向于它们。SVG是否有任何设施可以使曲线通过整个点并以自动方式适当弯曲曲线?

数学曲线

<svg height="400" width="450">
  <path d="M 80 90 C 190 40, 300 60, 380 160" stroke="blue" stroke-width="5" fill="none" />
  <path d="M 80 90 L 190 40, 300 60, 380 160" stroke="green" stroke-width="1" fill="none"/>
  <g stroke="black" stroke-width="3" fill="black">
    <circle id="pointC" cx="80" cy="90" r="3" stroke="black"/>
    <circle id="pointA" cx="190" cy="40" r="3" stroke="green"/>
    <circle id="pointC" cx="300" cy="60" r="3" stroke="red"/>
    <circle id="pointB" cx="380" cy="160" r="3" stroke="blue"/>
  </g>
  Sorry, your browser does not support inline SVG.
</svg>
Run Code Online (Sandbox Code Playgroud)

fan*_*ang 5

如果需要通过许多点绘制平滑曲线,请考虑使用 Catmull Rom 样条线或 Overhauser 样条线。两种算法都会产生在线段连接处具有 C1 连续性的三次样条。此外,它们比实现 C2 B 样条插值更容易实现,因为后者需要求解线性方程组。您还可以轻松地将 Catmull Rom 样条线或 Overhauser 样条线转换回贝塞尔形式。