C#弹跳球问题 [英] C# Bouncing Ball problem

查看:95
本文介绍了C#弹跳球问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我确实需要您的帮助来解决这个问题.我必须制作一个Windows窗体应用程序,其中图像在窗口中弹跳.我的弹跳部分已经完成,但是作业的下一部分是使它弹跳,以便用户可以调整速度以及图像的角度.我已经完成了速度,但是我想不出办法改变角度以使速度保持不变.
拜托,我真的需要有关如何更改反射图像角度的帮助
谢谢.

Hello I really need your help with this problem that I am having. I have to make a Windows Form application where an image bounces around in the window. I have the bouncing around part done, but the next part of the assignment is to make it so that the user can adjust the speed and also the angle of the image. I have done the speed, but I cannot figure out a way for the angle to be changed so that the speed remains the same.
Please, I really need help on how to change the angle of the bouncing image
Thanks.

推荐答案

我认为您可能过分担心它可能使这个问题变得太困难了.

在弹跳球问题中,您只需要考虑几个因素.首先,您具有初始的发射速度和发射角度;它们共同形成一个速度,一个向量.当您的物体移动时,它仅受到动量和重力的向下作用.当它碰到诸如墙壁或天花板之类的固体物体时,它以与入射角相等的角度反射,但没有能量损失(假设,像大多数家庭作业一样,没有摩擦损失和完美的弹性).由于速度是矢量,但是速度是标量值,因此要使速度保持恒定,必须随入射角的变化而更改垂直和水平速度,以使行进路径上的速度保持恒定.这将需要一些三角函数.

给定速度S时,速度矢量的水平和垂直分量由下式给出:

V h = S * cos(Φ)
V v = S * sin(Φ)

随着时间的流逝,垂直分量会由于重力的作用而减小,而水平分量不会,因为没有施加力来减小它.对于您的应用程序,首先将用户输入的速度和角度转换为矢量量,然后相应地计算入射表面上的轨迹.这不是一个小问题,但是,经过一点数学上的准备,解决起来也不难.你能行的!我也很期待您在编程论坛上发表有关该解决方案的文章.
I think that you may be making this problem too hard by worrying excessively about it.

In a bouncing ball problem you only have a couple of factors to worry about. First, you have an initial speed and angle of launch; together they form a velocity, a vector quantity. As your object moves, it''s subject only to momentum and the downward force of gravity. When it strikes a solid object, such as a wall or ceiling, it is reflected at an angle equal to the angle of incidence, but with no loss of energy (assuming, as most homework problems do, no frictional losses and perfect elasticity). Because velocity is a vector quantity, but speed is a scalar value, to hold your speed constant, you have to change your vertical and horizontal speeds as the angle of incidence changes in order to keep your speed along the path of travel constant. This is going to require a bit of trigonometry.

Given a speed of S, the horizontal and vertical components of the velocity vector are given by:

Vh = S*cos(Φ)
Vv = S*sin(Φ)

As time passes, the vertical component will diminish because of the effect of gravity, but the horizontal component will not, because there is no force being applied to reduce it. For your application, first convert the speed and angle entered by the user to vector quantities, then calculate the trajectory on the incident surfaces accordingly. It''s not a small problem, but it''s not too hard to solve, either, given a bit of mathematical preparation. You can do it! And I look forward to your post about the solution in the programming forums.


这篇关于C#弹跳球问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