ianmackenzie / elm-geometry-prerelease / Circle2d

A Circle2d is defined by its center point and radius. This module includes functionality for


type alias Circle2d =
Geometry.Types.Circle2d

Constants

unit : Circle2d

The unit circle, centered on the origin with a radius of 1.

Circle2d.unit
--> Circle2d.withRadius 1 Point2d.origin

Constructors

withRadius : Basics.Float -> Point2d -> Circle2d

Construct a circle from its radius and center point:

exampleCircle =
    Circle2d.withRadius 3
        (Point2d.fromCoordinates ( 1, 2 ))

If you pass a negative radius, the absolute value will be used.

throughPoints : Point2d -> Point2d -> Point2d -> Maybe Circle2d

Attempt to construct a circle that passes through the three given points. If the three given points are collinear, returns Nothing.

Circle2d.throughPoints
    Point2d.origin
    (Point2d.fromCoordinates ( 1, 0 ))
    (Point2d.fromCoordinates ( 0, 1 ))
--> Just
-->     (Circle2d.withRadius 0.7071
-->         (Point2d.fromCoordinates ( 0.5, 0.5 ))
-->     )

Circle2d.throughPoints
    Point2d.origin
    (Point2d.fromCoordinates ( 2, 1 ))
    (Point2d.fromCoordinates ( 4, 0 ))
--> Just
-->     (Circle2d.withRadius 2.5
-->         (Point2d.fromCoordinates ( 2, -1.5 ))
-->     )

Circle2d.throughPoints
    Point2d.origin
    (Point2d.fromCoordinates ( 2, 0 ))
    (Point2d.fromCoordinates ( 4, 0 ))
--> Nothing

Circle2d.throughPoints
    Point2d.origin
    Point2d.origin
    (Point2d.fromCoordinates ( 1, 0 ))
--> Nothing

sweptAround : Point2d -> Point2d -> Circle2d

Construct a circle by rotating a point on the circle around a given center point. The center point is given first and the point on the circle is given second.

Circle2d.sweptAround Point2d.origin
    (Point2d.fromCoordinates ( 2, 0 ))
--> Circle2d.withRadius 2 Point2d.origin

The above example could be rewritten as

Point2d.fromCoordinates ( 2, 0 )
    |> Circle2d.sweptAround Point2d.origin

and if you wanted to create many concentric circles all centered on the origin but passing through several other different points, you could use something like

concentricCircles =
    points
        |> List.map
            (Circle2d.sweptAround Point2d.origin)

Properties

centerPoint : Circle2d -> Point2d

Get the center point of a circle.

Circle2d.centerPoint exampleCircle
--> Point2d.fromCoordinates ( 1, 2 )

radius : Circle2d -> Basics.Float

Get the radius of a circle.

Circle2d.radius exampleCircle
--> 3

diameter : Circle2d -> Basics.Float

Get the diameter of a circle.

Circle2d.diameter exampleCircle
--> 6

area : Circle2d -> Basics.Float

Get the area of a circle.

Circle2d.area exampleCircle
--> 28.2743

circumference : Circle2d -> Basics.Float

Get the circumference of a circle.

Circle2d.circumference exampleCircle
--> 18.8496

boundingBox : Circle2d -> BoundingBox2d

Get the minimal bounding box containing a given circle.

Circle2d.boundingBox exampleCircle
--> BoundingBox2d.fromExtrema
-->     { minX = -2
-->     , maxX = 4
-->     , minY = -1
-->     , maxY = 5
-->     }

Conversion

toArc : Circle2d -> Geometry.Types.Arc2d

Convert a circle to a 360 degree arc.

Circle2d.toArc exampleCircle
--> Point2d.fromCoordinates ( 4, 2 )
-->     |> Arc2d.sweptAround
-->         (Point2d.fromCoordinates ( 1, 2 ))
-->         (degrees 360)

Queries

contains : Point2d -> Circle2d -> Basics.Bool

Check if a circle contains a given point.

Circle2d.contains Point2d.origin exampleCircle
--> True

exampleCircle
    |> Circle2d.contains
        (Point2d.fromCoordinates ( 10, 10 ))
--> False

Transformations

scaleAbout : Point2d -> Basics.Float -> Circle2d -> Circle2d

Scale a circle about a given point by a given scale.

Circle2d.scaleAbout Point2d.origin 2 exampleCircle
--> Circle2d.withRadius 6
-->     (Point2d.fromCoordinates ( 2, 4 ))

exampleCircle
    |> Circle2d.scaleAbout
        (Point2d.fromCoordinates ( 1, 2 ))
        0.5
--> Circle2d.withRadius 1.5
-->     (Point2d.fromCoordinates ( 1, 2 ))

rotateAround : Point2d -> Basics.Float -> Circle2d -> Circle2d

Rotate a circle around a given point by a given angle (in radians).

exampleCircle
    |> Circle2d.rotateAround Point2d.origin
        (degrees 90)
--> Circle2d.withRadius 3
-->     (Point2d.fromCoordinates ( -2, 1 ))

translateBy : Vector2d -> Circle2d -> Circle2d

Translate a circle by a given displacement.

exampleCircle
    |> Circle2d.translateBy
        (Vector2d.fromComponents ( 2, 2 ))
--> Circle2d.withRadius 3
-->     (Point2d.fromCoordinates ( 3, 4 ))

translateIn : Direction2d -> Basics.Float -> Circle2d -> Circle2d

Translate a circle in a given direction by a given distance;

Circle2d.translateIn direction distance

is equivalent to

Circle2d.translateBy
    (Vector2d.withLength distance direction)

mirrorAcross : Axis2d -> Circle2d -> Circle2d

Mirror a circle across a given axis.

Circle2d.mirrorAcross Axis2d.x exampleCircle
--> Circle2d.withRadius 3
-->     (Point2d.fromCoordinates ( 1, -2 ))

Coordinate conversions

relativeTo : Frame2d -> Circle2d -> Circle2d

Take a circle defined in global coordinates, and return it expressed in local coordinates relative to a given reference frame.

localFrame =
    Frame2d.atPoint (Point2d.fromCoordinates ( 2, 3 ))

Circle2d.relativeTo localFrame exampleCircle
--> Circle2d.withRadius 3
-->     (Point2d.fromCoordinates ( -1, -1 ))

placeIn : Frame2d -> Circle2d -> Circle2d

Take a circle considered to be defined in local coordinates relative to a given reference frame, and return that circle expressed in global coordinates.

localFrame =
    Frame2d.atPoint (Point2d.fromCoordinates ( 2, 3 ))

Circle2d.placeIn localFrame exampleCircle
--> Circle2d.withRadius 3
-->     (Point2d.fromCoordinates ( 3, 5 ))