Algorithm:
The grid consists out of walls.
A wall is of/in a certain dimension: (Vertical, Horizontal, Depth)
The wall dimensions intersect forming cells (in final dimension)
The line intersects the walls primarly in their own dimension.
The solution is to view the problem as: How to intersect a line with a wall in it's own dimension.
The solution is to slide across the line from wall to wall, switch dimensions as necessary.
The sliding across the line happens such that the nearest wall is always chosen as the next destination.
The sliding from wall to wall in it's own dimension is constant/always the same.
The intersection of the line and the walls is different per dimension.
This ultimately decides the order of the wall intersections.
The solution is therefore to:
Phase 1: Initialization
Compute Dimension.IntersectT
Compute Dimension.SlideT
Phase 2: Start sliding from origin towards destination selecting nearest wall:
Dimension.T := Dimension.IntersectT
while ? end condition ?
Select smallest Dimension.T
Update selected Dimension.T += Dimension.SlideT
end
The difficulty lies in computing the Ts.
Bye,
Skybuck.