Advertisement
Guest User

Vector2D.java

a guest
Oct 28th, 2012
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. package genericzombieshooter.structures;
  2.  
  3. import java.awt.Point;
  4.  
  5. /**
  6.  *
  7.  * @author packetpirate
  8.  */
  9. public class Vector2D extends Point.Double {
  10.     public Vector2D() {
  11.         super();
  12.     }
  13.    
  14.     public Vector2D(double x_, double y_) {
  15.         super(x_, y_);
  16.     }
  17.    
  18.     public Vector2D(Vector2D v_) {
  19.         super(v_.x, v_.y);
  20.     }
  21.    
  22.     public double getLength() {
  23.         return Math.sqrt((x*x) + (y*y));
  24.     }
  25.    
  26.     public Vector2D normalize() {
  27.         if(getLength() > 10) return new Vector2D((x / getLength()), (y / getLength()));
  28.         else return null;
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement