Why ray_cast is behaving like this?
Thanks to batFINGER, I found the error. The ray_cast function should be supplied with a point (v1, in my example) and the normalized direction, reached by (v2 - v1).normalized(). Now it is working as expected.