Collision can be done in several ways, the most usual being by the use of Bounding Boxes, in this case, a rectangle that more or less covers the area of our object, this can be done in several ways and it is very easy to implement, however, for carcode I stepped this up to something more generic with a given set of vectors, which should be very similar to 3D Bounding Box collision detection, but 2D, I had to workout my rusty math skills but I came up with a nice and general way.
At first I tough of making assumptions such as that the box was actually a rectangle, however this isn't generic enough, I could want to have a non rectangle quadrilateral or even define an area with more than 4 vectors, the answer was "triangles", you can basically divide any "regular" polygon defined by n vectors in triangles, and thus began my quest for collision detection inside a triangle.
By using a vector as the basic unit for collision detection (a vector inside a given area) it should be generic enough for "collisioning" two different polygons, the basics of this is to pick 3 vectors for the triangle, noted by v1, v2, v3, translate the figure to Origin by using v1 as base, now we calculate the angle between v1 and v3, and rotate so V3y will be exactly 0 (on the X axis), we do the same to the vector we want to collision test (Vc), now with Vcy we calculate the distances in the X axis of a pair of vectors that delimits the triangle on Y - Vcy, this is basically done by using the angle alpha1 (angle of V1) and alpha2 (angle of V3).
X1 = tan(90 - alpha1) * Vcy
X2 = tan(90 - alpha2) * Vcy
We do a substraction, X2 - X1, if the result is negative basically means that Vc is outside the triangle (in Y), you could also check this by using V2y, now we test if: (V3x - X2) > Vcx > X1, in case of being true it means that the vector is inside the V1,V2,V3 delimited area (in X).
Doing all this for every frame could be time consuming, but we can pre-calculate a lot of things such as dX and dY from the translations and rotations, then tan(90-alpha), which will basically reduce the whole algorithm to a pair of additions, two multiplications and tree comparisons, in the optimal case (the area is not moving, and we use V2y for Y test).
That is the basics, but even then I'm making some assumptions, I will try to prototype some code and do the necessary refinements. Hopefully I will have some time next week after the Pharmacology (this Friday) exam and the Physiology exam (next Tuesday), which obviously pharmacology is way way bigger than physiology.