【发布时间】:2016-01-19 09:49:11
【问题描述】:
首先,代码如下:
decimal gravity = decimal.Parse(gforce.Text) / 1000;
decimal speed = decimal.Parse(initialSpeed.Text) / 1000;
decimal newAngle = DegreesToRadians(decimal.Parse(angle.Text));
double doubleNewAngle = (double)newAngle;
decimal Px = Math.Round(((decimal)Math.Cos(doubleNewAngle) * 0.001M), 13);
decimal Py = Math.Round(((decimal)Math.Sin(doubleNewAngle) * 0.001M), 13);
string PxTemp = "";
for(decimal t = 0.001M; Py > 0; t = t + 0.001M)
{
gravity = gravity + gravity * 0.001M;
Py = Py + speed - gravity;
Px = (Px + speed * Px);
graphics.DrawArc(new Pen(Color.Magenta, 10f), 45 + (float)Px, 475 - (float)Py, 1, 1, 0, 360);
try
{
graphics.DrawArc(new Pen(Color.Magenta, 10f), 45 + (float)Px, 475 - (float)Py, 1, 1, 0, 360);
}
catch
{
MessageBox.Show("Error Px: " + Px.ToString() + " Py: " + Py.ToString(), "Error");
this.Close();
}
我正在尝试创建一个弹丸模拟器,我已成功创建了 y 轴上的重力和加速度效果。但是,当将速度应用于 x 轴(使速度取决于角度)时,我遇到了麻烦。我可以做到这一点,弹丸每秒移动 1 米,但要正确,弹丸在 x 轴上的速度应该取决于速度和角度。
为了实现这一点,我已经做到了:
Px = Px + (speed * Px)
其中 Px 是轴上距离的值 角度的余弦:
decimal Px = Math.Round(((decimal)Math.Cos(doubleNewAngle) * 0.001M), 13);
当我这样做时
Px = Px + (speed * Px)
该值返回一些巨大的数字,例如 4412651515851.41214244121,我起初认为这是因为 Px 超出了它的精度点,但我所做的任何舍入尝试都失败了,我应该如何获得正确的 Px 数字?
这是一个可视化的图像:
任何帮助将不胜感激,我整天都在挣扎,我在网上找不到任何东西。提前致谢。
【问题讨论】:
标签: c# winforms math physics projectile