diagrams-lib-0.4.0.1: Embedded domain-specific language for declarative graphics

Diagrams.TwoD.Polygons

Description

General API for creating various types of polygons.

Synopsis

Polygons

data PolyType Source

Method used to determine the vertices of a polygon.

Constructors

 forall a . Angle a => PolyPolar [a] [Double] A "polar" polygon. The first argument is a list of central angles from each vertex to the next. The second argument is a list of radii from the origin to each successive vertex. To construct an n-gon, use a list of n-1 angles and n radii. Extra angles or radii are ignored. Cyclic polygons (with all vertices lying on a circle) can be constructed using a second argument of `(repeat r)`. forall a . Angle a => PolySides [a] [Double] A polygon determined by the distance between successive vertices and the angles formed by each three successive vertices. In other words, a polygon specified by "turtle graphics": go straight ahead x1 units; turn by angle a1; go straght ahead x2 units; turn by angle a2; etc. The polygon will be centered at the centroid of its vertices. The first argument is a list of vertex angles, giving the angle at each vertex from the previous vertex to the next. The first angle in the list is the angle at the second vertex; the first edge always starts out heading in the positive y direction from the first vertex. The second argument is a list of distances between successive vertices. To construct an n-gon, use a list of n-2 angles and n-1 edge lengths. Extra angles or lengths are ignored. PolyRegular Int Double A regular polygon with the given number of sides (first argument) and the given radius (second argument).

Determine how a polygon should be oriented.

Constructors

 NoOrient No special orientation; the first vertex will be at (1,0). This is the default. OrientH Orient horizontally, so the bottommost edge is parallel to the x-axis. OrientV Orient vertically, so the leftmost edge is parallel to the y-axis. OrientTo R2 Orient so some edge is facing in the direction of, that is, perpendicular to, the given vector.

Options for specifying a polygon.

Constructors

 PolygonOpts FieldspolyType :: PolyTypeSpecification for the polygon's vertices. polyOrient :: PolyOrientationShould a rotation be applied to the polygon in order to orient it in a particular way? polyCenter :: P2Should a translation be applied to the polygon in order to place the center at a particular location?

Instances

 Default PolygonOpts The default polygon is a regular pentagon of radius 1, centered at the origin, aligned to the x-axis.

Generate the vertices of a polygon. See `PolygonOpts` for more information.

polygon :: (PathLike p, V p ~ R2) => PolygonOpts -> pSource

Generating polygon vertices

polyPolarVs :: Angle a => [a] -> [Double] -> [P2]Source

Generate the vertices of a polygon specified by polar data (central angles and radii). See `PolyPolar`.

polySidesVs :: Angle a => [a] -> [Double] -> [P2]Source

Generate the vertices of a polygon specified by side length and angles, with the origin placed at the centroid. See `PolySides`.

polySidesVs' :: Angle a => [a] -> [Double] -> [P2]Source

Generate the vertices of a polygon specified by side length and angles, with the origin corresponding to the first vertex. See `PolySides`.

polyRegularVs :: Int -> Double -> [P2]Source

Generate the vertices of a regular polygon. See `PolyRegular`.

orient :: R2 -> [P2] -> [P2]Source

Orient a list of points, rotating them as little as possible. The points are rotated so that the edge furthest in the direction of the given vector is perpendicular to it. (Note: this may do odd things to non-convex lists of points.)

Star polygons

data StarOpts Source

Options for creating "star" polygons, where the edges connect possibly non-adjacent vertices.

Constructors

 StarFun (Int -> Int) Specify the order in which the vertices should be connected by a function that maps each vertex index to the index of the vertex that should come next. Indexing of vertices begins at 0. StarSkip Int Specify a star polygon by a "skip". A skip of 1 indicates a normal polygon, where edges go between successive vertices. A skip of 2 means that edges will connect every second vertex, skipping one in between. Generally, a skip of n means that edges will connect every nth vertex.

star :: StarOpts -> [P2] -> Path R2Source

Create a generalized star polygon. The `StarOpts` are used to determine in which order the given vertices should be connected. The intention is that the second argument of type `[P2]` could be generated by a call to `polygon`, `regPoly`, or the like, since a list of vertices is `PathLike`. But of course the list can be generated any way you like. A `Path R2` is returned (instead of any `PathLike`) because the resulting path may have more than one component, for example if the vertices are to be connected in several disjoint cycles.

Function graphs

data GraphPart a Source

Pieces of a function graph can either be cycles or hairs.

Constructors

 Cycle [a] Hair [a]

Instances

 Functor GraphPart Show a => Show (GraphPart a)

mkGraph :: (Int -> Int) -> [a] -> [GraphPart a]Source

Generate a function graph from the given function and labels.

Utility

centroid :: [P2] -> P2Source

The centroid of a set of n points is the sum of vertices divided by n.