I'm using a structure for several objects but I need a float within it to be constant for just one object. (the velocity of the sun in a solar system simulations). Is this possible or do I need a new structure
Well the velocity of the sun is initially set to zero, but this changes when calculating the gravity.I find the the planets drag it slightly. I guess the mass difference in the sun and planets is to low. I am struggling to produce steady orbits is there any way to stabilize it? The earth spinning round the sun OK but it drags the sun slightly and the moon smashes into the earth after 2 orbits.
Well the velocity of the sun is initially set to zero,...
I find this part to be interesting because it isn't true, our solar system isn't stationary. Maybe your program is fine but your math is flawed. What happens when you take into account the fact that Sol is orbiting the center of the universe galaxy and is being acted upon by a mass far greater than anything else in our system (I would represent the center of the galaxy as a constant rate of acceleration acting on the sun, but that's because I'm lazy).
I need a float within it to be constant for just one object.
vlad from moscow wrote:
I have not understood what you want. I showed you a static data member that is common for all objects of a given class.
@OP: Your viewpoint may be centered on the sun, but that doesn't mean the sun doesn't move from its original position. I know, theory of relativity blah blah, but for simulation's sake you can't do what you're trying to do. And how would you expect it to work in writing the code? You can't just say "Oh wait that's the sun? I won't change its velocity then." - that doesn't make sense.
Ok thanks. Is there any way to produce a steady orbit of objects around another object though? I started by two objects of equal mass and they attract according to
Fg = G (m1*m2)/(d^2)
Playing with it I added a object with a very large mass in the center and some of much smaller mass around it with a little starting velocity in the hope of producing some sort of orbit. Is it at all possible to produce a steady orbit in any way?
> I'm using a structure for several objects but I need a float within it to be constant for just one object.
> Is this possible or do I need a new structure
You need a different structure; but it could be a different instantiations of the same template.
1 2 3 4 5 6 7 8 9 10
#include <type_traits>
template < bool CONST = false > struct A
{
int b = 5 ;
typename std::conditional< CONST, constint, int >::type c = 9 ;
};
A<> one ; // one.c is not cnst qualified
A<true> two ; // two.c is const qualified
I find this part to be interesting because it isn't true, our solar system isn't stationary.
It is interesting. If we consider just two bodies in isolation, such as the Earth and the Moon, it is inaccurate to consider that the Moon simply orbits the Earth. What actually happens is the two bodies both orbit around their common centre of gravity, so that neither of them remains stationary.
As more bodies (planets, or the Sun) are added to the system, the same principle applies, but the motion is obviously much more complex.
See also this question in the FAQ here:
"Why does Mercury get thrown out of the Solar System when I turn up the time step?"