[Ipe-discuss] Spline tutorial

Otfried Cheong ipe at otfried.org
Sun Feb 5 22:12:20 CET 2023

On Sun, Jan 29, 2023, at 12:19, Soeren Terziadis via Ipe-discuss wrote:
> Recently it was mentioned here 
> <https://github.com/otfried/ipe-issues/issues/444> that a tutorial of 
> spline usage and editing would be nice to have. I tried my hand at one 
> and attached it.
> However I am no expert when it comes to splines. In particular I am not 
> a hundred percent sure about the statement that IPE approximates any 
> spline with a sequence of cubic B-Splines, when they are rendered 
> (something I got from here 
> <https://ipe.otfried.org/manual/manual_16.html> but might have 
> misunderstood).

This is very nice, thanks a lot.  Once you have uploaded it to the Wiki, I will link to it from the manual.

All curves in Ipe (including circular arcs) are rendered as a sequence of cubic Bezier curves, and all spline types (B-splines, cardinal splines, clothoid splines) can actually be converted into a sequence of Bezier curves inside Ipe.

The reason you cannot switch between splines and lines mode inside the splinegon tool is that the splinegon tool creates a *single* closed subpath that does not have *any* vertices, only control points.   And switching mode can only happen at a *vertex*.  If the terminology is not clear:  A path object can consist of several subpaths (think filled object with holes).  Each subpath is either open (has a starting point and an endpoint) or closed (a loop), and consists of *pieces*.  Each piece begins and ends at a vertex, so the subpath visits all the vertices in this order.  A piece can simply be a straight segment (so the polyline tool creates many pieces), a circular arc, or a spline (so the spline tool actually creates a *single* piece, unless you switch to line mode while drawing).  A spline starts and ends in the vertex, and is otherwise specified by control points (which are not visited by a B-spline).  When editing a path object, the vertices are displayed as pink disks, the control points as blue squares.

So when you say "Note that this action actually cuts the spline in two. You obtain one spline object consisting of two disconnected subpaths and two endpoints of these paths coincide",
this isn't quite the Ipe-terminoloy:   What it does is to cut the spline *piece* into two pieces, so the subpath has now one more vertex (which lies on the original spline piece) and one more piece.  It is still a single subpath with the same start point and end point and completely identical geometric shape.

If you want to split a subpath (into two subpaths), you would need to use the function "Cut at vertex" of the contex menu at a *vertex*.  (If the subpath was originally closed, this will turn it into an open subpath.)  Very often you then want to delete one of the two halves - that's how you create shorter versions of a given path. 

Often Ipe users want to cut a B-spline in the middle.  Ipe allows you to do this only at the *knots* of the B-spline: these are the points where one Bezier curve of the B-spline ends and the next one begins.  This is the operation "Insert vertex at knot" that you describe.

To cut a B-spline at an *arbitrary* point, one needs to do a bit more work:  you need to first insert vertices at the knots surrounding the cutting point (so two times "Insert vertex at knot").  This will turn the middle piece into a single Bezier curve (it has exactly two blue control points), for which you can then use the cutting tool that you describe.

It would probably be nice to add the possibility of cutting the B-spline directly, and let Ipe find the two knots automatically.  In fact, it's on my todo list: https://github.com/otfried/ipe-issues/issues/374#issuecomment-776854980

If only the day had more hours...


More information about the Ipe-discuss mailing list