77 lines
1.8 KiB
Java
Executable File
77 lines
1.8 KiB
Java
Executable File
/**
|
|
* @file Vector.java
|
|
* @brief
|
|
* File containing the Vector class, a helper class for the
|
|
* vector based evaluation system
|
|
*
|
|
* @author Christos Choutouridis 8997 cchoutou@ece.auth.gr
|
|
* @author Konstantina Tsechelidou 8445 konstsec@ece.auth.gr
|
|
*/
|
|
|
|
package gr.auth.ee.dsproject.node;
|
|
|
|
/**
|
|
* @class Vector
|
|
* @brief
|
|
* A helper class to represent vectors in the Maze
|
|
*/
|
|
public class Vector {
|
|
public int x, y; // the coordinate alternative to vector representation
|
|
|
|
/**
|
|
* @brief the plain constructor makes a zero vector
|
|
*/
|
|
public Vector () {
|
|
x = y = 0;
|
|
}
|
|
|
|
/**
|
|
* @brief
|
|
* Makes a vector from x,y coordinates of two points in Maze
|
|
* @param p1x Point 1 x coordinate
|
|
* @param p1y Point 1 y coordinate
|
|
* @param p2x Point 2 x coordinate
|
|
* @param p2y Point 2 y coordinate
|
|
*/
|
|
public Vector (int p1x, int p1y, int p2x, int p2y) {
|
|
x = p2x - p1x;
|
|
y = p2y - p1y;
|
|
}
|
|
|
|
/*
|
|
* ========== setters =========
|
|
*/
|
|
public int setX (int x) { return (this.x = x); } // set x
|
|
public int setY (int y) { return (this.y = y); } // set y
|
|
|
|
/**
|
|
* @brief
|
|
* The Euclidean norm of the vector
|
|
* @return the norm
|
|
*/
|
|
public double norm () {
|
|
return Math.sqrt (x*x + y*y);
|
|
}
|
|
|
|
/**
|
|
* @brief
|
|
* The dot product of the vector with another vector
|
|
* @param a The 2nd vector of the product
|
|
* @return the dot product value
|
|
*/
|
|
public double dot (Vector a) {
|
|
return (a.x*this.x + a.y*this.y);
|
|
}
|
|
|
|
/**
|
|
* @brief
|
|
* A static version of dot product of 2 vectors
|
|
* @param a Vector a
|
|
* @param b Vector b
|
|
* @return The dot product of a and b
|
|
*/
|
|
public static double dot (Vector a, Vector b) {
|
|
return (a.x*b.x + a.y*b.y);
|
|
}
|
|
}
|