Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Circle

A circle is defined by a center point and a radius. A circle also has an orientation (defined by a plane). The orientation is important as it controls where the circle's outer edge starts/ends, which is used in methods like pointAt, to generate points on the circle's edge.

Example

import { Circle, Point } from 'shapetypes';

// Create a new circle
const circle = new Circle(10, new Point(3,4));

// Get properties of the circle
console.log(circle.center.toString());
// => (3,4)
console.log(circle.area);
// => 314.16

// Scale the circle
const larger = circle.scale(2);
console.log(larger.radius);
// => 20

Hierarchy

Index

Constructors

constructor

  • new Circle(radius: number): Circle
  • new Circle(radius: number, position: Point): Circle
  • new Circle(radius: number, position: Plane): Circle

Accessors

area

  • get area(): number

boundingBox

center

circumference

  • get circumference(): number

diameter

  • get diameter(): number

plane

  • Gets the plane defining the circle's position. The plane's origin is the center of the circle. The plane's x-axis is the orientation of the circle.

    Returns Plane

radius

  • get radius(): number

Create Methods

Static fromCenterStart

  • Creates a circle defined by a center point and a point on the edge. The circle will be orientated so pointAt begins at the edge point.

    Parameters

    • center: Point

      The center of the circle.

    • start: Point

      A point on the edge of the circle.

    Returns Circle

Static fromThreePoints

  • Creates a circle that passes through the three points.

    note

    Throws an error if the three points are in a straight line.

    Parameters

    • p1: Point

      The first point to pass through. The circle will be orientated so pointAt begins at this point.

    • p2: Point

      The second point to pass through.

    • p3: Point

      The third point to pass through.

    Returns Circle

Other Methods

closestParameter

  • closestParameter(testPoint: Point): number
  • Finds the closest point on the circle and returns the parameter for the point.

    Parameters

    • testPoint: Point

      The target to get closest to.

    Returns number

    The parameter of the closest point. Entering the parameter into pointAt will return the closest point.

closestPoint

  • closestPoint(testPoint: Point, includeInterior?: boolean): Point
  • Finds the closest point on the circle and returns the point.

    Parameters

    • testPoint: Point

      Target to get closest to.

    • Default value includeInterior: boolean = false

      If false, the closest point must lie on the outer edge of the circle. If true, the closest point can also be a point on the interior of the circle.

    Returns Point

contains

  • Checks whether a point is inside, outside, or on the edge of a circle.

    Parameters

    • testPoint: Point

      The point to test for containment.

    • Default value tolerance: number = shapetypesSettings.absoluteTolerance

      The distance the point can be from the edge of the circle and still considered coincident.

    Returns PointContainment

equals

  • equals(otherCircle: Circle, tolerance?: number): boolean
  • Checks whether another circle has the same plane and radius. Returns true if it does.

    Parameters

    • otherCircle: Circle

      The circle to compare against.

    • Default value tolerance: number = shapetypesSettings.absoluteTolerance

      The amount the radius and plane can differ and still be considered equal.

    Returns boolean

pointAt

  • pointAt(t: number): Point
  • Finds the point a certain number of radians from the start. Returns the point.

    Parameters

    • t: number

      Position of the point (in radians). This is measured counter-clockwise from the start of the circle.

    Returns Point

pointAtLength

  • pointAtLength(distance: number): Point
  • Finds the point a certain distance from the start. Returns the point.

    Parameters

    • distance: number

      Position of the point. This is measured counter-clockwise from the start of the circle.

    Returns Point

tangentAt

  • tangentAt(t: number): Vector
  • Finds the tangent for the circle a certain number of radians from the start.

    Parameters

    • t: number

      Position of the tangent (in radians). This is measured counter-clockwise from the start of the circle.

    Returns Vector

toString

  • toString(): string
  • Gets the circle as a string in the format: [plane,radius].

    Returns string

withArea

  • withArea(newArea: number): Circle
  • Creates a copy of the circle with a different area. The circle will be in the same position but have a different radius.

    Parameters

    • newArea: number

      The area of the new circle.

    Returns Circle

withCenter

  • Creates a copy of the circle with a different center. The circle will be the same size and have the same orientation but will be translated to the new center.

    Parameters

    • newCenter: Point

      The center of the new circle.

    Returns Circle

withCircumference

  • withCircumference(newCircumference: number): Circle
  • Creates a copy of the circle with a different circumference. The circle will be in the same position but have a different radius.

    Parameters

    • newCircumference: number

      The circumference of the new circle.

    Returns Circle

