Another interesting thing to do is to extract some points from a GraphicsPath. This can be achieved using a number of methods of the GraphicsPath class.
The GetPoints method
The GetPoints method returns the end points of all the segments in the path (regardless of whether each segment is a line segment, an arc, or a Bézier curve). The method returns a IEnumerable<List<Point>>, where each List contained in the IEnumerable corresponds to the points of a different figure (a figure is initiated on each call to MoveTo).
The following example shows how to use this method.
Note that the IEnumerable returned by this method is enumerated lazily; therefore, if you need to reuse the points multiple times, it may be beneficial to convert it to a List or an array, so that it does not have to be enumerated more than once.
The GetPointAtAbsolute and GetPointAtRelative methods
The GetPointAtAbsolute and GetPointAtRelative methods make it possible to obtain the point at the specified position in the path (even if it is not the end point of a segment).
Both methods require a single double parameter, which determines the position in the path of the point to be returned. For the GetPointAtAbsolute method, this is expressed in graphics units; for the GetPointAtRelative method, this is expressed as a fraction of the total length of the path.
The library measures the length of each segment in the path until it finds the point at the specified offset from the beginning of the path.
The following example shows how to use the GetPointAtRelative method:
Getting the tangent and normal at a specific point
In addition to GetPointAtAbsolute/GetPointAtRelative, other methods can be used to compute the tangent and the normal at a specific point in the path. These are GetNormalAtAbsolute/GetNormalAtRelative (for the normal) and GetTangentAtAbsolute/GetTangentAtRelative (for the tangent).
Each method takes a single double argument representing the position of the point at which the normal/tangent is computed (the difference between the “relative” and “absolute” methods is the same as for the GetPointAtAbsolute/GetPointAtRelative methods). These methods return a Point whose length is 1, representing a versor in the direction of the tangent/normal.
The following example shows how to use these methods.