Collision detection

I made a simple 3D world, based on 2D squares.
(Each square can have 4 walls, N, E, S or W)
To check if the viewer collides with one of the walls, i make the following steps:
-calculate the point the viewer is heading to (p2, p1 would be the viewers previous position)
-rico = (p2.y - p1.y) / (p2.x - p2.y)
-for each wall in a square
if (wall.orientation = north)
if (p1.x < xt) && ( xt < p2.x) collision;
(for south, east and west the code is mush the same)
This does work in all cases except
-if you walk straight (angle = 0°) on to a wall (i can understand that (div/0))
-in a corner between two walls, you can walk through them

What am i doing wrong?

(If there are thing you want to know, i’ll post the full code)

Why don’t you just make a 2 dimensional bit array. 0 is empty 1 is full.

Take the camera or object location and refer to the array to see if they collide.

or check out Dr. Kinesh Minoa’s ICOLLIDE API.
Its free but you must ask him for it
Search: ICOLLIDE or collision detection