From e278022475608a2fcfa2d23b88d63467f304a542 Mon Sep 17 00:00:00 2001 From: Eugeniy Mikhailov Date: Thu, 7 Jul 2011 11:46:24 -0400 Subject: add simple check for interception --- beam2face_distance.m | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'beam2face_distance.m') diff --git a/beam2face_distance.m b/beam2face_distance.m index ba3d16b..4df0f49 100644 --- a/beam2face_distance.m +++ b/beam2face_distance.m @@ -2,10 +2,23 @@ function [hit_distance, hit_position, is_face_hit] = beam2face_distance(beam,fac %% return distance to face if beam hits it or infinity otherwise % for beams and faces structure description see face_beam_interaction.m + % defaul returning values fot the case when beam misses the face + is_face_hit = false; + hit_position = [NA, NA]; + hit_distance = Inf; + k = beam.k; % face direction or kf kf=face.vertex2 - face.vertex1; % not a unit vector + %% simple check for intersection of two vectors + % if beam are parallel no intersection is possible + % we do this via simulated cross product calculation + if ( ( k(1)*kf(2)-k(2)*kf(1) ) == 0 ) + % beams never intercept + return; + end + %% let's find the intersection of lines passing through face and light beam % we introduce parameters tb and tf % which define distance (in arb. units) along k vectors @@ -23,9 +36,6 @@ function [hit_distance, hit_position, is_face_hit] = beam2face_distance(beam,fac is_face_hit = true; else % beam misses the face - is_face_hit = false; - hit_position = [NA, NA]; - hit_distance = Inf; return; end -- cgit v1.2.3