【发布时间】:2023-03-22 20:45:01
【问题描述】:
如何在两个 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 组件。我该怎么做?
【问题讨论】:
标签: java 3d trigonometry lerp