Skip to main content

Class: DrawingPen

Defined in: packages/replicad/src/draw.ts:263

DrawingPen is a helper class to draw in 2D. It is used to create drawings by exposing a builder interface. It is not a drawing itself, but it can be used to create a drawing.

Extends​

Implements​

Constructors​

Constructor​

new DrawingPen(origin?): DrawingPen;

Defined in: packages/replicad/src/draw.ts:267

Parameters​

origin?​

Point2D = ...

Returns​

DrawingPen

Overrides​

BaseSketcher2d.constructor

Arc Segment​

bulgeArc()​

bulgeArc(
xDist,
yDist,
bulge): this;

Defined in: packages/replicad/src/Sketcher2d.ts:273

Draws an arc of circle by defining its end point and the bulge - the maximum distance between the arc and the straight line going from start to end point in units of half the chord. The end point is defined by its horizontal and vertical distances from the start point.

Parameters​

xDist​

number

yDist​

number

bulge​

number

Returns​

this

Implementation of​

GenericSketcher.bulgeArc

Inherited from​

BaseSketcher2d.bulgeArc


bulgeArcTo()​

bulgeArcTo(end, bulge): this;

Defined in: packages/replicad/src/Sketcher2d.ts:265

Draws an arc of circle by defining its end point and the bulge - the maximum distance between the arc and the straight line going from start to end point.

Parameters​

end​

Point2D

bulge​

number

Returns​

this

Implementation of​

GenericSketcher.bulgeArcTo

Inherited from​

BaseSketcher2d.bulgeArcTo


hBulgeArc()​

hBulgeArc(distance, bulge): this;

Defined in: packages/replicad/src/Sketcher2d.ts:284

Draws an horizontal arc of circle by defining its end point and the bulge

  • the maximum distance between the arc and the straight line going from start to end point in units of half the chord. The end point is defined by its horizontal distance from the start point.

Parameters​

distance​

number

bulge​

number

Returns​

this

Implementation of​

GenericSketcher.hBulgeArc

Inherited from​

BaseSketcher2d.hBulgeArc


hSagittaArc()​

hSagittaArc(distance, sagitta): this;

Defined in: packages/replicad/src/Sketcher2d.ts:261

Draws an horizontal arc of circle by defining its end point and the sagitta - the maximum distance between the arc and the straight line going from start to end point.The end point is defined by its horizontal distance from the start point.

Parameters​

distance​

number

sagitta​

number

Returns​

this

Implementation of​

GenericSketcher.hSagittaArc

Inherited from​

BaseSketcher2d.hSagittaArc


sagittaArc()​

sagittaArc(
xDist,
yDist,
sagitta): this;

Defined in: packages/replicad/src/Sketcher2d.ts:250

Draws an arc of circle by defining its end point and the sagitta - the maximum distance between the arc and the straight line going from start to end point.The end point is defined by its horizontal and vertical distances from the start point.

Parameters​

xDist​

number

yDist​

number

sagitta​

number

Returns​

this

Implementation of​

GenericSketcher.sagittaArc

Inherited from​

BaseSketcher2d.sagittaArc


sagittaArcTo()​

sagittaArcTo(end, sagitta): this;

Defined in: packages/replicad/src/Sketcher2d.ts:223

Draws an arc of circle by defining its end point and the sagitta - the maximum distance between the arc and the straight line going from start to end point.

Parameters​

end​

Point2D

sagitta​

number

Returns​

this

Implementation of​

GenericSketcher.sagittaArcTo

Inherited from​

BaseSketcher2d.sagittaArcTo


tangentArc()​

tangentArc(xDist, yDist): this;

Defined in: packages/replicad/src/Sketcher2d.ts:308

Draws an arc of circle from the current point as a tangent to the previous part of curve drawn.The end point is defined by its horizontal and vertical distances from the start point.

Parameters​

xDist​

number

yDist​

number

Returns​

this

Implementation of​

GenericSketcher.tangentArc

Inherited from​

BaseSketcher2d.tangentArc


tangentArcTo()​

tangentArcTo(end): this;

Defined in: packages/replicad/src/Sketcher2d.ts:288

Draws an arc of circle from the current point as a tangent to the previous part of curve drawn.

Parameters​

end​

Point2D

Returns​

this

Implementation of​

GenericSketcher.tangentArcTo

Inherited from​

BaseSketcher2d.tangentArcTo


threePointsArc()​

threePointsArc(
xDist,
yDist,
viaXDist,
viaYDist): this;

Defined in: packages/replicad/src/Sketcher2d.ts:210

