Re: SVG2 CR - Catmull-Rom curve commands missing??

On Nov 12, 2018, at 2:27 PM, Doug Schepers <standards@schepers.cc> wrote:
> I'm the person who originally suggested the Catmull-Rom path command. I'd love to see it added, as I think it would make a lot of authoring tasks much more straightforward.

For sure.


> My initial suggestion was simply having some form of smooth curve that interpolates between control points, such that all the control points are on the line itself (unlike Beziérs); after a bit of research, I stumbled on Catmull-Rom curves as a reasonable solution to that.

With no attempt to suggest the following should be used instead of Catmull-Rom, I wanted to share my own investigations into this.

Given a set of points (P0, P1, … Pn), and a desire to create a smooth path through them using a cubic Bézier curve, I came up with the following algorithm (which I ostentatiously call a “kistcurve”):

Put the first control point of the Bézier on the starting point P0.

Put every third Bézier control point on a points on the curve P1, P2, …

For each point calculate the segment between the adjacent points. (For endpoints P0 and Pn, use the endpoint for the adjacent point after the line.) For example, for point P7, calculate the segment P8-P6. Use this segment as the tangent at that point. Scale the length of the tangent between some maximum factor when the angle formed by the adjacent points is straight, and some minimum factor when the angle is 180°.


As shown in this test (works on Desktop on Chrome, doesn’t work on iOS Safari), the results (shown in dashed orange) can be quite similar to a Catmull-Rom curve (shown in blue). And by adjusting the min and maximum factors, you can control how smooth or sharp the curve is under some interesting factors.

http://phrogz.net/svg/kistcurve2_vs_catmullrom.html

Received on Monday, 12 November 2018 23:25:39 UTC