withDiameter

  • withDiameter(newDiameter: number): Circle
  • Creates a copy of the circle with a different diameter. The circle will be in the same position but have a different radius/diameter.

    Parameters

    • newDiameter: number

      The diameter of the new circle.

    Returns Circle

withPlane

  • Creates a copy of the circle with a different plane. The circle will be the same size but centered on the new plane.

    Parameters

    • newPlane: Plane

      The plane of the new circle.

    Returns Circle

withRadius

  • withRadius(newRadius: number): Circle
  • Creates a copy of the circle with a different radius.

    Parameters

    • newRadius: number

      The radius of the new circle.

    Returns Circle

Transform Methods

changeBasis

  • changeBasis(planeFrom: Plane, planeTo: Plane): this
  • Translates the geometry from one coordinate system to another while keeping the geometry in the same position. In other words, if the geometry is currently described relative to planeFrom, after changeBasis, it will be in the same position but described relative to planeTo.

    see

    Transform.changeBasis.

    Parameters

    • planeFrom: Plane

      The coordinate system the geometry is currently described relative to.

    • planeTo: Plane

      The coordinate system to describe the geometry relative to.

    Returns this

    The geometry in the new coordinate system.

planeToPlane

  • planeToPlane(planeFrom: Plane, planeTo: Plane): this

rotate

  • rotate(angle: number): this
  • rotate(angle: number, pivot: Point): this
  • Rotates the geometry about (0,0).

    see

    Transform.rotate.

    Parameters

    • angle: number

      Angle to rotate the geometry (in radians). The direction is counter-clockwise.

    Returns this

  • Rotates the geometry about a point.

    see

    Transform.rotate.

    category

    Transform

    Parameters

    • angle: number

      Angle to rotate the geometry (in radians). If the environment's y-axis points upwards, the direction is counter-clockwise.

    • pivot: Point

      Point to pivot the geometry about.

    Returns this

scale

  • scale(amount: number): this
  • scale(x: number, y: number): this
  • scale(x: number, y: number, center: Point): this
  • Scales the geometry and returns the resized geometry. The geometry will be scaled about (0,0), meaning everything will shrink or expand away from this point.

    see

    Transform.scale.

    Parameters

    • amount: number

      Magnitude to scale in x- and y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.

    Returns this

  • Scales the geometry and returns the resized geometry. The geometry will be scaled about (0,0), meaning everything will shrink or expand away from this point.

    see

    Transform.scale.

    category

    Transform

    Parameters

    • x: number

      Magnitude to scale in x-direction. If less than 1, the object will shrink. If greater than 1, it will grow.

    • y: number

      Magnitude to scale in y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.

    Returns this

  • Scales the geometry about a point and returns the resized geometry.

    see

    Transform.scale.

    category

    Transform

    Parameters

    • x: number

      Magnitude to scale in x-direction. If less than 1, the object will shrink. If greater than 1, it will grow.

    • y: number

      Magnitude to scale in y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.

    • center: Point

      Center of scaling. Everything will shrink or expand away from this point.

    Returns this

transform

  • Transforms the circle by a transform matrix and returns the result.

    Example

    import { Circle, Transform } from 'shapetypes';
    
    // Create circle
    const circle = new Circle(10);
    console.log(circle.radius);
    // => 10
    
    // Scale using a transform matrix
    const matrix = Transform.scale(2);
    const scaled = scale.transform(matrix);
    console.log(scaled.radius);
    // => 20
    
    // Scale using the direct method
    const otherScaled = circle.scale(2);
    console.log(otherScaled.radius);
    // => 20
    note

    If you're applying the same transformation a lot of geometry, creating the Transform matrix once and calling this function is faster than using the direct methods.

    Parameters

    Returns this

translate

  • translate(move: Vector): this
  • translate(move: Vector, distance: number | undefined): this
  • Moves the geometry along a vector and returns the moved geometry. The translation is always linear.

    see

    Transform.translate.

    Parameters

    • move: Vector

      The direction and distance to move the geometry.

    Returns this

  • Moves the geometry along a vector and returns the moved geometry. The translation is always linear.

    see

    Transform.translate.

    category

    Transform

    Parameters

    • move: Vector

      The direction to move the geometry.

    • distance: number | undefined

      The distance to move the geometry.

    Returns this

Generated using TypeDoc