Draws an arc of circle by defining its end point and a third point through which the arc will pass. Both poinats are defined in horizontal (x) and vertical (y) distances from the start point.

Parameters​

xDist​

number

yDist​

number

viaXDist​

number

viaYDist​

number

Returns​

this

Implementation of​

GenericSketcher.threePointsArc

Inherited from​

BaseSketcher2d.threePointsArc


threePointsArcTo()​

threePointsArcTo(end, midPoint): this;

Defined in: packages/replicad/src/Sketcher2d.ts:198

Draws an arc of circle by defining its end point and a third point through which the arc will pass.

Parameters​

end​

Point2D

midPoint​

Point2D

Returns​

this

Implementation of​

GenericSketcher.threePointsArcTo

Inherited from​

BaseSketcher2d.threePointsArcTo


vBulgeArc()​

vBulgeArc(distance, bulge): this;

Defined in: packages/replicad/src/Sketcher2d.ts:280

Draws a vertical arc of circle by defining its end point and the bulge

  • the maximum distance between the arc and the straight line going from start to end point in units of half the chord. The end point is defined by its vertical distance from the start point.

Parameters​

distance​

number

bulge​

number

Returns​

this

Implementation of​

GenericSketcher.vBulgeArc

Inherited from​

BaseSketcher2d.vBulgeArc


vSagittaArc()​

vSagittaArc(distance, sagitta): this;

Defined in: packages/replicad/src/Sketcher2d.ts:257

Draws a vertical arc of circle by defining its end point and the sagitta

  • the maximum distance between the arc and the straight line going from start to end point.The end point is defined by its vertical distance from the start point.

Parameters​

distance​

number

sagitta​

number

Returns​

this

Implementation of​

GenericSketcher.vSagittaArc

Inherited from​

BaseSketcher2d.vSagittaArc

Bezier Curve​

bezierCurveTo()​

bezierCurveTo(end, controlPoints): this;

Defined in: packages/replicad/src/Sketcher2d.ts:425

Draws a generic bezier curve to the end point, going using a set of control points.

This is the generic definition of a bézier curve, you might want to use either the quadratic or cubic (most common) version, unless you know exactly what you are aiming at.

Parameters​

end​

Point2D

controlPoints​

| Point2D | Point2D[]

Returns​

this

Implementation of​

GenericSketcher.bezierCurveTo

Inherited from​

BaseSketcher2d.bezierCurveTo


cubicBezierCurveTo()​

cubicBezierCurveTo(
end,
startControlPoint,
endControlPoint): this;

Defined in: packages/replicad/src/Sketcher2d.ts:449

Draws a cubic bezier curve to the end point, using the start and end control point to define its shape. This corresponds to the most commonly used bezier curve.

If you are struggling setting your control points, the smoothSpline might be better for your needs.

Parameters​

end​

Point2D

startControlPoint​

Point2D

endControlPoint​

Point2D

Returns​

this

Implementation of​

GenericSketcher.cubicBezierCurveTo

Inherited from​

BaseSketcher2d.cubicBezierCurveTo


quadraticBezierCurveTo()​

quadraticBezierCurveTo(end, controlPoint): this;

Defined in: packages/replicad/src/Sketcher2d.ts:445

Draws a quadratic bezier curve to the end point, using the single control point.

Parameters​

end​

Point2D

controlPoint​

Point2D

Returns​

this

Implementation of​

GenericSketcher.quadraticBezierCurveTo

Inherited from​

BaseSketcher2d.quadraticBezierCurveTo


smoothSpline()​

smoothSpline(
xDist,
yDist,
splineConfig?): this;

Defined in: packages/replicad/src/Sketcher2d.ts:498

Draws a cubic bezier curve to the end point, attempting to make the line smooth with the previous segment. The end point is defined by its distance to the first point.

It will base its first control point so that its tangent is the same than the previous segment. You can force another tangent by defining startTangent.

