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