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

Copyright(c) 2013 diagrams-lib team (see LICENSE)
LicenseBSD-style (see LICENSE)
Maintainerdiagrams-discuss@googlegroups.com
Safe HaskellNone
LanguageHaskell2010

Diagrams.Angle

Contents

Description

Type for representing angles.

Synopsis

Angle type

data Angle n #

Angles can be expressed in a variety of units. Internally, they are represented in radians.

Instances

Functor Angle # 

Methods

fmap :: (a -> b) -> Angle a -> Angle b #

(<$) :: a -> Angle b -> Angle a #

Applicative Angle # 

Methods

pure :: a -> Angle a #

(<*>) :: Angle (a -> b) -> Angle a -> Angle b #

(*>) :: Angle a -> Angle b -> Angle b #

(<*) :: Angle a -> Angle b -> Angle a #

Additive Angle # 

Methods

zero :: Num a => Angle a #

(^+^) :: Num a => Angle a -> Angle a -> Angle a #

(^-^) :: Num a => Angle a -> Angle a -> Angle a #

lerp :: Num a => a -> Angle a -> Angle a -> Angle a #

liftU2 :: (a -> a -> a) -> Angle a -> Angle a -> Angle a #

liftI2 :: (a -> b -> c) -> Angle a -> Angle b -> Angle c #

Enum n => Enum (Angle n) # 

Methods

succ :: Angle n -> Angle n #

pred :: Angle n -> Angle n #

toEnum :: Int -> Angle n #

fromEnum :: Angle n -> Int #

enumFrom :: Angle n -> [Angle n] #

enumFromThen :: Angle n -> Angle n -> [Angle n] #

enumFromTo :: Angle n -> Angle n -> [Angle n] #

enumFromThenTo :: Angle n -> Angle n -> Angle n -> [Angle n] #

Eq n => Eq (Angle n) # 

Methods

(==) :: Angle n -> Angle n -> Bool #

(/=) :: Angle n -> Angle n -> Bool #

Ord n => Ord (Angle n) # 

Methods

compare :: Angle n -> Angle n -> Ordering #

(<) :: Angle n -> Angle n -> Bool #

(<=) :: Angle n -> Angle n -> Bool #

(>) :: Angle n -> Angle n -> Bool #

(>=) :: Angle n -> Angle n -> Bool #

max :: Angle n -> Angle n -> Angle n #

min :: Angle n -> Angle n -> Angle n #

Read n => Read (Angle n) # 
Show n => Show (Angle n) # 

Methods

showsPrec :: Int -> Angle n -> ShowS #

show :: Angle n -> String #

showList :: [Angle n] -> ShowS #

Num n => Semigroup (Angle n) # 

Methods

(<>) :: Angle n -> Angle n -> Angle n #

sconcat :: NonEmpty (Angle n) -> Angle n #

stimes :: Integral b => b -> Angle n -> Angle n #

Num n => Monoid (Angle n) # 

Methods

mempty :: Angle n #

mappend :: Angle n -> Angle n -> Angle n #

mconcat :: [Angle n] -> Angle n #

((~) (* -> *) (V t) V2, (~) * (N t) n, Transformable t, Floating n) => Action (Angle n) t #

Angles act on other things by rotation.

Methods

act :: Angle n -> t -> t #

type N (Angle n) # 
type N (Angle n) = n

Using angles

(@@) :: b -> AReview a b -> a infixl 5 #

30 @@ deg is an Angle of the given measure and units.

>>> pi @@ rad
3.141592653589793 @@ rad
>>> 1 @@ turn
6.283185307179586 @@ rad
>>> 30 @@ deg
0.5235987755982988 @@ rad

For Iso's, (@@) reverses the Iso' on its right, and applies the Iso' to the value on the left. Angles are the motivating example where this order improves readability.

This is the same as a flipped review.

(@@) :: a -> Iso'      s a -> s
(@@) :: a -> Prism'    s a -> s
(@@) :: a -> Review    s a -> s
(@@) :: a -> Equality' s a -> s

