Gameplay in HTML5: Homework #3

Vectors

  1. Let u = [ -1, 3 ], v = [ 7, 2 ], w = [ 5, 0 ], e = [ 1, 0 ], and f = [ 0, 1 ].
    1. What is ux?
    2. What is vy?
    3. What is w1?
    4. Compute |u|.
    5. Compute |v|.
    6. Compute |w|.
    7. Compute |e|.
    8. Compute 3u.
    9. Compute 0v.
    10. Compute -3u.
    11. What is -v?
    12. Compute w/2.
    13. Compute v/0.
    14. What do you get when you normalize u?
    15. What do you get when you normalize w?
    16. Compute u + v.
    17. Compute v + w.
    18. Compute v + u.
    19. Compute 3(u + v).
    20. Compute 3u + 3v.
    21. Compute (2 + 1)u.
    22. Compute 2u + 1u.
    23. Compute 3e + 5f.
    24. Compute u - v.
    25. Compute v - u.
    26. Compute u·v.
    27. Compute v·w.
    28. Compute v·u.
    29. Compute 3(u·v).
    30. Compute (3uv.
    31. Compute u·(3v).
    32. Compute u·u. Compare this to |u|.
    33. Compute e·u. Compare this to ux.
    34. Compute f·u. Compare this to uy.
    35. Compute e·v. Compare this to vx.
    36. Compute f·v. Compare this to vy.
    37. Compute the angle between u and v. What type of angle is it?
    38. Compute the angle between v and w. What type of angle is it?
    39. Compute the angle between e and w. What type of angle is it?
    40. Compute the angle between f and w. What type of angle is it?
  2. Create a JavaScript library for vector mathematics. Call it Vector.js and declare an object called, say, app.vector, which will have methods for vector operations. Let's represent vectors themselves as objects with properties x and y, so the vector v = [ 3, -7.5 ] is declared as var v = { x: 3, y: -7.5 }.
    1. Define vector.add as a function( vec1, vec2 ) that returns vec1 + vec2.
    2. Define vector.subtract.
    3. Define vector.scalarMul.
    4. Define vector.length.
    5. Define vector.normalize.
    6. Define vector.distance.
    7. Define vector.dot.
    8. Add this function:
      app.vector.perp = function( vec )
      {
          return {
              x: -vec.y,
              y: vec.x
          };
      };
                  
      What does it do? (Hint: What is the angle between v and perp(v)? Try plotting a few examples on graph paper.)
  3. You may submit your answers to the first part, plus the last question, on paper at class, or as a Web page or text, PDF, AbiWord, LibreOffice, or MS Word document.
  4. Archive your file. E.g.:
    tar -czvf Gameplay_3_MyName.tgz Vector.js
    (Please do not include jquery.js or modernizr.js files in the archive. Links are OK.)
    E-mail the archive to the instructor.