How to correctly create planetary orbits from kepler elements I would like to build a gravity model (with 3D graphics) that would build the orbit of the planets based on orbital elements input and the gravity calculation for each element. 

My initial code is live here (Click the 0.005 to turn it into 0.05 and then click on restart time to run the orbits).

The example above has all planets on Solar System (up to Neptune), the Sun and the asteroid Apophis. For clarity, the Sun and planets other than earth have been hidden, but are still considered for gravity calculations.

However, the orbits do not match the correct estimate intersection date. In this article, it says that Earth-Apophis close-encounters will happen on 13 April (meaning that the earth should be in the orbit's intersection point every 13 April, or very close to it).

The data from the program is taken from Nasa JPL.


Apophis Data
Planets Data
The sun is positioned at the origin


Start date is 2454441.5, as given in JPL Apophis data. Planets orbital elements have been corrected to this date, with the calculations in the above PDF.

Why the orbits intersection date is wrong? Should I be doing something else? Am I doing something wrong?

The above Apophis link also cites a "Standard Dynamical Model". If anyone knows how to correctly create one, I believe this would answer my question as well.

TLDR: How can I correctly create planetary orbits from kepler elements?

Thank you in advance if anyone can help me!
If you're running your own N-body dynamics,
you can get initial Cartesian positions and velocities for each body in your system (including the Sun) by asking
JPL HORIZONS
for Ephemeris Type: Vectors.
I would choose Coordinate Origin: Solar System Barycenter so that the Sun does not drift away from the origin,
and Target Body: [Planet] Barycenter (or Sol) unless you are modeling the Earth and Moon as separate bodies.

If you still want to compute initial Cartesian positions and velocities from Keplerian elements, first do a sanity check: Earth should cross the X axis at the equinoxes and the Y axis at the solstices.
Second, those approximate elements for the major planets may not be precise enough for your purpose.
Instead you might ask HORIZONS for Ephemeris Type: Elements, and Time Span beginning with the epoch of your elements for Apophis.
You could also get elements for Apophis in a more convenient epoch this way.

Note that Keplerian elements are subject to dynamic evolution and are only valid for a limited time near their epoch.
If you ask HORIZONS for Apophis's orbital elements one week before and after its close approach to Earth, you can see that they are quite different. Of course the latter are also highly uncertain.

For the gory post-Newtonian details of the dynamical model the Apophis prediction article discussed extending, see JPL's
notes on DE430 and DE431, part III.