rad :: Iso' (Angle n) n #

The radian measure of an Angle a can be accessed as a ^. rad. A new Angle can be defined in radians as pi @@ rad.

turn :: Floating n => Iso' (Angle n) n #

The measure of an Angle a in full circles can be accessed as a ^. turn. A new Angle of one-half circle can be defined in as 1/2 @@ turn.

deg :: Floating n => Iso' (Angle n) n #

The degree measure of an Angle a can be accessed as a ^. deg. A new Angle can be defined in degrees as 180 @@ deg.

Common angles

fullTurn :: Floating v => Angle v #

An angle representing one full turn.

halfTurn :: Floating v => Angle v #

An angle representing a half turn.

quarterTurn :: Floating v => Angle v #

An angle representing a quarter turn.

Trigonometric functions

sinA :: Floating n => Angle n -> n #

The sine of the given Angle.

cosA :: Floating n => Angle n -> n #

The cosine of the given Angle.

tanA :: Floating n => Angle n -> n #

The tangent function of the given Angle.

asinA :: Floating n => n -> Angle n #

The Angle with the given sine.

acosA :: Floating n => n -> Angle n #

The Angle with the given cosine.

atanA :: Floating n => n -> Angle n #

The Angle with the given tangent.

atan2A :: RealFloat n => n -> n -> Angle n #

atan2A y x is the angle between the positive x-axis and the vector given by the coordinates (x, y). The Angle returned is in the [-pi,pi] range.

atan2A' :: OrderedField n => n -> n -> Angle n #

Similar to atan2A but without the RealFloat constraint. This means it doesn't handle negative zero cases. However, for most geometric purposes, the outcome will be the same.

Angle utilities

angleBetween :: (Metric v, Floating n, Ord n) => v n -> v n -> Angle n #

Compute the positive angle between the two vectors in their common plane in the [0,pi] range. For a signed angle see signedAngleBetween.

Returns NaN if either of the vectors are zero.

angleRatio :: Floating n => Angle n -> Angle n -> n #

Calculate ratio between two angles.

normalizeAngle :: (Floating n, Real n) => Angle n -> Angle n #

Normalize an angle so that it lies in the [0,tau) range.

Classes

class HasTheta t where #

The class of types with at least one angle coordinate, called _theta.

Methods

_theta :: RealFloat n => Lens' (t n) (Angle n) #

Instances

HasTheta v => HasTheta (Point v) # 

Methods

_theta :: RealFloat n => Lens' (Point v n) (Angle n) #

HasTheta v => HasTheta (Direction v) # 

Methods

_theta :: RealFloat n => Lens' (Direction v n) (Angle n) #

class HasTheta t => HasPhi t where #

The class of types with at least two angle coordinates, the second called _phi. _phi is the positive angle measured from the z axis.

Methods

_phi :: RealFloat n => Lens' (t n) (Angle n) #

Instances

HasPhi v => HasPhi (Point v) # 

Methods

_phi :: RealFloat n => Lens' (Point v n) (Angle n) #

HasPhi v => HasPhi (Direction v) # 

Methods

_phi :: RealFloat n => Lens' (Direction v n) (Angle n) #

Rotation

rotation :: Floating n => Angle n -> Transformation V2 n #

Create a transformation which performs a rotation about the local origin by the given angle. See also rotate.

rotate :: (InSpace V2 n t, Transformable t, Floating n) => Angle n -> t -> t #

Rotate about the local origin by the given angle. Positive angles correspond to counterclockwise rotation, negative to clockwise. The angle can be expressed using any of the Isos on Angle. For example, rotate (1/4 @@ turn), rotate (tau/4 @@ rad), and rotate (90 @@ deg) all represent the same transformation, namely, a counterclockwise rotation by a right angle. To rotate about some point other than the local origin, see rotateAbout.

Note that writing rotate (1/4), with no Angle constructor, will yield an error since GHC cannot figure out which sort of angle you want to use. In this common situation you can use rotateBy, which interprets its argument as a number of turns.