Geometry
1 Vector
vec
vec-x
vec-y
vec-add
vec-sub
vec-scale
rotate
polar
angle-of
mag
dist
2 Line Like
line-pp
line-pa
ray-pa
line-segment-pp
angle-of-ll
ll-p1
ll-p2
8.1

Geometry

 (require "../../racket/ctf/vector.rkt") package: base

Note: if you are using this code, it is assumed you will be working in (radians-mode)

1 Vector

To use vectors, make sure to put (require "../../racket/ctf/vector.rkt") at the top of your file.

procedure

(vec x y)  vec?

  x : number?
  y : number?

procedure

(vec-x vec)  number?

  vec : vec?

procedure

(vec-y vec)  number?

  vec : vec?

(vec x y) will return a value with the given x and y stored in it. You can then get out those values using vec-x and vec-y. For example (vec-y (vec 1 2.5)) returns 2.5.

procedure

(vec-add vec1 vec2)  vec?

  vec1 : vec?
  vec2 : vec?
Returns a new vector which is the sum vec1 and vec2

procedure

(vec-sub vec1 vec2)  vec?

  vec1 : vec?
  vec2 : vec?
Returns a new vector which is vec1 minus v2

procedure

(vec-scale vec c)  vec?

  vec : vec?
  c : number?
Returns a new vector which is vec1 scaled the c

procedure

(rotate vec angle)  vec?

  vec : vec?
  angle : number?
Returns a new vector that is vec rotated angle radians to the right

procedure

(polar r angle)  vec?

  r : number?
  angle : number?
Returns a vector whose magnitude is r and whose angle with the positive x-axis is angle

procedure

(angle-of vec)  number?

  vec : vec?
Returns the angle that vec makes with the positive x-axis

procedure

(mag vec)  number?

  vec : vec?
Returns the magnitude of vec

procedure

(dist vec1 vec2)  number?

  vec1 : vec?
  vec2 : vec?
Returns the distance between vec1 and vec2

2 Line Like

To use line like, make sure to put (require "../../racket/ctf/ll.rkt") at the top of your file.

A "line like" (not a real term) is any shape that is a subset of a single line. The three that we are dealing with are: - Lines - Rays - Line Segments When we say line like, or ll, we are referring to any one of these 3 shapes.

procedure

(line-pp p1 p2)  ll?

  p1 : vec?
  p2 : vec?
Returns a line like that is treated as the line that goes through p1 and p2

procedure

(line-pa p angle)  ll?

  p : vec?
  angle : number?
Returns a line like that is treated as the line that starts at p, and travels in the direction of the given angle

procedure

(ray-pa p angle)  ll?

  p : vec?
  angle : number?
Returns a line like that is treated as the ray that starts at p, and travels in the direction of the given angle

procedure

(line-segment-pp p1 p2)  ll?

  p1 : vec?
  p2 : vec?
Returns a line like that is treated as the line segment with ends at p1 and p2

procedure

(angle-of-ll ll)  number?

  ll : ll?
Returns the angle above or below the positive x-axis of the line. The value of angle-of-ll will always be in [-90,90)

procedure

(ll-p1 ll)  vec?

  ll : ll?
Returns one point on the line like. If it’s a line segment or a ray it will be one of its end points.

procedure

(ll-p2 ll)  vec?

  ll : ll?
Same as ll-p1 except