Пример #1
0
 public int sign(Vector2D v2)
 {
     return prep.dotProd(v2) < 0 ? -1 : 1;
 }
Пример #2
0
 //两向量相减
 public Vector2D subtract(Vector2D v2)
 {
     return new Vector2D(_x - v2.x, _y - v2.y);
 }
Пример #3
0
 //向量积
 public double dotProd(Vector2D v2)
 {
     return _x * v2.x + _y * v2.y;
 }
Пример #4
0
 public Boolean equals(Vector2D v2)
 {
     return _x == v2.x && _y == v2.y;
 }
Пример #5
0
 //返回当前向量与V2的距离的平方
 public double distanceSQ(Vector2D v2)
 {
     double dx = v2.x - _x;
     double dy = v2.y - _y;
     return dx * dx + dy * dy;
 }
Пример #6
0
 //返回当前向量与V2的距离
 public double distance(Vector2D v2)
 {
     return Math.Sqrt(distanceSQ(v2));
 }
Пример #7
0
 //判断两向量是否垂直
 public double crossProd(Vector2D v2)
 {
     return _x * v2.y - _y * v2.x;
 }
Пример #8
0
 //两向量相加
 public Vector2D add(Vector2D v2)
 {
     return new Vector2D(_x + v2.x, _y + v2.y);
 }
Пример #9
0
 //返回两向量夹角的弧度值
 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));
 }