A java PacMan game application for A.U.TH (data structures class)
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

77 lignes
1.8 KiB

  1. /**
  2. * @file Vector.java
  3. * @brief
  4. * File containing the Vector class, a helper class for the
  5. * vector based evaluation system
  6. *
  7. * @author Christos Choutouridis 8997 cchoutou@ece.auth.gr
  8. * @author Konstantina Tsechelidou 8445 konstsec@ece.auth.gr
  9. */
  10. package gr.auth.ee.dsproject.node;
  11. /**
  12. * @class Vector
  13. * @brief
  14. * A helper class to represent vectors in the Maze
  15. */
  16. public class Vector {
  17. public int x, y; // the coordinate alternative to vector representation
  18. /**
  19. * @brief the plain constructor makes a zero vector
  20. */
  21. public Vector () {
  22. x = y = 0;
  23. }
  24. /**
  25. * @brief
  26. * Makes a vector from x,y coordinates of two points in Maze
  27. * @param p1x Point 1 x coordinate
  28. * @param p1y Point 1 y coordinate
  29. * @param p2x Point 2 x coordinate
  30. * @param p2y Point 2 y coordinate
  31. */
  32. public Vector (int p1x, int p1y, int p2x, int p2y) {
  33. x = p2x - p1x;
  34. y = p2y - p1y;
  35. }
  36. /*
  37. * ========== setters =========
  38. */
  39. public int setX (int x) { return (this.x = x); } // set x
  40. public int setY (int y) { return (this.y = y); } // set y
  41. /**
  42. * @brief
  43. * The Euclidean norm of the vector
  44. * @return the norm
  45. */
  46. public double norm () {
  47. return Math.sqrt (x*x + y*y);
  48. }
  49. /**
  50. * @brief
  51. * The dot product of the vector with another vector
  52. * @param a The 2nd vector of the product
  53. * @return the dot product value
  54. */
  55. public double dot (Vector a) {
  56. return (a.x*this.x + a.y*this.y);
  57. }
  58. /**
  59. * @brief
  60. * A static version of dot product of 2 vectors
  61. * @param a Vector a
  62. * @param b Vector b
  63. * @return The dot product of a and b
  64. */
  65. public static double dot (Vector a, Vector b) {
  66. return (a.x*b.x + a.y*b.y);
  67. }
  68. }