given

line end point={e.x, e.y, e.z}

line start pont={s.x, s.y, s.z}

cube center point={c.x, c.y, c.z}

cube height=h

define dx,dy,dz as

if( s.x<=e.x ){

dx=1;

}else if( e.x<= s.x ){

dx=-1;

}

if( s.y<=e.y ){

dy=1;

}else if( e.y<= s.y ){

dy=-1;

}

if( s.z<=e.z ){

dz=1;

}else if( e.z<= s.z ){

dz=-1;

}

and let

S=max( 0, (e.x-(c.x-dx*h/2))/(e.x-s.x), (e.y-(c.y-dy*h/2))/(e.y-s.y), (e.z-(c.z-dz*h/2))/(e.z-s.z))

E=min( 1, (e.x-(c.x+dx*h/2))/(e.x-s.x), (e.y-(c.y+dy*h/2))/(e.y-s.y), (e.z-(c.z+dz*h/2))/(e.z-s.z))

if S<=E, then the portion of the line which intersects the cube goes from

start = { s.x+S*(e.x-s.x), s.y+S*(e.y-s.y), s.z+S*(e.z-s.z) }

to

end = { s.x+E*(e.x-s.x), s.y+E*(e.y-s.y), s.z+E*(e.z-s.z) }

if E<S, then the line does not intersect the cube

line end point={e.x, e.y, e.z}

line start pont={s.x, s.y, s.z}

cube center point={c.x, c.y, c.z}

cube height=h

define dx,dy,dz as

if( s.x<=e.x ){

dx=1;

}else if( e.x<= s.x ){

dx=-1;

}

if( s.y<=e.y ){

dy=1;

}else if( e.y<= s.y ){

dy=-1;

}

if( s.z<=e.z ){

dz=1;

}else if( e.z<= s.z ){

dz=-1;

}

and let

S=max( 0, (e.x-(c.x-dx*h/2))/(e.x-s.

E=min( 1, (e.x-(c.x+dx*h/2))/(e.x-s.

if S<=E, then the portion of the line which intersects the cube goes from

start = { s.x+S*(e.x-s.x), s.y+S*(e.y-s.y), s.z+S*(e.z-s.z) }

to

end = { s.x+E*(e.x-s.x), s.y+E*(e.y-s.y), s.z+E*(e.z-s.z) }

if E<S, then the line does not intersect the cube