What the actual …?
Normal vectors and dot product? Come on.
I’d suggest exactly what Screem suggested, and I’ll add a little bit of code to it, too:
This only works when both objects are considered to behave like two axis-aligned boxes:
// Assuming some kind of vector implementation like Vec2(int x, int y) with the fields "x" and "y".
// AABB = Axis Aligned Bounding Box
public Vec2 getCollisionVelocity(Vec2 velocity, AABB ball, AABB object) {
// side is either TOP, LEFT, RIGHT or BOTTOM
int side = getCollisionSide(ball, object);
switch (side) {
case TOP:
case BOTTOM:
return Vec2(velocity.x, -velocity.y);
case LEFT:
case RIGHT:
return Vec2(-velocity.x, velocity.y);
}
}
The principle of reflecting along an axis is really easy. The hard thing is finding out the side at which they collided. But depending on what kind of game you are creating this might not actually be too hard.
You only need advanced vector math with normals similar when you want to bounce an object off from an arbitrary surface / edge. But then you might as well just use a Physics library like Box2D, because that stuff can get really hard when you want to add rotation upon colliding or similar ^^