Position, Velocity And acceleration relations Today we showed our physics teacher our code for a basic physics engine.
He told us that this code snippet is incorrect:
 float sumX = AccelerationOnXAxis;
 float sumY = AccelerationOnYAxis;

 velocity += new Vector2(sumX, sumY) * delta;

 Position += velocity * delta;

Where delta is the delta time between two frames (usually 1/60).
Because our teacher isnt that good in explaining he just mumbled something with the equation of acceleration / 2.
Any idea what we did wrong and what he meant?
Thanks in advance!
 A: I suspect your teacher glanced at it very quickly, and didn't realize you were using timesteps.  When you work with timesteps you are doing a discrete approximation of the differential equations which describe the relationships, namely:
$\frac{dv}{dt} = a$ and $\frac{dx}{dt} = v$
which in the discrete form, and arranged to match your code, become:
$\Delta v = a \Delta t$ and $\Delta x = v \Delta t$
(Read out loud as, "The change in $v$ equals $a$ times the change in $t$".)  This will be exactly right in the limit where $\Delta t$ is infinitesimal (like the differential equation form).  It will accumulate deviations from the exact answer whenever $\Delta t$ is large.  (A common class of problems with timestep based simulations.)
He was probably thinking about the constant acceleration equations, where you rearrange the first set of equations to do:
$dv = a dt$ which after integrating both sides becomes $v = a t + v_0$
Then using the second equation you get $dx = (a t + v_0) dt$ which after integrating becomes $x = \frac{1}{2}at^2 + v_0 t + x_0$, which is the normal equation of motion under constant acceleration.  It has the $\frac{1}{2}$, and it gives you the position at any point in time without calculating the positions for times in between.  As you can see, the two expressions are identical if acceleration is constant since one derives from the other.  Essentially what you are doing in the timestep version is doing the two integrals numerically.  This has the disadvantage that small inaccuracies accumulate, but it has the advantage that acceleration can change at each timestep.
(Technically there's a slight bug in your code as posted.  You wrote, "sumY = AccelerationOnXAxis" which mixes Y and X.  But the answer holds true if that is fixed.)
A: $s = v \cdot t$ is only true if $v$ stays constant. If $v$ changes with time, the proper relation is
$$ s(t) = \int_{t_0}^{t} v(t') \mathrm dt'$$
For $v = a \cdot t$ with a constant acceleration $a$ this becomes
$$ s = \frac{1}{2} a t^2 $$
So instead of calculating the position from the velocity you could calculate it from acceleration directly.  
A: Your solution is correct at the level of your course.  We don't see what else is in your code, so there might be another problem.   I can only guess what he means by "acceleration / 2".   Perhaps he didn't read your program carefully enough;  he might have been expecting a solution involving $1/2 a t^2$, and when he didn't see it, moved on.
Your solution does not conserve energy, but the deviation from exact conservation will be very small, and unnoticeable unless you run for a long time and/or compare energy with an exact solution.  I doubt that your teacher is referring to this, but you never know.  Personally, I would not make a big deal of this very small issue. 
