1.2 Angles
(require euclid/plane/angle) | package: euclid |
An angle is a measure of rotation. Angles can be measured in degrees, where a full rotation is 360 degrees, or radians, where a full rotation is 2π radians.
Because turning more than a full rotation leaves an object in the same orientation as if it had only fractionally rotated, angles of equivalent rotations are always normalized to the smallest nonnegative rotation. That is, (degrees 10) and (degrees 370) are equal? and cannot be distinguished.
Like numbers, angles can be either exact or inexact. The degrees and rotations constructors always return exact angles when given exact inputs. However, the radians constructor never returns exact angles, with the exception of (radians 0). Exactness primarily matters when using the trigonometric functions on angles such as angle-sin, which make an effort to produce exact results from exact angles when possible. For example, (angle-sin (degrees 30)) produces 1/2 whereas (sin (degrees->radians 30)) produces 0.49999999999999994.
The degrees constructor can also be used as a match expander. The pattern (degrees pat) matches any angle? whose measure in degrees matches pat.
(define (north? a) (match a [(degrees 90) #true] [_ #false]))
> (north? (degrees 90)) #t
> (north? (degrees 270)) #f
> (north? (rotations 1/4)) #t
The radians constructor can also be used as a match expander. The pattern (radians pat) matches any angle? whose measure in radians matches pat.
(define (small-acute-angle? a) (match a ; Note that 1 radian is a little less than 60 degrees. [(radians x) #:when (<= 0 x 1) #true] [_ #false]))
> (small-acute-angle? (radians 0)) #t
> (small-acute-angle? (radians 1/2)) #t
> (small-acute-angle? (degrees 50)) #t
> (small-acute-angle? (degrees 80)) #f
The rotations constructor can also be used as a match expander. The pattern (rotations pat) matches any angle? whose measure in fractions of a rotation matches pat.
(define (north? a) (match a [(rotations 1/4) #true] [_ #false]))
> (north? (rotations 1/4)) #t
> (north? (degrees 90)) #t
> (north? (degrees 270)) #f
procedure
(angle-degrees a) → (and/c (>=/c 0) (</c 360))
a : angle?
> (angle-degrees (degrees 20)) 20
> (angle-degrees (degrees 380)) 20
> (angle-degrees (rotations 1/4)) 90
> (angle-degrees (radians pi)) 180.0
> (angle-radians (radians pi)) 3.141592653589793
> (angle-radians (degrees 90)) 1.5707963267948966
> (angle-radians (rotations 1/4)) 1.5707963267948966
procedure
(angle-rotations a) → (and/c (>=/c 0) (</c 1))
a : angle?
> (angle-rotations (degrees 90)) 1/4
> (angle-rotations (rotations 1/4)) 1/4
> (angle-rotations (radians pi)) 0.5
1.2.1 Trigonometric Functions
> (angle-sin (degrees 30)) 1/2
> (angle-sin (degrees 45)) 0.7071067811865475
> (angle-sin (degrees 60)) 0.8660254037844386
> (angle-cos (degrees 30)) 0.8660254037844387
> (angle-cos (degrees 45)) 0.7071067811865475
> (angle-cos (degrees 60)) 1/2