meta data for this page
  •  

This is an old revision of the document!


Path

A path is a series of points, connected by very thin (invisible) line segments. Paths can be created as a line from an array of points, or by calling various functions to create or extend another path.

let mypathA = line([[10, 10], [-10, 10]])
let mypathB = line([[-10, -10], [10, -10]])
mypath = path2.concat(mypathA, mypathB)
mypath = path2.close(mypath)

In addition, a path can be open or closed. An open path is typically used to create another by appending additional points. A closed path is final, and has a line between first and last points.

Curved paths can also be simulated. Paths can be created as an arc, or an arc can be appended to an existing path. The segments specify the number of segments to create per full rotation.

let mypath = line([[27, -22], [27, 22]])
mypath = path2.appendArc({endPoint: [-27, -22], radius: [54, 44], segments: 64}, mypath)
mypath = path2.close()

Append Points

Append the given list of points to the end of the given geometry.

let mypath = line([[27, -22], [27, 22]])
mypath = path2.appendPoints([[-27, 22], [-27, -27]], mypath)
mypath = path2.close()

Append an Arc

Append a Bezier Curve

Which include:

arc(endpoint, options): return a circular or ellipsoid curved path (see example below for usage).

appendPoint([x,y]): create and return a new Path containing the callee's points followed by the given point.

appendPoints(x,y): return a new Path containing the callee's points followed by the given points

appendBezier(x,y, options): create and return a new Path containing the callee's points followed by a Bezier curve ending at the last point given; all but the last point given are the control points of the Bezier; a null initial control point means use the last two points of the callee as control points for the new Bezier curve.

options can specify {resolution: 55}. Paths can be concatenated with .concat(), the result is a new path.

Note: The difference between Paths and 2D shapes are that Paths are composed of very thin lines, whereas a two dimensional shapes always enclose an area.

Conversion to 2D Shape

There are many ways to convert paths into to two dimensional shapes. The following provide some examples.

First, a two dimensional shape can be created from the points inside a path, but the path must be closed.

// create a closed path in shape of triangle
let mypath = line([[10, 10], [-10, 10], [-10, -10], [10, 10]])
let myshape = geom2.fromPoints(path2.toPoints(mypath))

Second, a path can be expanded into a two dimensional shape. The result is a shape that fits around the path. The path can be either open or closed.

// create an open path in shape of L
let mypath = line([[10, 10], [-10, 10], [-10, -10], [10, 10]])
let myshape = expand({delta: 2, corners: 'chamfer'}, mypath)

Conversion to 3D Shape

Hint: Any two dimensional shape can be extruded into a three dimensional shape.