Gravity in C++ using classes and lists (no graphical representation)
What I need to achieve is a program which will simulate gravity in 2D plane (only x and y axis), using Euler equation, based on class of an astronomical object and a list of said objects.
As for the object, I need to give it both positions, a mass and a velocity (if it exists from the beginning). Radius is ignored, since I'm not going into collisions.
Then, I was told to recalculate every object's position and velocity accordingly, when I add a new object to the list, based on this new object's mass.
I have no idea how to do this, since all of this should be determined by time, right? It's a constantly changing situation, especially without taking collision into account. This means that all the objects will be inifnitely spinning and flying around, so I can't simply say "well, upon adding a new object, the previous one moved to XY and stayed there".
I tried searching for that before, but most gravity projects use Box2D engine or similar libraries, while everything I need to do is to use a simple class, a list and a formula.
I know the maths behind it, Gravitational Constant, force equations and whatnot, but I have absolutely no clue how to implement this. I'm having a big problem, since the assignment is for Monday, and having a lot of work on my own (I have a freshly started-up company) I forgot a lot from C++ lectures.
I will be really grateful if anyone could help me with that, thanks in advance!
EDIT: I really have not a slightest clue how to approach this problem, everyone I ask tells me to make a class with vectors, throw it in a list and create a method which will update all the parameters in time, but while I do know this, because I understand the subject, I do not know how to present it in code... I know I should do this earlier, but I'm really desperate right now. I will need to revise the code and understand it anyways, I'm no computer dummy and I will need to explain it to my professor, so I'll get the grasp of it - I just don't know C++ at this point and I'm probably done with my studies if I don't make it in time...
链接地址: http://www.djcxy.com/p/65402.html上一篇: 用测角仪计算重力