我正在处理一个项目,其中有一个叫做Vector2的对象。
想要做以下事情:
这是可能的吗?如果是,我该怎么做?这被称为什么?提前致谢。
public static class Vector2 {
public Vector2 (float x, float y) {
this.x = x;
this.y = y;
}
public float x;
public float y;
public static Vector2 ZERO = new Vector2 (0, 0);
public static Vector2 FORWARD = new Vector2 (0, 1);
public static Vector2 LEFT = new Vector2 (1, 0);
public static float Distance (Vector2 a, Vector2 b) {
return (float) Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
}
}
想要做以下事情:
Vector2 a = new Vector2 (2.32, 453.12);
Vector2 b = new Vector2 (35.32, 532.32);
Vector2 c = a * b;
// c.x = 2.32*35.32
// c.y = 453.12*532.32
float num = 5;
c = a * num;
// c.x = 2.32*5
// c.y = 453.12*5
这是可能的吗?如果是,我该怎么做?这被称为什么?提前致谢。