function [hit,s] = xplane(xp,x0,u,inside) % Calculates the distance of a particle to a planar surface normal to the % x-axis % Inputs %%%%%%%% % double % xp: x-coordinate that the plane passed through % x0: x-coordinate of the particle % u : x-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 & u > 0) | (~inside & u < 0)) % headed towards the surface hit = true; s = max(0,(xp-x0)/u); return else hit = false; s = inf; return end