A Circle2d is defined by its center point and radius. This module includes
functionality for
The unit circle, centered on the origin with a radius of 1.
Circle2d.unit
--> Circle2d.with
--> { centerPoint = Point2d.origin
--> , radius = 1
--> }Construct a circle from its center point and radius:
exampleCircle =
Circle2d.with
{ centerPoint =
Point2d.fromCoordinates ( 1, 2 )
, radius = 3
}The actual radius of the circle will be the absolute value of the given radius
(passing radius = -2 will have the same effect as radius = 2).
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.with
--> { centerPoint =
--> Point2d.fromCoordinates ( 0.5, 0.5 )
--> , radius = 0.7071
--> }
--> )
Circle2d.throughPoints
( Point2d.origin
, Point2d.fromCoordinates ( 2, 1 )
, Point2d.fromCoordinates ( 4, 0 )
)
--> Just
--> (Circle2d.with
--> { centerPoint =
--> Point2d.fromCoordinates ( 2, -1.5 )
--> , radius = 2.5
--> }
--> )
Circle2d.throughPoints
( Point2d.origin
, Point2d.fromCoordinates ( 2, 0 )
, Point2d.fromCoordinates ( 4, 0 )
)
--> Nothing
Circle2d.throughPoints
( Point2d.origin
, Point2d.origin
, Point2d.fromCoordinates ( 1, 0 )
)
--> NothingGet the center point of a circle.
Circle2d.centerPoint exampleCircle
--> Point2d.fromCoordinates ( 1, 2 )Get the radius of a circle.
Circle2d.radius exampleCircle
--> 3Get the diameter of a circle.
Circle2d.diameter exampleCircle
--> 6Get the area of a circle.
Circle2d.area exampleCircle
--> 28.2743Get the circumference of a circle.
Circle2d.circumference exampleCircle
--> 18.8496Get the minimal bounding box containing a given circle.
Circle2d.boundingBox exampleCircle
--> BoundingBox2d.with
--> { minX = -2
--> , maxX = 4
--> , minY = -1
--> , maxY = 5
--> }Convert a circle to a 360 degree arc.
Circle2d.toArc exampleCircle
--> Arc2d.with
--> { centerPoint =
--> Point2d.fromCoordinates ( 1, 2 )
--> , startPoint =
--> Point2d.fromCoordinates ( 4, 2 )
--> , sweptAngle = degrees 360
--> }Check if a circle contains a given point.
Circle2d.contains Point2d.origin exampleCircle
--> True
exampleCircle
|> Circle2d.contains
(Point2d.fromCoordinates ( 10, 10 ))
--> FalseScale a circle about a given point by a given scale.
Circle2d.scaleAbout Point2d.origin 2 exampleCircle
--> Circle2d.with
--> { centerPoint =
--> Point2d.fromCoordinates ( 2, 4 )
--> , radius = 6
--> }
exampleCircle
|> Circle2d.scaleAbout
(Point2d.fromCoordinates ( 1, 2 ))
0.5
--> Circle2d.with
--> { centerPoint =
--> Point2d.fromCoordinates ( 1, 2 )
--> , radius = 1.5
--> }Rotate a circle around a given point by a given angle (in radians).
exampleCircle
|> Circle2d.rotateAround Point2d.origin
(degrees 90)
--> Circle2d.with
--> { centerPoint =
--> Point2d.fromCoordinates ( -2, 1 )
--> , radius = 3
--> }Translate a circle by a given displacement.
exampleCircle
|> Circle2d.translateBy
(Vector2d.fromComponents ( 2, 2 ))
--> Circle2d.with
--> { centerPoint =
--> Point2d.fromCoordinates ( 3, 4 )
--> , radius = 3
--> }Mirror a circle across a given axis.
Circle2d.mirrorAcross Axis2d.x exampleCircle
--> Circle2d.with
--> { centerPoint =
--> Point2d.fromCoordinates ( 1, -2 )
--> , radius = 3
--> }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.with
--> { centerPoint =
--> Point2d.fromCoordinates ( -1, -1 )
--> , radius = 3
--> }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.with
--> { centerPoint =
--> Point2d.fromCoordinates ( 3, 5 )
--> , radius = 3
--> }