ofn-path-to-shape

ofn-path-to-shape has been spurred by:

So this script takes a different approach: points coordinates come from anchors in an existing path. In other words, a path, drawn by hand or obtained bya previous script execution, is used to specify another path.

Functions in this script are divided in three groups:

The functions are accessed in a Shapes sub-menu, at the bottom of the right-click menu in the Paths list:

menu-location

Note: You need at least one path in that list before you can right-click on something.

Since a schematic is worth a thousands words, functions are mostly documented with graphics. The source path (the one on which the script is called) is in blue source, and the result path is in red result.


Functions on strokes

The general rules of functions on strokes are:


Circles

Note: Constructing a circle from a center and a radius or from a diameter is a function on segments (see below)

Circumcircle

This function draws the circle going through three points. In practice it finds the center and radius of the circle, and draws an approximation of the circle with Bezier splines, which may not go exactly through all three points, but by construction the first point is guaranteed to be on the circle.

circumcircle

For best accuracy, the three points should be as much spread apart as possible.

Crosshair

This function draws two perpendicular diameters of the circumcircle, one of them going through the first point of the stroke. Although it has its uses to draw accurate diameters, it is mostly handy to determine the center of the circle for various purposes, including many that won't even involve paths, such as the starting point for a radial gradient.

crosshair


Lines

Divide segment

The straight lines that goes through the two ends of the stroke is divided in as many sub-segments. In other words, the intermediate anchors in the source stokes are repositioned to equally divide the stroke.

divide

Multiply segment

The straight line segment that goes through the first two points of the stroke is extended with as many aligned sub-segments. In other words, the subsequent anchors are realigned with the first two and equally spaced.

multiply


Polygons

Polygon from circumradius

The circumradius is the line between the center of the polygon and a corner. The stroke points are:

  1. The center,
  2. The first corner,
  3. More points indicates the other corners, so that the whole stroke has one more anchor than the required number of corners.

circumradius-1

Note that if corner points can be roughly positioned on the image, which may help determine the needed number of corners, this is not mandatory and this would work just as well:

circumradius-2

Polygon from apothem

The apothem is the line between the center of the polygon and the middle of a side. The stroke points are:

  1. The center,
  2. The middle of the first side,
  3. More points indicate the other sides, so that the whole stroke has one more anchor than the required number of sides.

apothem

Polygon from side

The stroke points are:

  1. The beginning of the first side of the polygon,
  2. The end of the first side of the polygon,
  3. The first additional side. This point also indicates on which side of the initial segment the polygon should be.
  4. More points indicate the number of sides.

side


Rounded polygons

Rounded polygons are polygons with rounded corners. In the functions described below:

roudness

Rounded polygons (blue) can be seen as having an inner "support" polygon (green), whose corners are used as the center or the circles arcs. Between the two lies a strip of constant width (orange):

rounded-polygon-support

Rounded polygon from circumradius

The stroke points are:

  1. The center,
  2. The center of the rounding arc for the first corner,
  3. The midpoint of the arc of the first corner
  4. More points indicates the other corners, so that the whole stroke has two more anchors than the required number of corners.

strokes rounded-poligon-circumradius

Remark: the "support" polygon can be easily be constructed by deleting the third point of the stroke and using the function "Polygon from circumradius"

Rounded polygon from apothem

The stroke points are:

  1. The center,
  2. The radius of the rounding arc for the corners (th width of the orange strip in the picture above)
  3. The middle of the first side,
  4. More points indicate the other sides, so that the whole stroke has two more anchors than the required number of sides.

strokes-rounded-polygons-apothem

Rounded polygon from side

The stroke points are:

  1. The beginning of the first side of the enclosing "pointy" polygon (yellow),
  2. The beginning of the rounding arc,
  3. The end of the first side of the enclosing "pointy" polygon,
  4. The first additional side. This point also indicates on which side of the initial segment the polygon should be.
  5. More points indicate the number of sides, so that the whole stroke has one more anchor than the required number of sides.

strokes-rounded-polygons-side


Stars

Spokes

The stroke points are:

  1. The center,
  2. The end of the first spoke,
  3. Any additional points indicate additional spokes.

spokes

Star

The stroke points are:

  1. The center,
  2. The first outer ray,
  3. The radius for the inner corners,
  4. Additional points indicate the required number of rays.

star

Double star

The stroke points are:

  1. The center,
  2. The first outer ray,
  3. The radius for the inner corners,
  4. The radius for the secondary rays,
  5. Additional points indicate the required main rays.

doublestar


Rectangle

Unlike the other constructs, the stroke points do not define the orientation. The rectangle is always upright, with vertical and horizontal sides.

The stroke points are:

  1. One corner of the rectangle,
  2. The opposite corner of the rectangle,
  3. Optionally the radius of the rounded corners,

rectangle roundedrectangle


Functions on segments

Functions on segments build a shape using intervals between anchors in each stroke. The intervals only define the position, size and orientation of the shapes, everything else is specified in a dialog.

There are two ways to obtain segments from the stroke (in blue):

overlapping-vs-consecutive


Circles

Parameters are:

Of course, a single stroke with two points can be used to generate a simple circle.

Some examples:


Polygons

Parameters are:

pentagonhexagon


Rounded polygons

Parameters are:

segments-rounded-polygons-position-options-pentagon


Modify segments

This function is merely a way to move/resize the segments. The parameters are:

Example: result with Start=50 and End=110:

modifysegment

Hints:


Various functions

The catch-all section for everything that doesn't fit elsewhere.

Tangents

These functions compute the tangent to circles from either another circle or from a point. The circles are specified as either:

In other words, these functions do not operate only circle paths, but also on the paths that are used to construct the circles.

The result of these functions are additional paths that define the tangents. All possible tangents are computed, but there is one path per category of tangent so unwanted tangents can be easily discarded.

Tangents between circles

Note:

In the example below, a path containing two strokes (in blue) is used to create the tangents between two circles:

It can of course also be used to construct the circles (in red).

tangents-circles

Tangents to circle from point

Note:

In the example below:

The function is called on the blue path, after clicking on the link icon for the green path.

tangents-points

Using tangents to make continuous paths

When a continuous path must be obtained using parts of the circle(s) and the tangents, the trick is to use the tangent paths as guides to edit the circle path:


Putting it all together: creating a clock dial

The clock dial will have circles to make the hours, and small ticks for the minutes.

Hours

Add guides as an aid, and create a first path with the first point on the clock center, the second point on the 12 o'clock mark, then eleven more points roughly where the other hour marks will be (they could actually be anywhere, only their count is important, but this helps make sure their number is correct)

initial

Use Shapes>On strokes>Stars>Spokes to create 12 spokes evenly spaced:

hours-spokes

Getting the circles from there requires two more steps. First, using Shapes>On segments>Modify segments (with Start: 94 and End: 106) the spokes are transformed into small segments (in red) centered on their end:

hours-segments

Then circles (in green) are obtained from these segments using Shapes>On segments>Circles and using Segment reference: Diameter.

hours-circles

Minutes

Creating the minutes marks could be done the same way, but clicking 61 points could be prone to errors. A better way is to create a path for the clock diameter (in blue) and then use Shapes>On segments>Polygons or spokes to create 60 spokes:

minutes-spokes

Then, as for hours, create segments (in green) on the tip of the spokes, making them slightly shorter (with Start:96 and End:104):

minutes-segments

Finally

Use Edit>Stroke path to stroke the minute marks,

final-minutes

Then create a selection from the hours circles path, and bucket-fill the selection:

final-hours


Thanks to Rich2005 for his suggestions and review