我怎样才能在两个 3d 向量之间切换?我将此方法用于二维向量:
public Vector2d lerp(Vector2d other, double speed, double error) {
if (equals(other) || getDistanceSquared(other) <= error * error)
return other;
double dx = other.getX() - this.x, dy = other.getY() - this.y;
double direction = Math.atan2(dy, dx);
double x = this.x + (speed * Math.cos(direction));
double y = this.y + (speed * Math.sin(direction));
return new Vector2d(x, y);
}
注意:这不完全是“线性插值”;这种方法将以恒定的速率进行插值,这就是我想要的。
我想完全做到这一点,但为第三维添加了 z 组件。我怎样才能做到这一点?