Linearising paths
Table of contents
A GraphicsPath
can contain line segments, cubic Bézier segments and arc segments. This allows great flexibility, but it can be inconvenient in some situations, and can cause some computations to take a relatively long time (since there are no analytical formulae for some properties of Bézier curves, which have to be approximated using numerical approaches).
To simplify working with a GraphicsPath
, it is possible to “linearise” it, i.e. to replace all curves (arcs and Bézier curves) with straight segments that approximate them. This can greatly simplify some computations.
The GraphicsPath.Linearise
method
To linearise a GraphicsPath
, you can use the Linearise
method. This method requires a single parameter, a double
specifing the “resolution” of the linearisation in graphics units, i.e. the length of the straight segments that are used to approximate each curve. The smaller this value, the more accurate the approximation; however, the resulting path will contain more segments.
The following example shows how to use this method:
Back to top Back to Advanced topics
The GetLinearisationPointsNormals
method
When a smooth path is linearised using the Linearise
method, the normal of the path is not continuous any more, because a singularity is introduced at every joining point of two segments. The GetLinearisationPointsNormals
method, when used on the original GraphicsPath
object at the same resolution as the Linearise
method, returns a collection of Points
that correspond to the normals of the path at the end points of each segment. These can be e.g. interpolated to produce a smooth approximation of the original path.
The following example shows how to use this method.
Back to top Back to Advanced topics
The Graphics.Linearise
method
Sometimes, you may want to linearise multiple GraphicsPath
s that have been drawn on a Graphics
surface. You can do so by using the Linearise
method of the Graphics
class. This method has a single double
parameter, representing the linearisation resolution, that has the same meaning as the parameter of the GraphicsPath.Linearise
method. It returns a new Graphics
object, in which:
- Rectangles and raster images are left unchanged.
- Paths are linearised using the specified resolution.
- Text objects are transformed into paths and then linearised using the specified resolution.
You can then use the new Graphics
object as normal (e.g. drawing it on another Graphics
surface).