• Help with Gravity
    12 replies, posted
I am taking a course on C++ in school and one of the programs we were given was one that calculates the gravitational force between two objects. You have to enter the mass of each and the distance between the two. Here is the actual project description: [quote] The gravitational attractive force between two bodies with masses m1 and m2 separated by a distance d is given by: F = [u]G m1m2[/u] --------d² where G is the universal gravitational constant: G = 6.673 X 10^-8 cm³/(g x sec²) Write a function definition that takes arguments for the masses of two bodies and the distance between them, and that returns the gravitational force between them. Since you will use the preceding formula, the gravitational force will be in dynes. One dyne equals a g x cm/sec² You should use a globally defined constant for the universal gravitational constant. Embed your function definition in a complete program that computes the gravitational force between two objects given suitable inputs. Your program should allow the user to repeat this calculation as often as the user wishes. [/quote] I won't have any trouble implementing the formulas in C++ but I have some questions about the formulas. I haven't taken physics yet so don't blame me for not knowing. First, how do you find centimeters in cm³? How do you find grams in the both parts? And, how do you find seconds in both parts? Please post what you know or where I can find the info. I have no background info for physics you don't assume I know something because I probably don't.
We have : F = G m1m2/d² We transform it into "unit equation" [N] = [G] [g][g]/[m²] [g][m]/[s²] = [G][g²]/[m²] [g][m³]/[s²] = [G][g²] [G] = [m³]/([s²][g]) You just need to convert [m] to [cm] and you have the correct unit for G. But I don't understand why you would need it for your C++ program.
You mean its not necessary to find the gravitational force between the objects or that gravity and C++ are totally unrelated? Also the program only says that mass of two objects and distance should be enters so I don't know where seconds centimeters, and g (grams or gravity) comes from.
--Snip, give me boxes--
Understood, and point taken. But it has to calculate gravitational force between two objects at x distance and x mass for each one.
[QUOTE=DainBramageStudios;17946334]Mass is irrelevent; objects of different masses fall at the same rate.[/QUOTE] They're not talking about objects in free fall. They are talking about the gravitational pull of two objects in space. (most likely would have a very large mass) The amount of pull it has on other objects depends on it's mass and the distance between itself and the other object.
Just throw the units away, example: m1 = 10,000,000 m2 = 10,000,000 d = 100 G = 6.673*10^-8 F = 667.3 (Two masses are 10 tonnes / 10,000 kg / 10,000,000 grams. Length is 1 meter / 100 cm) THEN add Newton for F I guess. Predefine what distance and weight unit should be entered.
[QUOTE=ryan1271;17946255]You mean its not necessary to find the gravitational force between the objects or that gravity and C++ are totally unrelated? Also the program only says that mass of two objects and distance should be enters so I don't know where seconds centimeters, and g (grams or gravity) comes from.[/QUOTE] You have everything you need, "cm³/(g x sec²)" in "G = 6.673 X 10^-8 cm³/(g x sec²)" is just an unit, not a variable.
O forgot something, don't add newton as unit for F, do dyne, as described. [editline]09:36PM[/editline] Then maybe convert to newton?
[QUOTE=I am a noob;17946607]O forgot something, don't add newton as unit for F, do dyne, as described. [editline]09:36PM[/editline] Then maybe convert to newton?[/QUOTE] We know that F = Mass*Acceleration So [N] = [g]*[m]/[s²] (1) Just develop the "unit" equation, by putting "[cm³]/([g][s]²)" instead of "[G]". And you will find the equation n° (1)
I'm not really understanding what you're saying. Thanks anyway though. I am just going to ask the teacher next class.
I don't get your problem? Cm, g, sec; are just unit! They don't have value. Only values you need are : G (which is given) m1,m2 and d which are the inputs of your programs. If your program was in C it will consist in : [code] float main(){ float m1,m2,d; const float g = 0.00000006673; scanf("%f,%f,%f",&m1,&m2,&d); float result = g*m1*m2/(d*d); printf("%f",result); return result; } [/code]
[QUOTE=ryan1271;17946255]You mean its not necessary to find the gravitational force between the objects or that gravity and C++ are totally unrelated? Also the program only says that mass of two objects and distance should be enters so I don't know where seconds centimeters, and g (grams or gravity) comes from.[/QUOTE] cm³/(g x sec²) are the units of the gravitational constant.
Sorry, you need to Log In to post a reply to this thread.