简体   繁体   English

如何减少贝塞尔曲线路径中的点数

[英]How to reduce the number of points in bezier curve paths

I have a large svg path which has quadratice bezier curves. 我有一个大的svg路径,它有quadratice贝塞尔曲线。 The path data is used for drawing maps. 路径数据用于绘制地图。 How to reduce the number of points of the bezier curve without distorting the overall shape? 如何在不扭曲整体形状的情况下减少贝塞尔曲线的点数?

You don't say whether you want to do this offline (pre-prepared paths) or online (on the fly). 您没有说是要离线(预先准备的路径)还是在线(动态)。 If offline is fine, use a tool like Inkscape. 如果离线很好,请使用像Inkscape这样的工具。

If you want to calculate the simplified curve yourself, then the typical algorithm used to do this is also the same one that has been used for drawing bezier curves. 如果您想自己计算简化曲线,那么用于执行此操作的典型算法也与用于绘制贝塞尔曲线的算法相同。 The algorithm is called "flattening". 该算法称为“展平”。

Basically the idea is to convert the bezier curves to a series of straight line segments. 基本上,我们的想法是将贝塞尔曲线转换为一系列直线段。 Because you don't want the the flatness of the line segments to be visible, you have to take into account the scale of the drawing and how curvy the bezier is. 因为您不希望线段的平整度可见,所以您必须考虑绘图的比例以及贝塞尔曲线的曲线。 If the bezier is very curvy you have to use more line segments than if it is fairly straight. 如果bezier非常曲线,你必须使用更多的线段而不是相当直的。

What you typically do is divide each bezier into two using De Casteljau's algorithm. 您通常使用De Casteljau算法将每个贝塞尔曲线分成两个。 Then look at each of the two half bezier curves. 然后查看两个半贝塞尔曲线中的每一个。 If a bezier is straight enough to meet a flatness limit you decide on, then stop dividing. 如果贝塞尔直线足以满足您决定的平直度限制,则停止分割。 Otherwise, divide in half and try again. 否则,分成两半再试一次。

At the end of the process you should get a polyline that is indistinguishable from the bezier version. 在该过程结束时,您应该获得与bezier版本无法区分的折线。 Or if you use a "flatness test" that is a bit courser than that, you will get a rougher approximation of the shape. 或者如果你使用比平面测试更平坦的“平整度测试”,你会得到更粗糙的形状近似值。 In your case a map. 在你的情况下一张地图。

If you google bezier flattening you can find a number of papers on the technique. 如果你google bezier flattening你可以找到很多关于这项技术的论文。 And a few pages which describe how to do it in a more friendly accessible way. 还有一些页面描述了如何以更友好的方式进行操作。 For example this one, which is about generating offset curves, but starts out by describing how to flatten a curve: 例如,这个是关于生成偏移曲线,但首先描述如何展平曲线:

https://seant23.wordpress.com/2010/11/12/offset-bezier-curves/ https://seant23.wordpress.com/2010/11/12/offset-bezier-curves/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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