I am currently trying to code a 2D physics engine in gamemaker studio, however I have run into a problem.
I have found the following useful website to help me calculate the new x and y components of my speed vector after collision: http://williamecraver.wixsite.com/elastic-equations
EDIT: I'll try and be more specific about my problem: I want to calculate collision in 2D. In order to do this I first rotate my x-y axis so that x runs from the centre of one object through the center of the other object (both are circles). (the image in the link nicely illustrates the situation)
In the link I provide, calculation of resulting vx and vy vectors for each object after the collision is explained. It uses the following equations to rotate the vx and vy components(I'm sorry I don't know how to insert proper equations)
vxr = v * cos(theta - phi)
vyr = v * sin(theta - phi)
with vxr being the rotated vx vector (same for vy), theta being my original angle between v and the x axis, phi being my rotation angle
Then these "rotated" vx and vy components are inserted into the equations for conservation of momentum and kinetic energy to solve a 1D collision (which is possible because of the rotation of the axis). Afterwards he rotates the axis back using the following equations:
vfx = vfxr * cos(phi) + vyr * cos(phi + pi/2)
vfy = vfyr * sin(phi) + vyr * sin(phi + pi/2)
with vfxr/vfyr being the resulting rotated x/y component after collision, vfx vfy being the resulting x/y components transformed back into the regular x-y plane.
My problem is that my y-axis is pointing down (instead of the conventional up). Therefore I believe the original equations for vyr should be:
vyr = v * -sin(theta - phi)
My first question is if my assumption for the vyr component is correct and if I missed other things that should change in the calculation because of the inverted y-axis. What about the equation to rotate vx and vy back to the regular x-y plane?
Secondly, if my assumptions are correct, I am unable to perform the calculations when inserting these equations into the 1D collision equations. Especially regarding the conversion back to regular x-y plane, I don't understand where these equations come from and how they change with an inverse y-axis.