A Circle2d is defined by its center point and radius. Currently you can only
do a few basic things with circles, such as measuring the area or checking if a
particular point is contained, but this should increase in the future.
Circles can be constructed by passing a record with centerPoint and radius
fields to the Circle2d constructor, for example
exampleCircle =
Circle2d
{ centerPoint = Point2d ( 1, 2 )
, radius = 3
}You must ensure the provided radius is positive (or zero, but that's not a very useful circle).
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.8496Check if a circle contains a given point.
Circle2d.contains Point2d.origin exampleCircle
--> True
Circle2d.contains (Point2d ( 10, 10 )) exampleCircle
--> FalseScale a circle about a given point by a given scale.
Circle2d.scaleAbout Point2d.origin 2 exampleCircle
--> Circle2d
--> { centerPoint = Point2d ( 2, 4 )
--> , radius = 6
--> }
Circle2d.scaleAbout (Point2d ( 1, 2 )) 0.5 exampleCircle
--> Circle2d
--> { centerPoint = Point2d ( 1, 2 )
--> , radius = 1.5
--> }Rotate a circle around a given point by a given angle (in radians).
Circle2d.rotateAround Point2d.origin (degrees 90) exampleCircle
--> Circle2d
--> { centerPoint = Point2d ( -2, 1 )
--> , radius = 3
--> }Translate a circle by a given displacement.
Circle2d.translateBy (Vector2d ( 2, 2 )) exampleCircle
--> Circle2d
--> { centerPoint = Point2d ( 3, 4 )
--> , radius = 3
--> }Mirror a circle across a given axis.
Circle2d.mirrorAcross Axis2d.x exampleCircle
--> Circle2d
--> { centerPoint = Point2d ( 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.at (Point2d ( 2, 3 ))
Circle2d.relativeTo localFrame exampleCircle
--> Circle2d
--> { centerPoint = Point2d ( -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.at (Point2d ( 2, 3 ))
Circle2d.placeIn localFrame exampleCircle
--> Circle2d
--> { centerPoint = Point2d ( 3, 5 )
--> , radius = 3
--> }Get the minimal bounding box containing a given circle.
Circle2d.boundingBox exampleCircle
--> BoundingBox2d
--> { minX = -2
--> , maxX = 4
--> , minY = -1
--> , maxY = 5
--> }
Get the center point of a circle.