function [hit,s] = zplane(zp,z0,w,inside) % Calculates the distance of a particle to a planar surface normal to the % z-axis % Inputs %%%%%%%% % double % zp: z-coordinate that the plane passed through % z0: z-coordinate of the particle % w : z-axis direction cosine of the particle % logical % inside: == true particle thinks it is inside % : == false particle thinks it is outside % % Outputs %%%%%%%%% % logical % hit: == true particle would hit the surface % : == false particle would miss the surface % % double % s: distance to the surface (if hit) if ((inside & w > 0) | (~inside & w < 0)) % headed towards the surface hit = true; s = max(0,(zp-z0)/w); return else hit = false; s = inf; return end