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 Snippetremstart
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