我需要创建一个以弧线跳跃穿过屏幕的弹簧单高跷。我认为最好的方法就是将其移动到正弦波上。如果波的顶部为 1,地面为 0,波的底部为 -1,那么每次到达 0 时,我都会重置这些值以再次启动正弦波。因此,它不会遵循典型的正弦波(0, 1, 0, -1, 0 等),而是会走向 0, 1, 0, 1, 0 等。
不幸的是,我的数学非常糟糕,我已经尝试了几个小时制定一个公式。目前,我只是试图制作一个正常的正弦波,其中上半部分模拟弹簧单高跷跳跃,似乎甚至无法走那么远。我最接近的是:
m_vel.x++;
float f = PI / 30 / 2;
m_vel.y = 200 * sin(f * m_vel.x);
m_vel.y = -m_vel.y;
我需要波浪非常窄,高点非常高。上面的公式在第一次迭代中开始时没问题,但随后波浪变得更宽,高点和低点彼此接近。谁能帮助数学菜鸟吗?
I need to create a pogo stick that jumps across the screen in arcs. I was thinking the best way to do this would be to move it on a sin wave. If the top of the wave is 1, the ground is 0 and the bottom of the wave is -1, then every time it hits 0 I would reset the values to start the sin wave again. So instead of following the typical sin wave (0, 1, 0, -1, 0 etc) it would go 0, 1, 0, 1, 0 etc.
Unfortunately my math is pretty terrible and I've been trying for hours to develop a formula. At the moment I'm just trying to make a normal sin wave where the top half emulates a pogo stick jumping, can't seem to even get that far. The closest I have is:
m_vel.x++;
float f = PI / 30 / 2;
m_vel.y = 200 * sin(f * m_vel.x);
m_vel.y = -m_vel.y;
I need the waves to be quite narrow, and the high point to be quite high. The above formula starts off ok for the first iteration but then the waves get wider and the high and low points close in on each other. Can anyone help a math noob out?
发布评论
评论(4)
不确定你的数学,你的物理需要复习!弹簧单高跷是抛射运动及其轨迹形式的一个示例a 抛物线,由 二次方程。
但是,您是否应该坚持使用不正确的正弦模型:正弦波的“上半部分”(或正)部分从 0 到 pi 弧度运行。正弦仅代表 y 项(高度),不应有 x 项,它仅决定每个点的水平步长。其中 200 表示弹簧单高跷将达到的最大高度:
其中 0 <= theta <= pi,并且随着时间的推移而增加。增量的大小将由前进速度或总跳跃距离决定。
这样,当您达到 pi 弧度时,您将移动 jump_distance。在跳跃过程中,瞬时距离(以及图中的 x 值)将为:
Not sure about your math, your physics needs some brushing up! The pogo stick is an example of projectile motion and its trajectory forms a parabola, which is described by a quadratic equation.
However should you persist with the incorrect sinusoidal model: The "top half" (or positive) part of a sine wave runs from 0 to pi radians. The sine represents only the y term (height), you should not have an x term there, that simply determines the horizontal step for each point. Where you have 200, that represents the maximum height the pogo stick will reach:
where 0 <= theta <= pi, and is incremented over time. The size of the increment will be determined by the forward speed, or total jump distance.
so that by the time you have reached pi radians, you will have moved by jump_distance. During the jump instantaneous distance (and therefore the x value in a plot) will be:
只需取正弦波的绝对值即可。
所以负的部分变成了正。
Just take the absolute value of a sin wave.
So the parts that are negative are turned positive.
Hammerite 有票:
不要忘记正弦函数需要弧度,因此作为参数传入的值必须采用正确的单位。
Hammerite has the ticket:
Don't forget that the sine function requires radians, so the value you pass in as a parameter must be in the right units.
这是新编写的正弦波和抛物线波的参数代码。
[...]
Here is the fresh-written, parametric code for both a sinus wave and a parabolic wave.
[...]