Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Programming challenge, gravity
Message
De
24/06/2004 12:55:12
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
 
À
24/06/2004 12:14:48
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00916106
Message ID:
00916926
Vues:
40
>>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)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform