# TIP #168 Version 1.1: Cubic Bezier Curves on the Canvas

This is not necessarily the current version of this TIP.

 TIP: 168 Title: Cubic Bezier Curves on the Canvas Version: $Revision: 1.1$ Author: Lars Hellström State: Draft Type: Project Tcl-Version: 8.5 Vote: Pending Created: Sunday, 25 January 2004

## Abstract

This document proposes a new -smooth method for line and polygon canvas items that supports cubic Bezier curves and clarifies some of the existing terminology in that area.

## Proposal

A new method for the -smooth canvas item option will be defined. Under this method, the points defining the item will be interpreted as a sequence knot-point control-point control-point knot-point control-point control-point ... of a curve composed of cubic Bezier segments. More precisely, if the list of coordinates is

  a_0 b_0 a_1 b_1 a_2 b_2 ...


then the Nth (counting from zero) segment of the curve consists of points whose coordinates (x,y) satisfies

  x = a_{3N} (1-t)^3 + 3 a_{3N+1} t (1-t)^2 + 3 a_{3N+2} t^2 (1-t) + a_{3N+3} t^3,
y = b_{3N} (1-t)^3 + 3 b_{3N+1} t (1-t)^2 + 3 b_{3N+2} t^2 (1-t) + b_{3N+3} t^3


for some value of t between 0 and 1, inclusive. If there are 3N+1 points then the above defines an N segment curve. In the case that the number of points is 3N or 3N-1 then they shall still define an N segment curve, where in the first case the first knot of the first segment is reused as the last knot in the last segment, and in the second case the first knot and control point in the first segment are reused as the last control point and knot in the last segment respectively.

Straight line segments in the curve can be encoded as a segment where the control points are equal to the neighbouring knot points. While this is not the only way to encode a straight line, it is a case that is recognised and handled more efficiently by code that renders the canvas item.

The name of this new method should be "raw".

The name of the existing -smooth method (as returned by the itemcget widget command) should be changed from "bezier" to "true", and the name "bezier", while at least in Tcl 8.5 still supported, should be deprecated.

## Rationale

Cubic Bezier curves, being for example the native curve format in Postscript and its descendants, is probably the most common format for smooth curves in computing today. It is even used internally in Tk; for each segment of a -smooth 1 curve, rendering starts with the calculation of a cubic Bezier representation of that curve and continues to use only this representation when approximating the smooth curve with straight line segments. Hence it might be claimed that the cubic Bezier curve is the "raw" format of a smooth curve in Tk. No new calculations need to be implemented in the core to implement this TIP, it is merely a matter of combining existing functions in a suitable way and move data around. Therefore it seems a waste to not provide cubic Bezier curves, when they are anyway already half implemented.

The reason for the interpretation of a curve with 3N points given is that this will cause the curve to be closed. Conversely, omitting the final knot point is sometimes used as a way of encoding the fact that the curve should be closed. This rule will therefore facilitate the use of data where then omitted endpoint convention has been employed. The only reason for the 3N-1 point rule is that it fits a simple scheme (when at the end of the list of coordinates, continue from the start) that supports the 3N and 3N+1 cases.

The reason for deprecating the name "bezier" for the traditional smoothing method is that it is at best confusing, and according to many authorities simply wrong. The term "Bezier curve" is very often used as a synonym of "cubic Bezier curve", whence the majority of programmers new to this feature of the canvas widget would probably expect "-smooth bezier" to imply the effect of the smoothing option proposed in this document rather than the smoothing via quadratic splines that it currently is. The amount of disappointment that could result from the unpleasant discovery that what one thought was the former is really the latter should not be underestimated.

The reason for changing the official name of the traditional smoothing method to "true" are (i) that it is backwards compatible in the sense that this name works for specifying that smoothing method in all Tk versions and (ii) that it is somewhat memnonic, because it happens to coincide with the format used for curves in TrueType fonts.

## Background

The question of what may rightfully be called "bezier" is somewhat complicated and deserves expounding upon. It really begins with Bernstein; the Bernstein degree n form of a polynomial f is

  f(t) = \sum_{k=0}^n  a_k \binom{n}{k} t^k (1-t)^{n-k}


[this is LaTeX code, in case anyone wonders]. One advantage this form has over the standard form is that the coefficients a_0, ..., a_n are directly comparable to the