You can configure the tangent of the end point by configuring the endTangent, either as "symmetric" to reproduce the start angle, as an angle from the X axis (in the coordinate system) or a 2d direction (still in the coordinate system.

The start- and end- factors decide on how far the control point is from the start and end point. At a factor of 1, the distance corresponds to a quarter of the straight line distance.

Parameters​

xDist​

number

yDist​

number

splineConfig?​

SplineConfig

Returns​

this

Implementation of​

GenericSketcher.smoothSpline

Inherited from​

BaseSketcher2d.smoothSpline


smoothSplineTo()​

smoothSplineTo(end, config?): this;

Defined in: packages/replicad/src/Sketcher2d.ts:457

Draws a cubic bezier curve to the end point, attempting to make the line smooth with the previous segment.

It will base its first control point so that its tangent is the same than the previous segment.

The control point relative to the end is by default set to be in the direction of the straight line between start and end. You can specifiy the endSkew either as an angle (in degrees) to this direction, or as an absolute direction in the coordinate system (a Point).

The start- and end- factors decide on how far the control point is from the start and end point. At a factor of 1, the distance corresponds to a quarter of the straight line distance.

Parameters​

end​

Point2D

config?​

SplineConfig

Returns​

this

Implementation of​

GenericSketcher.smoothSplineTo

Inherited from​

BaseSketcher2d.smoothSplineTo

Drawing State​

penPosition​

Get Signature​

get penPosition(): Point2D;

Defined in: packages/replicad/src/Sketcher2d.ts:92

Returns the current pen position as [x, y] coordinates

Added By Ben Harper 5/12/2025

Returns​

Point2D

Inherited from​

BaseSketcher2d.penPosition

Drawing State​

Added By Ben Harper 5/12/2025 to solve issue with being unable to draw a line perpendicular to the tangent extension at the end of a .tangentArc() that did not finish at a known angle.

penAngle​

Get Signature​

get penAngle(): number;

Defined in: packages/replicad/src/Sketcher2d.ts:108

Returns the current pen angle in degrees

The angle represents the tangent direction at the current pen position, based on the last drawing operation (line, arc, bezier, etc.). Returns 0 if nothing has been drawn yet.

Returns​

number

Inherited from​

BaseSketcher2d.penAngle

Ellipse Arc Segment​

ellipse()​

ellipse(
xDist,
yDist,
horizontalRadius,
verticalRadius,
rotation?,
longAxis?,
sweep?): this;

Defined in: packages/replicad/src/Sketcher2d.ts:381

Draws an arc of ellipse by defining its end point and an ellipse. The end point is defined by distances from he start point.

The shape of the ellipse is defined by both its radiuses, its angle relative to the current coordinat system, as well as the long and sweep flags (as defined for SVG paths)

Parameters​

xDist​

number

yDist​

number

horizontalRadius​

number

verticalRadius​

number

rotation?​

number = 0

longAxis?​

boolean = false

sweep?​

boolean = false

Returns​

this

Implementation of​

GenericSketcher.ellipse

Inherited from​

BaseSketcher2d.ellipse


ellipseTo()​

ellipseTo(
end,
horizontalRadius,
verticalRadius,
rotation?,
longAxis?,
sweep?): this;

Defined in: packages/replicad/src/Sketcher2d.ts:313

Draws an arc of ellipse by defining its end point and an ellipse.

The shape of the ellipse is defined by both its radiuses, its angle relative to the current coordinat system, as well as the long and sweep flags (as defined for SVG paths)

Parameters​

end​

Point2D

horizontalRadius​

number

verticalRadius​

number

rotation?​

number = 0

longAxis?​

boolean = false

sweep?​

boolean = false

Returns​

this

Implementation of​

GenericSketcher.ellipseTo

Inherited from​

BaseSketcher2d.ellipseTo


halfEllipse()​

halfEllipse(
xDist,
yDist,
minorRadius,
sweep?): this;

Defined in: packages/replicad/src/Sketcher2d.ts:415

Draws an arc as half an ellipse, defined by the sagitta of the ellipse (which corresponds to the radius in the axe orthogonal to the straight line).The end point is defined by distances from he start point.

The sweep flag is to be understood as defined for SVG paths.

Parameters​

xDist​

number

yDist​

number

minorRadius​

number

sweep?​

boolean = false

Returns​

this

Implementation of​

GenericSketcher.halfEllipse

Inherited from​

BaseSketcher2d.halfEllipse


halfEllipseTo()​

halfEllipseTo(
end,
minorRadius,
sweep?): this;

Defined in: packages/replicad/src/Sketcher2d.ts:401

Draws an arc as half an ellipse, defined by the sagitta of the ellipse (which corresponds to the radius in the axe orthogonal to the straight line).

The sweep flag is to be understood as defined for SVG paths.

Parameters​

end​

Point2D

minorRadius​

number

sweep?​

boolean = false

Returns​

this

Implementation of​

GenericSketcher.halfEllipseTo

Inherited from​

BaseSketcher2d.halfEllipseTo

Line Segment​

hLine()​

hLine(distance): this;

Defined in: packages/replicad/src/Sketcher2d.ts:160

Draws an horizontal line of length distance from the current point

Parameters​

distance​

number

Returns​

this

Implementation of​

GenericSketcher.hLine

Inherited from​

BaseSketcher2d.hLine


hLineTo()​

hLineTo(xPos): this;

Defined in: packages/replicad/src/Sketcher2d.ts:168

Draws an horizontal line to the x coordinate

Parameters​

xPos​

number

Returns​

this

Implementation of​

GenericSketcher.hLineTo

Inherited from​

BaseSketcher2d.hLineTo


line()​

line(xDist, yDist): this;

Defined in: packages/replicad/src/Sketcher2d.ts:152

Draws a line at the horizontal distance xDist and the vertical distance yDist of the current point

Parameters​

xDist​

number

yDist​

number

Returns​

this

Implementation of​

GenericSketcher.line

Inherited from​

BaseSketcher2d.line


lineTo()​

lineTo(point): this;

Defined in: packages/replicad/src/Sketcher2d.ts:142

Draws a line from the current point to the point given in argument

Parameters​

point​

Point2D

Returns​

this

Implementation of​

GenericSketcher.lineTo

Inherited from​

BaseSketcher2d.lineTo


polarLine()​

polarLine(distance, angle): this;

Defined in: packages/replicad/src/Sketcher2d.ts:178

Draws a line from the current point to the point defined in polar coordiates, of radius r and angle theta (in degrees) from the current point

Parameters​

distance​

number

angle​

number

Returns​

this

Implementation of​

GenericSketcher.polarLine

Inherited from​

BaseSketcher2d.polarLine


polarLineTo()​

polarLineTo(__namedParameters): this;

Defined in: packages/replicad/src/Sketcher2d.ts:172

Draws a line from the current point to the point defined in polar coordiates, of radius r and angle theta (in degrees) from the origin

Parameters​

__namedParameters​

Point2D

Returns​

this

Implementation of​

GenericSketcher.polarLineTo

Inherited from​

BaseSketcher2d.polarLineTo


tangentLine()​

tangentLine(distance): this;

Defined in: packages/replicad/src/Sketcher2d.ts:184

Draws a line from the current point as a tangent to the previous part of curve drawn. The distance defines how long the line will be.

Parameters​

distance​

number

Returns​

this

Implementation of​

GenericSketcher.tangentLine

Inherited from​

BaseSketcher2d.tangentLine


vLine()​

vLine(distance): this;

Defined in: packages/replicad/src/Sketcher2d.ts:156

Draws a vertical line of length distance from the current point

Parameters​

distance​

number

Returns​

this

Implementation of​

GenericSketcher.vLine

Inherited from​

BaseSketcher2d.vLine


vLineTo()​

vLineTo(yPos): this;

Defined in: packages/replicad/src/Sketcher2d.ts:164

Draws a vertical line to the y coordinate

Parameters​

yPos​

number

Returns​

this

Implementation of​

GenericSketcher.vLineTo

Inherited from​

BaseSketcher2d.vLineTo

Other​

close()​

close(): Drawing;

Defined in: packages/replicad/src/draw.ts:279

Stop drawing, make sure the sketch is closed (by adding a straight line to from the last point to the first) and returns the sketch.

Returns​

Drawing

Implementation of​

GenericSketcher.close


closeWithCustomCorner()​

closeWithCustomCorner(radius, mode?): Drawing;

Defined in: packages/replicad/src/draw.ts:294

Stop drawing, make sure the sketch is closed (by adding a straight line to from the last point to the first), change the corner between the last and the first segments and returns the sketch.

Parameters​

radius​

number

mode?​

"chamfer" | "fillet"

Returns​

Drawing


closeWithMirror()​

closeWithMirror(): Drawing;

Defined in: packages/replicad/src/draw.ts:284

Stop drawing, make sure the sketch is closed (by mirroring the lines between the first and last points drawn) and returns the sketch.

Returns​

Drawing

Implementation of​

GenericSketcher.closeWithMirror


customCorner()​

customCorner(radius, mode?): DrawingPen;

Defined in: packages/replicad/src/Sketcher2d.ts:512

Changes the corner between the previous and next segments.

Parameters​

radius​

number | ((first, second) => Curve2D[])

mode?​

"chamfer" | "fillet" | "dogbone"

Returns​

DrawingPen

Inherited from​

BaseSketcher2d.customCorner


done()​

done(): Drawing;

Defined in: packages/replicad/src/draw.ts:275

Stop drawing and returns the sketch.

Returns​

Drawing

Implementation of​

GenericSketcher.done


movePointerTo()​

movePointerTo(point): this;

Defined in: packages/replicad/src/Sketcher2d.ts:118

Changes the point to start your drawing from

Parameters​

point​

Point2D

Returns​

this

Implementation of​

GenericSketcher.movePointerTo

Inherited from​

BaseSketcher2d.movePointerTo