在 JavaScript 中创建一个 Projectile 类来计算高度水平距离和着陆
问题
我们需要编写一个JavaScript类Projectile,它在初始化时接受3个参数-
起始高度(0≤h0<200)
起始速度(0
我们需要为Projectile类编写以下方法。
一种horiz方法,它也接受一个参数t并计算射弹行进的水平距离。[接受双精度,返回双精度]
示例
这个类的代码将是-
class Projectile{ constructor(h, u, ang){ this.h= h; this.u= u; this.ang= ang; }; }; Projectile.prototype.horiz = function(t){ const dist = 2 * Math.cos(this.ang) * t; return dist; }; const p = new Projectile(5, 2, 45); const horizontal = p.horiz(.2); console.log(horizontal);输出结果
输出将是-
0.2101287955270919