4.2 Text objects4 Object types4.1 Path objects

4.1 Path objects

Path objects are defined by a set of subpaths, that is, curves in the plane. Each subpath is either open or closed, and consists of straight line segments, circular or elliptic arc segments, parabola segments (or, equivalently, quadratic Bézier splines), cubic Bézier splines, and cubic B-spline segments. The curves are drawn with the stroke color, dash style, and line width; the interior of the object specified is filled using the fill color.

The distinction between open and closed subpaths is meaningful for stroking only, for filling any open subpath is implicitely closed. Stroking a set of subpaths is identical to stroking them individually. This is not true for filling: using several subpaths, one can construct objects with holes, and more complicated pattern. The filling algorithm is normally the even-odd rule of Postscript/PDF: To determine whether a point lies inside the filled shape, draw a ray from that point in any direction, and count the number of path segments that cross the ray. If this number is odd, the point is inside; if even, the point is outside.

Ipe can draw arrows on the first and last segment of a path object, but only if that segment is part of an open subpath.

There are several Ipe modes that create path objects in different ways. All modes create an object consisting of a single subpath only. To make more complicated path objects, such as objects with holes, you create each boundary component separately, then select them all and use the Compose paths function in the Edit menu. The reverse operation is Decompose path, you find it in the context menu of a path object that has several subpaths.

You can also create complicated paths by joining curves sequentially. For this to work, the endpoint of one path must be (nearly) identical to the begin point of the next—easy to achieve using snapping. You select the path objects you wish to join, and call Join paths in the Edit menu. You can also join several open path objects into a single closed path this way.

Circles can be entered in three different ways. To create an ellipse, create a circle and shear or stretch and rotate it. Circular arcs can be entered by clicking three points on the arc or by clicking the center of the supporting circle as well as the begin and end vertex of the arc. They can be filled in Postscript/PDF fashion, and can have arrows. You can stretch a circular arc to create an elliptic arc.

A common application for arcs is to mark angles in drawings. The snap keys are useful to create such arcs: set arc creation to center & 2 pts, select snap to vertex and snap to boundary, click first on the center point of the angle (which is magnetic) and click then on the two bounding lines.

There are two modes for creating more complex general path objects. The difference between line mode and polygon mode is that the first creates an open path, the latter generates a closed one. As a consequence, the line mode uses the current arrow settings, while the polygon mode doesn't. The path object created using line or polygon mode consists of segments of various types. The initial setting is to create straight segments. By holding the shift-key when pressing the left mouse button one can switch to splines. Ipe offers three different kinds of splines: uniform B-splines, cardinal splines, and clothoid splines. You can select the type of spline in the Properties menu. Quadratic and cubic Bézier spline segments can be created as special cases of uniform B-splines with three and four control points.

Circular arcs can be added as follows: Click twice in polyline mode, once on the starting point of the arc, then on a point in the correct tangent direction. Press the a key, and click on the endpoint of the arc.

To make curves where segments of different type are joined with identical tangents, you can press the y key whenever you are starting a new segment: this will set the coordinate system centered at the starting point of the segment, and aligned with the tangent to the previous segment.

For the mathematically inclined, a more precise description of the segments that can appear on a subpath follows.

A subpath consists of a sequence of segments. Each segment is either a straight line segment, an elliptic arc, or a spline of one of the three supported types.

Note that a uniform B-spline with only three control points will be drawn as a quadratic Bézier spline. A B-spline with four control points is by definition a cubic Bézier spline.

The quadratic Bézier spline defined by control points p0, p1, and p2, is the curve

P(t) = (1-t)2 p0 + 2t(1-t) p1 + t2 p2,
where t ranges from 0 to 1. This implies that it starts in p0 tangent to the line p0p1, ends in p2 tangent to the line p1p2, and is contained in the convex hull of the three points. Any segment of any parabola can be expressed as a quadratic Bézier spline.

For instance, the piece of the unit parabola y = x2 between x=a and x=b can be created with the control points

p0 = (a, a2)
p1 = ( (a + b)/(2), ab)
p2 = (b, b2)
Any piece of any parabola can be created by applying some affine transformation to these points.

The cubic Bézier spline with control points p0, p1, p2, and p3 is the curve

R(t) = (1-t)3p0 + 3t(1-t)2 p1 + 3 t2(1-t) p2 + t3 p3.
It starts in p0 being tangent to the line p0p1, ends in p3 being tangent to the line p2p3, and lies in the convex hull of the four control points.

Uniform cubic B-splines approximate a series of n control points p0, p1, …, pn-1, n ≥ 3, with a curve consisting of n-3 cubic Bézier splines, see, for instance, Sederberg.1 To clamp the spline to the first and last control point, the first and last knot are repeated three times. If the curve is closed (a splinegon), there is no clamping and n control points define n Bézier splines.

Since each point on a Bézier curve is a convex combination of the four control points, the curve segment lies in the convex hull of the control points. Furthermore, any affine transformation can be applied to the curve by applying it to the control points. Note that a control point has influence on only a few Bézier segments, so when you edit a spline object and move a control point, only a short piece of the spline in the neighborhood of the control point will move.

A cardinal spline is an interpolating spline—unlike a uniform B-spline, it will go through the control points. Ipe converts a sequence of n control points into n-1 Bézier segments, each starting and ending at a control point. The tangent at each control point is parallel to the segment connecting the previous and the next control point.

Finally, a clothoid spline (spline type "spiro") is created by solving an optimization problem that tries to minimize the change in curvature (so they look much "rounder" and are generally more pleasing). Details can be found in Raph Levien's thesis.