function [hit,s] = ccylz(R,x,u,inside) % Calculates the distance to a cylinder of radius R concentric and aligned % with the z-axis % Inputs %%%%%%%% % double % R : Radius of the cylinder (scalar) % x : coordinates of the particle (row vector) % u : direction cosines of the particle (row vector) % 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) % % Internal variables % double % A: Quadratic coefficient A (communicated to quadric) (scalar) % B: Quadratic coefficient B (communicated to quadric) (scalar) % C: Quadratic coefficient C (communicated to quadric) (scalar) % Compute the quadratic coefficients A = u(1).^2 + u(2).^2; B = u(1).*x(1)+ u(2).*x(2); C = x(1).^2 + x(2).^2 - R.^2; % Call the quadratic solver [hit,s] = quadric(A,B,C,inside); return