On this page:
point
origin
point-add
point-sum
into-point-sum
point-distance
1.1.1 2D Polar Coordinates
polar-point
polar-point-radius
polar-point-azimuth
8.12

1.1 2D Points🔗ℹ

 (require euclid/plane/point) package: euclid

A 2D point is an exact location in the Euclidean plane, and has no length, width, or thickness.

struct

(struct point (x y)
    #:transparent)
  x : (and/c real? (not/c infinite?) (not/c nan?))
  y : (and/c real? (not/c infinite?) (not/c nan?))
A 2D point structure with coordinates x and y.

value

origin : point? = (point 0 0)

The origin, which is the point located at coordinates (0,0).

procedure

(point-add p ...)  point?

  p : point?
Adds each p together and returns a point representing their sum.

Example:
> (point-add (point 2 3) (point 1 5))

(3,8)

procedure

(point-sum points)  point?

  points : (sequence/c point?)
Returns the sum of points.

Example:
> (point-sum (list (point 1 1) (point 2 2) (point 3 3)))

(6,6)

A reducer that adds together a sequence of points.

Example:
> (transduce (in-range 0 5)
             (mapping (λ (x) (point x 0)))
             #:into into-point-sum)

(10,0)

procedure

(point-distance p q)  (and/c (>=/c 0) (not/c infinite?))

  p : point?
  q : point?
Returns the distance between p and q.

Example:
> (point-distance (point 1 1) (point 4 5))

5

1.1.1 2D Polar Coordinates🔗ℹ

procedure

(polar-point radius azimuth)  point?

  radius : (and/c (>=/c 0) (not/c infinite?))
  azimuth : angle?
Constructs a point represented by the polar coordinates radius and azimuth, where radius is the point’s distance from the origin and azimuth is the angle of direction from the origin.

Examples:
> (polar-point 6 (degrees 0))

(6,0)

> (polar-point 6 (degrees 30))

(5.196152422706632,3)

> (polar-point 6 (degrees 45))

(4.242640687119285,4.242640687119285)

> (polar-point 6 (degrees 60))

(3,5.196152422706632)

> (polar-point 6 (degrees 90))

(0,6)

procedure

(polar-point-radius p)  (and/c (>=/c 0) (not/c infinite?))

  p : point?
Returns the distance from the origin to p.

Examples:
> (polar-point-radius (point 3 4))

5

> (polar-point-radius (point 10 0))

10

procedure

(polar-point-azimuth p)  angle?

  p : point?
Returns the angle of direction from the origin to p. If p is the origin, then an angle of zero degrees is returned.

Examples:
> (polar-point-azimuth (point 5 0))

> (polar-point-azimuth (point 5 5))

45°

> (polar-point-azimuth (point 0 5))

90°