public int sign(Vector2D v2) { return prep.dotProd(v2) < 0 ? -1 : 1; }
//两向量相减 public Vector2D subtract(Vector2D v2) { return new Vector2D(_x - v2.x, _y - v2.y); }
//向量积 public double dotProd(Vector2D v2) { return _x * v2.x + _y * v2.y; }
public Boolean equals(Vector2D v2) { return _x == v2.x && _y == v2.y; }
//返回当前向量与V2的距离的平方 public double distanceSQ(Vector2D v2) { double dx = v2.x - _x; double dy = v2.y - _y; return dx * dx + dy * dy; }
//返回当前向量与V2的距离 public double distance(Vector2D v2) { return Math.Sqrt(distanceSQ(v2)); }
//判断两向量是否垂直 public double crossProd(Vector2D v2) { return _x * v2.y - _y * v2.x; }
//两向量相加 public Vector2D add(Vector2D v2) { return new Vector2D(_x + v2.x, _y + v2.y); }
//返回两向量夹角的弧度值 public static double angleBetween(Vector2D v1, Vector2D v2) { if (!v1.isNormalized()) { v1 = v1.clone().normalize(); } if (!v2.isNormalized()) { v2 = v2.clone().normalize(); } return Math.Acos(v1.dotProd(v2)); }