meta data for this page
Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
en:design_guide_path [2020/12/03 05:55] JSCAD Editor |
en:design_guide_path [2022/04/13 12:44] (current) rozek included "require" statements, corrected mistakes |
||
|---|---|---|---|
| Line 4: | Line 4: | ||
| <code javascript> | <code javascript> | ||
| - | let mypathA = line([[10, 10], [-10, 10]]) | + | const { line } = require(' |
| - | let mypathB = line([[-10, -10], [10, -10]]) | + | const { path2 } = require(' |
| - | mypath = path2.concat(mypathA, | + | |
| + | const mypathA = line([[10, 10], [-10, 10]]) | ||
| + | const mypathB = line([[-10, -10], [10, -10]]) | ||
| + | let mypath = path2.concat(mypathA, | ||
| mypath = path2.close(mypath) | 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. | + | 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 segment |
| - | Curved paths can also be simulated. Paths can be created as an '' | + | The 'path2' |
| <code javascript> | <code javascript> | ||
| - | let mypath = line([[27, -22], [27, 22]]) | + | const { path2 } = require(' |
| - | mypath = path2.appendArc({endPoint: | + | |
| - | mypath | + | |
| </ | </ | ||
| - | === Append Points | + | === Curved Paths === |
| - | === Append | + | Curved paths can also be simulated. Paths can be created as an ' |
| - | === Append a Bezier Curve === | + | {{ : |
| + | The ' | ||
| + | Defaults: | ||
| + | * center : [0, 0] | ||
| + | * radius : 1 | ||
| + | * startAngle : 0 | ||
| + | * endAngle : PI * 2 | ||
| + | * segments : 32 | ||
| - | Which include: | + | <code javascript> |
| + | const { arc } = require(' | ||
| - | arc(endpoint, options): return a circular or ellipsoid curved path (see example below for usage). | + | const mypath = arc({radius: 5, startAngle: Math.PI / 2}) |
| + | const mypath = arc({center: | ||
| + | </ | ||
| - | appendPoint([x, | + | === Appending Points === |
| - | appendPoints([[x,y]]): return | + | Any number of points can be appended to a path, which produces |
| - | 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. | + | <code javascript> |
| + | const { path2 } = require(' | ||
| + | const { line } = require('@jscad/ | ||
| - | options can specify {resolution: | + | const mypath = line([[27, -22], [27, 22]]) |
| - | Paths can be concatenated with .concat(), the result is a new path. | + | const newpath = path2.appendPoints([[-27, 22], [-27, -27], [27, -22]], mypath) |
| + | </ | ||
| - | //Note: The difference between Paths and 2D shapes | + | An ' |
| + | |||
| + | Defaults: | ||
| + | * radius : [0, 0] | ||
| + | * clockwise : false | ||
| + | * large : false | ||
| + | * segments : 32 | ||
| + | |||
| + | // | ||
| + | |||
| + | <code javascript> | ||
| + | const { path2 } = require(' | ||
| + | |||
| + | let p1 = path2.create([[10, | ||
| + | p1 = path2.appendPoints([[27.5, | ||
| + | p1 = path2.appendArc({endpoint: | ||
| + | </ | ||
| + | |||
| + | In addition, ' | ||
| + | |||
| + | The ' | ||
| + | |||
| + | //Note: This implementation follows the SVG specifications.// | ||
| + | |||
| + | <code javascript> | ||
| + | const { path2 } = require(' | ||
| + | |||
| + | let p5 = path2.create([[10, | ||
| + | p5 = path2.appendBezier({controlPoints: | ||
| + | p5 = path2.appendBezier({controlPoints: | ||
| + | </ | ||
| === Conversion to 2D Shape === | === Conversion to 2D Shape === | ||
| Line 50: | Line 94: | ||
| <code javascript> | <code javascript> | ||
| + | const { geom2, path2 } = require(' | ||
| + | const { line } = require(' | ||
| + | |||
| // create a closed path in shape of triangle | // create a closed path in shape of triangle | ||
| - | let mypath = line([[10, 10], [-10, 10], [-10, -10], [10, 10]]) | + | const mypath = line([[10, 10], [-10, 10], [-10, -10], [10, 10]]) |
| - | let myshape = geom2.fromPoints(path2.toPoints(mypath)) | + | const 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. | + | Second, a path can be expanded into a two dimensional shape. The result is a two dimensional |
| <code javascript> | <code javascript> | ||
| // create an open path in shape of L | // create an open path in shape of L | ||
| - | let mypath = line([[10, 10], [-10, 10], [-10, -10], [10, 10]]) | + | const { expand } = require(' |
| - | let myshape = expand({delta: | + | const { line } = require(' |
| + | |||
| + | const mypath = line([[10, 10], [-10, 10], [-10, -10]]) | ||
| + | const myshape = expand({delta: | ||
| </ | </ | ||
| === Conversion to 3D Shape === | === Conversion to 3D Shape === | ||
| - | Hint: Any two dimensional | + | Two dimensional |
| + | |||
| + | <code javascript> | ||
| + | const { path2 } = require(' | ||
| + | const { extrudeLinear } = require(' | ||
| + | |||
| + | // create a closed path in shape of triangle | ||
| + | const mypath = path2.fromPoints({ closed: true }, [[0, 0], [12, 0], [6, 10]]) | ||
| + | // extrude into triangular prism | ||
| + | const myshape = extrudeLinear({ height: 15 }, mypath) | ||
| + | </ | ||