Posted: 19th Aug 2011 18:54
I attempted to perform a two dimensional motion with constant acceleration test and I am running into a problem.

1) I am interested in setting a scale of 0.03, which corresponds to 1.5 m = 50 pixels. For this scale, the simulation agrees with those expected from constant acceleration equations for small run times. If the scale is increased from 0.03 to 0.1 (and higher), the agreement is better for much larger run time times. Why is scale connected to run time? Why do small scales give agreement only for small run times? My scale seems reasonable and I am simulating simple two dimensional motion with constant acceleration. Seems like this shouldn't be a problem.

2) Even more odd, is that the scale can be set to large values like 10 and still get good agreement for larger run times. 10 meters = 1 pixel seems to be not practical. What is the range of allowable scales?

3) Commands like SetPhysicsGravity require you to scale the parameters - see code below. To get SetPhysicsVelocity to agree with predictions, you have to pass the parameters with the default and new scales - see code below.

+ Code Snippet
remstart
Set simulation run time runtime#
Set initial x position x0#
Set initial x velocity v0x#
Set x acceleration ax#
Set initial y position x0#
Set initial y velocity v0x#
Set y acceleration ay#
When the program runs, an object will move across the screen based on the settings above.
After runtime# seconds, the positions and velocities will be displayed.
The values are to be compared with those calculated from the basic equations of physics.
remend

runtime# = 1.22 ` simulation run time (in seconds)

x0# = 0 ` initial x position (in meters)
v0x# = 10 ` initial x velocity (in meters/second)
ax# = 0 ` x acceleration (in meters/second^2)

y0# = 0 ` initial y position (in meters)
v0y# = 0 ` initial y velocity (in meters/second)
ay# = 10 ` y acceleration (in meters/second^2)

setvirtualresolution(480, 320)
setprintsize(12)

scale# = 0.03 ` scale (in meters/pixel)
setphysicsscale(scale#)
setphysicsgravity(ax#/scale#, ay#/scale#)

sync()
sync()

setphysicswallbottom(0)
setphysicswallleft(0)
setphysicswalltop(0)
setphysicswallright(0)

loadimage(1, "object.jpg")
createsprite(1, 1)
setspriteposition(1, x0#/scale#, y0#/scale#)
setspritephysicson(1, 2)
setspritephysicsvelocity(1, v0x#*(0.2/scale#), v0y#*(0.2/scale#))

time# = timer()
do

    timeElapsed# = timer() - time#
    if (timeElapsed#) >= runtime#

        x# = getspritex(1)*scale# ` x position (in meters)
        xcalc# = x0# + v0x#*timeElapsed# + 0.5*ax#*(timeElapsed# * timeElapsed#) ` calculated x position (in meters)
        vx# = getspritephysicsvelocityx(1)*scale# ` x velocity (in meters/second)
        vxcalc# = v0x# + ax#*timeElapsed# ` calculated x velocity (in meters/second)

        y# = getspritey(1)*scale# ` y position (in meters)
        ycalc# = y0# + v0y#*timeElapsed# + 0.5*ay#*(timeElapsed# * timeElapsed#) ` calculated y position (in meters)
        vy# = getspritephysicsvelocityy(1)*scale# ` y velocity (in meters/second)
        vycalc# = v0y# + ay#*timeElapsed# ` calculated y velocity (in meters/second)

        printc("time:  ")
        print(timeElapsed#)
        print("")

        printc("x (m):  ")
        print(x#)
        printc("x (m) should be ")
        print(xcalc#)
        print("")

        printc("vx (m/s):  ")
        print(vx#)
        printc("vx (m/s) should be ")
        print(vxcalc#)
        print("")

        printc("y (m):  ")
        print(y#)
        printc("y (m) should be ")
        print(ycalc#)
        print("")

        printc("vy (m/s):  ")
        print(vy#)
        printc("vy (m/s) should be ")
        print(vycalc#)

        sync()
        repeat
        until getpointerpressed() = 1
    endif
    sync()
loop

end
Posted: 20th Aug 2011 14:02
Regarding item 1 above... I believe I have found the answer.

After running a series of test on the code above, I have determined that there is a speed limit of 600 pixels/sec. The maximum speed for each scale is determined by vmax = 600 pixels/sec * scale in meters/sec. This means that the measured and predicted quantities will be in close agreement until such time that the maximum speed has been reached. The speed is calculated from the square root of (velocity in the x direction squared + velocity in the y direction squared).

Here is an example:
If scale# = 0.3, then vmax = 180 m/s. If you attempt to launch something out horizontally (x0 = 0, v0x = 35 m/s and a0x = 0) and allow it to fall under the influence of gravity (y0 = 0, v0y = 0 and a0y = 10), then you will find that the measured quantities and predicted quantities will be in close agreement until vy reaches 177 m/s (from the speed calculation above: 180 = sqrt(35^2 + 177^2)). This then sets the run time to 17.7 seconds (from the vy calculation in the code: 177m/s = 0m/s + 10m/s^2*17.7 s). If the run time exceeds this amount, then there will no longer be agreeement between measured and predicted quantities.
Posted: 23rd Aug 2011 16:14
It turns out Box2D does have an internal speed limit of about 125m/s. Although the way this is enforced means it can reduce an object's speed down to 10m/s for one step, which then persists into the following steps.

I've changed it to enforce the 125m/s limit without reducing the speed below this, it may make it into the next update (for the windows interpreter). There was also a bug in the SetPhysicsScale command that would maintain the scale at 0.2 no matter what value was given to it.
Posted: 28th Aug 2011 6:15
I have integrated the fix into the next build which should be in the next seven days if all testing goes well.