Skip to content

Latest commit

 

History

History
30 lines (23 loc) · 1.3 KB

w2_4.1_points_and_vectors.md

File metadata and controls

30 lines (23 loc) · 1.3 KB

POINTS AND VECTORS (30 points possible)

The given prelude defines three types, one for three dimensional points, another for velocity vectors in three dimensions, and another one representing moving objects in space.

  1. Write a function move : point -> dpoint -> point such that move p dp is the point p whose coordinates have been updated according to dp. (x is now x +. dx, y is now y +. dy, z is now z +. dz).

  2. Write a function next : physical_object -> physical_object such that next o is the physical object o at time t + dt. The position of next o is the position of o moved according to its velocity vector. Suppose that these objects are spheres whose radius is 1.0.

  3. Write a function will_collide_soon : physical_object -> physical_object -> bool that tells if at the next instant, the two spheres will intersect.

THE GIVEN PRELUDE

type point  = { x : float; y : float; z : float }
type dpoint = { dx : float; dy : float; dz : float }
type physical_object = { position : point; velocity : dpoint }

YOUR OCAML ENVIRONMENT

let move p dp =
  "Replace this string with your implementation." ;;

let next obj =
  "Replace this string with your implementation." ;;

let will_collide_soon p1 p2 =
  "Replace this string with your implementation." ;;