# Need some maths help with my rocket....

• 15th October 2011, 06:09 PM
SimpleSi
Need some maths help with my rocket....
..simulation :)

I'm writing a rocket simulator in Scratch and want the rocket to appear to take off and reach orbit but I need some non-linear function to translate the real distances 0 - 1000000 metres to -170 to 50 (these are Scratch Screen units)

I'm looking for a function that will approach a limit on screen of y=50 when real height is 1000000 but if the rocketeer makes a bigger orbit - I need the function to stop the image disappear off the top of screen :)

My maths mojo has deserted me! help please :)

Si
• 15th October 2011, 06:30 PM
SYNACK
Cant you use log(x) or xlog(x) to compress from an exponential series to a linier one? Its been a while so I could be way out.

http://www.intmath.com/exponential-l...og-semilog.php
• 15th October 2011, 07:08 PM
LisaW
Scratch has the 'if 'control loop and the 'touching x ' sensing item, you can choose 'edge' to make something happen when your rocket reaches the edge. The 'if on edge bounce' motion item is useful in some circumstances too. Hope this helps.
• 18th October 2011, 10:35 AM
Progeniga
I'm not quite sure what you're getting at... if you want the rocket to reach a height greater than 1,000,000 and have a limit of 50 in Scratch then surely you need to recalculate the steps so the 50 Scratch units matches your yMax

The other easy solution is having a simple: if(rocket.Y > yMax) Then rocket.Y = yMax... that would stop it disappearing, but will also stop moving

Not sure if either are massively helpful suggestions
• 18th October 2011, 10:49 AM
SYNACK
The other thing you could do is add a scaling component as well so that depending on your viewpoint the vehicle gets smaller as it gets further away etc.
• 18th October 2011, 01:36 PM
SimpleSi
What I'm looking (I think anyway) is some sort of non-linear relationship between "real" height of rocket and Scratch y screen units so that as the rocket gets higher it doesn't appear to move as much on the screen.

I've already got a simpel scaling factor in

here is effort so far (Which isn't too bad)

Scratch | Project | rocket4

Si
• 18th October 2011, 02:36 PM
Progeniga
How about moving your rocket relative to the distance between where it is and its target height?

I've just done it in flash(actionscript) and it looks like this:

rocket_mc.y -= (rocket_mc.y - yMax)/speed;
speed += accel;

(Bear in mind the coordinate system is upside down in flash which is why there's a - sign)

As (rocket_mc.y - yMax) gets tends towards 0 as the rocket approaches yMax the distance moved will tend towards 0 also.

I put it together in a flash file over lunch too: rocketlaunch