An ellipse is defined by a center point, X and Y radius, and X and Y axes (which will always be perpendicular to each other). Ellipses are symmetric about their X and Y axes. This module includes functionality for
Construct an ellipse from its center point, X direction, and X and Y radii. If you pass a negative radius, the absolute value will be used.
exampleEllipse =
Ellipse2d.with
{ centerPoint =
Point2d.fromCoordinates ( 10, 10 )
, xDirection =
Direction2d.fromAngle (degrees 30)
, xRadius = 5
, yRadius = 3
}Get the center point of an ellipse.
Ellipse2d.centerPoint exampleEllipse
--> Point2d.fromCoordinates ( 10, 10 )Get the X axis of an ellipse.
Ellipse2d.xAxis exampleEllipse
--> Axis2d.through
--> (Point2d.fromCoordinates ( 10, 10 ))
--> (Direction2d.fromAngle (degrees 30))Get the Y axis of an ellipse.
Ellipse2d.yAxis exampleEllipse
--> Axis2d.through
--> (Point2d.fromCoordinates ( 10, 10 ))
--> (Direction2d.fromAngle (degrees 120))Get the direction of the ellipse's X axis.
Ellipse2d.xDirection exampleEllipse
--> Direction2d.fromAngle (degrees 30)Get the direction of an ellipse's Y axis.
Ellipse2d.yDirection exampleEllipse
--> Direction2d.fromAngle (degrees 120)Get the X and Y axes of an ellipse as a Frame2d.
Ellipse2d.axes exampleEllipse
--> Frame2d.withXDirection
--> (Direction2d.fromAngle (degrees 30))
--> (Point2d.fromCoordinates ( 10, 10 ))Get the radius of an ellipse along its X axis. This may be either the minimum or maximum radius.
Ellipse2d.xRadius exampleEllipse
--> 5Get the radius of an ellipse along its Y axis. This may be either the minimum or maximum radius.
Ellipse2d.yRadius exampleEllipse
--> 3Get the area of an ellipse.
Ellipse2d.area exampleEllipse
--> 47.1239Scale an ellipse about a given point by a given scale.
exampleEllipse
|> Ellipse2d.scaleAbout Point2d.origin 3
--> Ellipse2d.with
--> { centerPoint =
--> Point2d.fromCoordinates ( 30, 30 )
--> , xDirection =
--> Direction2d.fromAngle (degrees 30)
--> , xRadius = 15
--> , yRadius = 9
--> }Rotate an ellipse around a given point by a given angle (in radians).
exampleEllipse
|> Ellipse2d.rotateAround Point2d.origin
(degrees 45)
--> Ellipse2d.with
--> { centerPoint =
--> Point2d.fromCoordinates ( 0, 14.142 )
--> , xDirection =
--> Direction2d.fromAngle (degrees 75)
--> , xRadius = 5
--> , yRadius = 3
--> }Translate an ellipse by a given displacement.
exampleEllipse
|> Ellipse2d.translateBy
(Vector2d.fromComponents ( 5, 10 ))
--> Ellipse2d.with
--> { centerPoint =
--> Point2d.fromCoordinates ( 15, 20 )
--> , xDirection =
--> Direction2d.fromAngle (degrees 30)
--> , xRadius = 5
--> , yRadius = 3
--> }Translate an ellipse in a given direction by a given distance;
Ellipse2d.translateIn direction distanceis equivalent to
Ellipse2d.translateBy
(Vector2d.withLength distance direction)Mirror an ellipse across a given axis.
mirroredEllipse =
Ellipse2d.mirrorAcross Axis2d.x exampleEllipse
Ellipse2d.centerPoint mirroredEllipse
--> Point2d.fromCoordinates ( 10, -10 )
Ellipse2d.xDirection mirroredEllipse
--> Direction2d.fromAngle (degrees -30)
Ellipse2d.yDirection mirroredEllipse
--> Direction2d.fromAngle (degrees -120)Note that if the axes of the original ellipse form a right-handed frame, then the axes of the mirrored ellipse will form a left-handed frame (and vice versa).
Take an ellipse defined in global coordinates, and return it expressed in local coordinates relative to a given reference frame.
localFrame =
Frame2d.atPoint (Point2d.fromCoordinates (15, 5))
Ellipse2d.relativeTo localFrame exampleEllipse
--> Ellipse2d.with
--> { centerPoint =
--> Point2d.fromCoordinates ( -5, 5 )
--> , xDirection =
--> Direction2d.fromAngle (degrees 30)
--> , xRadius = 5
--> , yRadius = 3
--> }Take an ellipse 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 (15, 5))
Ellipse2d.placeIn localFrame exampleEllipse
--> Ellipse2d.with
--> { centerPoint =
--> Point2d.fromCoordinates ( 25, 15 )
--> , xDirection =
--> Direction2d.fromAngle (degrees 30)
--> , xRadius = 5
--> , yRadius = 3
--> }