diff options
author | Eugeniy Mikhailov <evgmik@gmail.com> | 2011-07-07 11:46:24 -0400 |
---|---|---|
committer | Eugeniy Mikhailov <evgmik@gmail.com> | 2011-07-07 11:46:24 -0400 |
commit | e278022475608a2fcfa2d23b88d63467f304a542 (patch) | |
tree | 7cfec4d1ff3ae189d086ff60e987272f5fb62f8c /beam2face_distance.m | |
parent | d13928279d3b245797ec39027c55f029fbcc1b59 (diff) | |
download | wgmr-e278022475608a2fcfa2d23b88d63467f304a542.tar.gz wgmr-e278022475608a2fcfa2d23b88d63467f304a542.zip |
add simple check for interception
Diffstat (limited to 'beam2face_distance.m')
-rw-r--r-- | beam2face_distance.m | 16 |
1 files changed, 13 insertions, 3 deletions
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 |