我的弹射器游戏产生了不正确的距离
Incorrect distance being produced by my catapult game
我在弹射器游戏中似乎遇到了一个涉及距离方程的严重问题。该方程旨在计算弹射器在给定速度和发射角度下发射的炮弹的距离。通常距离总是高得离谱。
速度是通过特定的用户输入密度来计算的,因此这也可能存在问题。我禁用了角度有效性检查,并将发射角度设置为90(这不是给我0距离吗),我得到了相当高的数字。
我无法验证是什么导致了这个程序的问题,因为我不学习物理,我知道方程中有任何错误(我们的老师给我们提供了公式)。我想知道是否有精通物理的程序员可以帮我修复这个游戏?
附言:我想问题可能是由我的弧度转换引起的。以下是我的代码片段:
cout << "Choose a material to launch:" << endl
<< "1) BIRCH WOOD (670 kg/m^3)n2) ICE (917 kg/m^3)n3) FLAMING COAL (1500 kg/m^3)n4) ASBESTOS (2450 kg/m^3)" << endl;
cin >> materialChoice;
materialChoice = int(materialChoice);
while (materialChoice < 1 || materialChoice > 4)
{
cout << "Please choose a valid material type:" << endl
<< "1) BIRCH WOOD (670 kg/m^3)n2) ICE (917 kg/m^3) 3) FLAMING COAL (1500 kg/m^3)n4) ASBESTOS (2450 kg/m^3)" << endl;
cin >> materialChoice;
materialChoice = int(materialChoice);
}
switch (materialChoice)
{
case 1:
density = 670;
break;
case 2:
density = 917;
break;
case 3:
density = 1500;
break;
default:
density = 2450;
}
cout << "Now select a launch angle between 20 and 70 degrees:" << endl;
cin >> angleChoice;
while (angleChoice < 20 || angleChoice > 70)
{
cout << "Please select a valid launch angle between 20 and 70 degrees:" << endl;
cin >> angleChoice;
}
cout << "Now select the radius of the projectile between 6 cm and 10 cm:" << endl;
cin >> radius;
while (radius < 6 || radius > 10)
{
cout << "Please select a valid radius for the projectile between 6 cm and 10 cm:" << endl;
cin >> radius;
}
velocity = 360000.0/(density * radius);
distance = 2 * sin(RADIAN * (angleChoice)) * velocity * cos(RADIAN * (angleChoice)) * velocity/9.8;
cout << "The projectile goes flying! Press any number to check where it landed" << endl;
cin >> null;
shortDiff = (abs(distance - 24));
RADIAN
的值应该是PI/180
(PI弧度)/(180度)*(角度,以度为单位)将以radian为单位给出结果
进行更改,然后根据需要进行调试。
相关文章:
- 使用2个键的cpp-stl::优先级队列排序不正确
- 正弦级数方程计算不正确
- 我试图制作一个程序,要求用户输入问题和答案,但程序循环不正确
- 密码登录程序将永远循环并显示不正确的结果
- 在C++中返回不正确的楼层函数值
- 形状对象的旋转和缩放不正确C++
- C++ 读取文件读取文件不正确
- 关于类的 Python 文档 - 对C++的引用不正确
- 特征 LLT 模块给出不正确的结果?
- glibcxx STL 在实现 std::valarray::sum() 时是否不正确?
- 如果语句逻辑不正确
- 来自逆 vp 矩阵和相机位置的光线方向不正确
- 不正确的操作数类型 MSVC
- 数组填充了不正确的值
- 我是否不正确地集中了这些字符数组?
- 为什么除非我使用 cout,否则我的值不正确?
- 计算幂级数的数学结果不正确
- 为什么 sizeof 在 C++ 中给出不正确的字节数?
- 汉明距离:计数不正确
- 我的弹射器游戏产生了不正确的距离