Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Programming challenge, gravity
Message
From
24/06/2004 12:55:12
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
24/06/2004 12:14:48
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00916106
Message ID:
00916926
Views:
30
>>Pretty interesting stuff. I think there's another way to do these calcs. Using Sin/Cos you can determine the x and y. You can build a table of sin/cos values in an array and get the value based on the angle between the two objects. This is supposed to be much faster than SQRT.
>
>Do you suppose you could post an alternate algorythm that we could compare?
>
>I used the Pythagorean theorem just because it was the simplest, my trig is sooooo rusty. :-)

The gravitational formula should give you a force vector, consisting of a) A force as a number, b) a direction (of course, the direction of the other object attracting the object in question). (It is easiest, for internal calculations, to have all angles in radians, not degrees.)

From this force vector, you can calculate the x-component as cos(angle) * force, and the y-component as sin(angle) * force (here, "force" means the scalar part of the force, that is, the magnitude, without the angle).

Next, you can apply the force in the x-direction, and the force in the y-direction, separately, to calculate the acceleration. (Acceleration = Force / Mass, and Change in Position = Velocity * Time, are applicable to the individual components of the vector).

HTH,

Hilmar.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform