Circle

Circle class provides static functions to create and operate on circles. A circle is usually represented as a Group of 2 Pts, where the first Pt specifies the center, and the second Pt specifies the radius. You can use the static functions as-is, or apply the Group.op or Pt.op to enable functional programming. See Op guide for details.

Class in src/Op.ts

Methods

STATIC fromCenter ( pt, radius )

Create a circle based on a center point and a radius.

parameters
pt: PtLike

center point of circle

radius: number

radius of circle

returns
Group

a Group that represents a circle

source

STATIC fromRect ( pts, enclose )

Create a circle that either fits within, or encloses, a rectangle.

parameters
pts: PtLikeIterable

a Group or an Iterable with 2 Pt representing a rectangle

enclose: boolean (default value: false)

if true, the circle will enclose the rectangle. Default is false, which will fit the circle inside the rectangle.

returns
Group

a Group that represents a circle

source

STATIC fromTriangle ( pts, enclose )

Create a circle that either fits within, or encloses, a triangle. Same as Triangle.circumcircle or Triangle.incircle.

parameters
pts: PtIterable

a Group or an Iterable with 3 Pt representing a rectangle

enclose: boolean (default value: false)

if true, the circle will enclose the triangle. Default is false, which will fit the circle inside the triangle.

returns
Group

a Group that represents a circle

source

STATIC intersectCircle2D ( circle1, circle2 )

Get the intersection points between two circles.

parameters
circle1: PtIterable

a Group or an Iterable with 2 Pt representing a circle

circle2: PtIterable

a Group or an Iterable with 2 Pt representing a circle

returns
Group

a Group of intersection points, or an empty Group if no intersection is found

source

STATIC intersectLine2D ( circle, line )

Get the intersection points between a circle and a line segment.

parameters
circle: PtIterable

a Group or an Iterable with Pt representing a circle

line: PtIterable

a Group or an Iterable with 2 Pt representing a line

returns
Group

a Group of intersection points, or an empty Group if no intersection is found

source

STATIC intersectRay2D ( circle, ray )

Get the intersection points between a circle and a ray (infinite line).

parameters
circle: PtIterable

a Group or an Iterable with 2 Pt representing a circle

ray: PtIterable

a Group or an Iterable with 2 Pt representing a ray

returns
Group

a Group of intersection points, or an empty Group if no intersection is found

source

STATIC intersectRect2D ( circle, rect )

Quick way to check rectangle intersection with a circle. For more optimized implementation, store the rectangle's sides separately (eg, Rectangle.sides) and use Polygon.intersectPolygon2D().

parameters
circle: PtIterable

a Group or an Iterable with 2 Pt representing a circle

rect: PtIterable

a Group or an Iterable with 2 Pt representing a rectangle

returns
Group

a Group of intersection points, or an empty Group if no intersection is found

source

STATIC toRect ( circle, within )

Get a rectangle that either fits within or encloses this circle. See also Rectangle.toCircle

parameters
circle: PtIterable

a Group or an Iterable with 2 Pt representing a circle

within: boolean (default value: false)

if true, the rectangle will be within the circle. If false, the rectangle will enclose the circle.

returns
Group

a Group representing a rectangle

source

STATIC toTriangle ( circle, within )

Get a triangle that fits within this circle.

parameters
circle: PtIterable

a Group or an Iterable with 2 Pt representing a circle

within: boolean (default value: true)

if true, the triangle will be within the circle. If false, the triangle will enclose the circle.

returns
Group

source

STATIC withinBound ( pts, pt, threshold )

Check if a point is within a circle.

parameters
pts: PtIterable

a Group or an Iterable with 2 Pt representing a circle

pt: PtLike

the point to checks

threshold: number (default value: 0)

an optional small number to set threshold. Default is 0.

returns
boolean

source