opensolid/geometry/1.2.0

NOTE: this package is not compatible with Elm 0.19.1

OpenSolid.Circle2d

Circle2d

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).

Predefined circles

unit : Circle2d

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

Circle2d.unit
--> Circle2d
-->     { centerPoint = Point2d.origin
-->     , radius = 1
-->     }

Constructors

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 ( 1, 0 ))
    (Point2d ( 0, 1 ))
--> Just
-->     (Circle2d
-->         { centerPoint = Point2d ( 0.5, 0.5 )
-->         , radius = 0.7071
-->         }
-->     )


Circle2d.throughPoints
    Point2d.origin
    (Point2d ( 2, 1 ))
    (Point2d ( 4, 0 ))
--> Just
-->     (Circle2d
-->         { centerPoint = Point2d ( 2, -1.5 )
-->         , radius = 2.5
-->         }
-->     )


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


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

Accessors

centerPoint : Circle2d -> Point2d

Get the center point of a circle.

Circle2d.centerPoint exampleCircle
--> Point2d ( 1, 2 )
radius : Circle2d -> Float

Get the radius of a circle.

Circle2d.radius exampleCircle
--> 3
diameter : Circle2d -> Float

Get the diameter of a circle.

Circle2d.diameter exampleCircle
--> 6
area : Circle2d -> Float

Get the area of a circle.

Circle2d.area exampleCircle
--> 28.2743
circumference : Circle2d -> Float

Get the circumference of a circle.

Circle2d.circumference exampleCircle
--> 18.8496

Queries

contains : Point2d -> Circle2d -> Bool

Check if a circle contains a given point.

Circle2d.contains Point2d.origin exampleCircle
--> True


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

Transformations

scaleAbout : Point2d -> Float -> Circle2d -> Circle2d

Scale 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
-->     }
rotateAround : Point2d -> Float -> Circle2d -> Circle2d

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
-->     }
translateBy : Vector2d -> Circle2d -> Circle2d

Translate a circle by a given displacement.

Circle2d.translateBy (Vector2d ( 2, 2 )) exampleCircle
--> Circle2d
-->     { centerPoint = Point2d ( 3, 4 )
-->     , radius = 3
-->     }
mirrorAcross : Axis2d -> Circle2d -> Circle2d

Mirror a circle across a given axis.

Circle2d.mirrorAcross Axis2d.x exampleCircle
--> Circle2d
-->     { centerPoint = Point2d ( 1, -2 )
-->     , radius = 3
-->     }

Coordinate frames

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.at (Point2d ( 2, 3 ))


Circle2d.relativeTo localFrame exampleCircle
--> Circle2d
-->     { centerPoint = Point2d ( -1, -1 )
-->     , radius = 3
-->     }
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.at (Point2d ( 2, 3 ))


Circle2d.placeIn localFrame exampleCircle
--> Circle2d
-->     { centerPoint = Point2d ( 3, 5 )
-->     , radius = 3
-->     }

Sketch planes

placeOnto : SketchPlane3d -> Circle2d -> Circle3d

Take a circle defined in 2D coordinates within a particular sketch plane and return the corresponding circle in 3D.

Circle2d.placeOnto SketchPlane3d.yz exampleCircle
--> Circle3d
-->     { centerPoint = Point3d ( 0, 1, 2 )
-->     , axialDirection = Direction3d.x
-->     , radius = 3
-->     }

Bounds

boundingBox : Circle2d -> BoundingBox2d

Get the minimal bounding box containing a given circle.

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