On this page:
angle?
degrees
radians
rotations
angle-degrees
angle-radians
angle-rotations
1.2.1 Trigonometric Functions
angle-sin
angle-cos
angle-tan
8.12

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.

procedure

(angle? v)  boolean?

  v : any/c
A predicate for angles.

procedure

(degrees d)  angle?

  d : real?
Constructs the angle measuring d degrees.

Examples:
> (degrees 50)

50°

> (degrees -10)

350°

> (degrees 500)

140°

The degrees constructor can also be used as a match expander. The pattern (degrees pat) matches any angle? whose measure in degrees matches pat.

Examples:
(define (north? a)
  (match a
    [(degrees 90) #true]
    [_ #false]))

 

> (north? (degrees 90))

#t

> (north? (degrees 270))

#f

> (north? (rotations 1/4))

#t

procedure

(radians r)  angle?

  r : real?
Constructs the angle measuring r radians. Note that because the mathematical value of π cannot be represented exactly as a real?, angles constructed with radians may be less precise than expected.

Examples:
> (radians pi)

180.0°

> (radians (/ pi 4))

45.0°

The radians constructor can also be used as a match expander. The pattern (radians pat) matches any angle? whose measure in radians matches pat.

Examples:
(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

procedure

(rotations x)  angle?

  x : real?
Constructs the angle measuring x rotations.

Examples:
> (rotations 1/4)

90°

> (rotations 1/36)

10°

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.

Examples:
(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?
Converts a into degrees.

Examples:
> (angle-degrees (degrees 20))

20

> (angle-degrees (degrees 380))

20

> (angle-degrees (rotations 1/4))

90

> (angle-degrees (radians pi))

180.0

procedure

(angle-radians a)  (and/c (>=/c 0) (</c (* pi 2)))

  a : angle?
Converts a into radians.

Examples:
> (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?
Converts a into a fraction of a rotation.

Examples:

1.2.1 Trigonometric Functions🔗ℹ

procedure

(angle-sin a)  (real-in -1 1)

  a : angle?
Returns the sine of a. The result is exact when a is exact and when the sine of a is a rational number.

Examples:
> (angle-sin (degrees 30))

1/2

> (angle-sin (degrees 45))

0.7071067811865475

> (angle-sin (degrees 60))

0.8660254037844386

procedure

(angle-cos a)  (real-in -1 1)

  a : angle?
Returns the cosine of a. The result is exact when a is exact and when the cosine of a is a rational number.

Examples:
> (angle-cos (degrees 30))

0.8660254037844387

> (angle-cos (degrees 45))

0.7071067811865475

> (angle-cos (degrees 60))

1/2

procedure

(angle-tan a)  (and/c real? (not/c nan?))

  a : angle?
Returns the tangent of a. The result is exact when a is exact and when the tangent of a is either a rational number or infinity.

Examples:
> (angle-tan (degrees 30))

0.5773502691896257

> (angle-tan (degrees 45))

1

> (angle-tan (degrees 60))

1.7320508075688767

> (angle-tan (degrees 90))

+inf.0