## Feature #766

### Add option to psxy to create Bézier curves

Status: | Closed | Start date: | 2015-09-17 | |
---|---|---|---|---|

Priority: | Normal | Due date: | ||

Assignee: | Paul | % Done: | 100% | |

Category: | - | Estimated time: | 12.00 hours | |

Target version: | Candidate for next minor release | |||

Platform: |

**Description**

This option should make it possible to draw a Bézier curve given a number of guide points given as a section of points in a file.

https://en.wikipedia.org/wiki/Bézier_curve

Something similar is possible in the LaTeX package PSTricks.

https://en.wikipedia.org/wiki/PSTricks

http://tug.org/PSTricks

Maybe we can learn something from it. It is likely that PostScript natively supports Bézier curves (curveto).

See the attachment as example.

### History

#### #1 Updated by Paul over 5 years ago

**Status**changed from*New*to*Feedback*

I have considered Bezier in the past. The way I thought to implement this is simply by taking input coordinates and fit the spline through them and use parameters of the spline to compute the Bezier spline guide points (there is C code for this on the web). It could be implemented via an extension to the **-A** option, e.g., **-Ab** for "resample the input data via a Bezier spline in the PostScript output". I don't think we want to read 4-5 columns of data to feed the PS bezier curve operator but compute these ourselves. I also think this would help beautify many aspects of our plots such as grid lines and curved boundaries which are now drawn as straight line segments. For many of these we could compute the bezier parameters directly and draw via a separate PSL function, for instance.

#### #2 Updated by Remko over 5 years ago

That's not exactly what I had in mind, but the **-A** extension is a good idea.

I thought to simply replace the PostScript "draw" command with "curveto". This would require that the input should be 4 points per segment. The curve would start in point 0 and end in point 3, with point 1 and point 2 serving to determine the tangents of the curve starting at point 0 and ending at point 3. This can be extended to allow any 3n+1 points, where the curveto would go through points 3i (with i=0...n). Because this line would have discontinuities, it would be better to have point 2 determine point 4 such that the tangent in point 3 is the same, ingoing or outgoing.

I think it would be simply be (x4,y4)=2(x3,y3)-(y2,y2). And hence the requirement would be to allow 2n+2 points per segment. However, I might be wrong about the assumption that one can derive point 4 from points 2 and 3, as that would limit the "velocity" component of the curve outgoing from point 3.

#### #3 Updated by Paul over 5 years ago

One reason I added the option to get derivatives of the cubic spline in sample1d is that these derivatives are needed to compute (x1,y1) and (x2,y2) for the Bezier guide points. Once I am done grading some homework (...) I will work up a new function that takes the psxy (x,y) input and produces the guide points and then a new function will write with the curveto function. We can then discuss whether this should be normal behavior (similar to us resampling along great circles if exceeding a threshold) or controlled by a new GMT defaults, or via -A. It may allow us to avoid using such a dense resampling along great circles as we currently do.

#### #4 Updated by Paul over 5 years ago

**Status**changed from*Feedback*to*Resolved*

This has now been added via revised pen option -W<pen>[+s] for Bezier spline. It is only available in psxy for now. In r14975.

#### #5 Updated by Paul over 5 years ago

**Assignee**changed from*Remko*to*Paul***% Done**changed from*0*to*100*

#### #6 Updated by Paul over 5 years ago

**Status**changed from*Resolved*to*Closed*

Closed as this is implemented and working.