Autodesk Creative Platform Core Version 1.19.0
A broad and deep collection of 2D and 3D capabilities.

Path2D Overview

2D paths are vector shapes on a 2D plane, such as the graphic objects you would find in a vector-based graphics program like Adobe Illustrator. They can be extruded to create 3D shapes using the Solid.extrude() function. The Path2D API is equivalent to the HTML5 Canvas API's methods for creating paths. Create an object that represents a 2D path. Call this constructor with JavaScript's standard new keyword: new Path2D() By default, the path is empty. Add line and curve segments to the path using the methods described below.

See Also: Bezier2D, Line2D

Introduced in Version: 1.0.0

Class Member Summary

Class Member Details

• Path2D ([json]) | Constructor

The following parameters can be specified in the constructor:
  • json: JSON - JSON received from the toJSON method. Throws exception if JSON not valid. | Optional

Path2D bezierCurveTo (cp1x, cp1y, cp2x, cp2y, x, y) | Chainable

Creates a cubic Bézier curve from the path's current point to the point (x, y), with two control points at (cp1x, cp1y) and (cp2x, cp2y) that control the curvature of the resulting curve. After adding the line, sets the path's current point to this line's end point.
  • cp1x: Number - coordinate x of first control point
  • cp1y: Number - coordinate y of first control point
  • cp2x: Number - coordinate x of second control point
  • cp2y: Number - coordinate y of second control point
  • x: Number - coordinate x of end point
  • y: Number - coordinate y of end point

Path2D clone()

Clones the Path2D object

Path2D close() | Chainable

Closes the path by creating a line segment from the path's current point to the start point of the path.

Line2D or Bezier2D curveAt (idx)

Constructs the curve at the given index
  • idx: Number - the index of curve

Array [ Line2D or Bezier2D ] curvesByPoint (point, tolerance)

Returns a collection of curves whose distances to the given point is less than tolerance. If the given point is close to a control point of a Bezier curve, the Bezier curve will be selected too. The result curves are sorted on the distance to the given point from farthest to closest
  • point: Point2D - A reference point to use for finding the curves.
  • tolerance: Number - A maximum distance from the reference point that curves can be.

Line2D or Bezier2D firstCurve()

Gets the first curve of the path

Line2D or Bezier2D lastCurve()

Gets the last curve of the path

Path2D lineTo (x, y) | Chainable

Creates a straight line from the path's current point to the point (x, y). After adding the line, sets the path's current point to the line's end point.
  • x: Number - coordinate x of end point
  • y: Number - coordinate y of end point

Path2D moveTo (x, y) | Chainable

Sets the path's current point to the point (x, y). The current point is used by a path's line-drawing methods as the starting point for each added line segment. By default, the current point of a newly created path lies at (0, 0).
  • x: Number - coordinate x of end point
  • y: Number - coordinate y of end point

Path2D quadraticCurveTo (cpx, cpy, x, y) | Chainable

Creates a quadratic Bézier curve from the path's current point to the point (x, y), with a control point at (cpx, cpy) that controls the curvature of the resulting curve. After adding the line, sets the path's current point to this line's end point.
  • cpx: Number - coordinate x of the control point
  • cpy: Number - coordinate y of the control point
  • x: Number - coordinate x of end point
  • y: Number - coordinate y of end point

JSON toJSON() | Beta - May Change!

Returns the JSON repressentation of the object that can be serialized. The resulting JSON can be passed into the constuctor later on to reconstruct the object.

Array [ Array [ Number ] ] toPolygons ([tolerance])

Gets an array of connected path outlines. If the first and last points are the same then the path is closed.
  • tolerance: Number - A chord height deviation to use for discretizing nonlinear curves. | Optional

1 Example:

// Iterate the polygons generated from the path2d
var polygons = path2DObj.toPolygons();
for (var i = 0; i < polygons.length; i++) {
    var polygon = polygons[i];
    for (var j = 0; j < polygon.length; j+=2) {
        var x = polygon[j];
        var y = polygon[j+1];
        ...
    }
}

Path2D transform (matrix) | Chainable

Transforms the geometry on the path by a transformation matrix.

2 Examples:

    // Scale to 2X and translation by 5, 5
    var tm = [
                2, 0, 0,
                0, 2, 0,
                5, 5, 1
             ];
    path.transform(tm);
    // Scale to 2X and translation by 5, 5
    var tm = new Matrix2D();
    tm.identity().scaling(2).translation(5, 5);
    path.transform(tm);