Commit 358fb8ab authored by Jonas Stienen's avatar Jonas Stienen
Browse files

Adding merging functions for outer edges

parent 3c7cb275
function merged_anchor = ita_propagation_merge_anchors( anchor_a, anchor_b )
%ita_propagation_merge_anchors Merges two anchors in a best-fit attempt
% Merge two outer wedges
if strcmpi( anchor_a.anchor_type, 'outer_edge_diffraction' ) && strcmpi( anchor_b.anchor_type, 'outer_edge_diffraction' )
merged_anchor = ita_propagation_merge_outer_edge_diffraction( anchor_a, anchor_b );
else
error( 'Merging types %s and %s is not supported, yet.', anchor_a.type, anchor_b.type )
end
end
function merged_outer_edge_diffraction = ita_propagation_merge_outer_edge_diffraction( a, b )
%ita_propagation_merge_anchors Merges two outer edge diffractions in a best-fit attempt
if a.main_wedge_face_id == b.main_wedge_face_id
aperture_dir_a = a.vertex_end - a.vertex_start;
aperture_dir_b = b.vertex_end - b.vertex_start;
if dot( aperture_dir_a, aperture_dir_b ) > 0
% Same direction, construct a centered substitute
else
% Opposite direction, use opposite b face
merged_outer_edge_diffraction = a;
merged_outer_edge_diffraction.main_wedge_face_normal = a.opposite_wedge_face_normal;
merged_outer_edge_diffraction.main_wedge_face_id = a.opposite_wedge_face_id;
merged_outer_edge_diffraction.opposite_wedge_face_normal = b.opposite_wedge_face_normal;
merged_outer_edge_diffraction.opposite_wedge_face_id = b.opposite_wedge_face_id;
merged_outer_edge_diffraction.vertex_start = mean( [ b.vertex_start, a.vertex_end ], 2 );
merged_outer_edge_diffraction.vertex_end = mean( [ b.vertex_end, a.vertex_start ], 2 );
merged_outer_edge_diffraction.interaction_point = mean( [ a.interaction_point, b.interaction_point ], 2 );
end
elseif a.opposite_wedge_face_id == b.opposite_wedge_face_id
aperture_dir_a = a.vertex_end - a.vertex_start;
aperture_dir_b = b.vertex_end - b.vertex_start;
if dot( aperture_dir_a, aperture_dir_b ) > 0
% Same direction, construct a centered substitute
else
% Opposite direction, use opposite b face
merged_outer_edge_diffraction = b;
merged_outer_edge_diffraction.main_wedge_face_normal = b.opposite_wedge_face_normal;
merged_outer_edge_diffraction.main_wedge_face_id = b.opposite_wedge_face_id;
merged_outer_edge_diffraction.opposite_wedge_face_normal = a.opposite_wedge_face_normal;
merged_outer_edge_diffraction.opposite_wedge_face_id = a.opposite_wedge_face_id;
merged_outer_edge_diffraction.vertex_start = mean( [ a.vertex_start, b.vertex_end ], 2 );
merged_outer_edge_diffraction.vertex_end = mean( [ a.vertex_end, b.vertex_start ], 2 );
merged_outer_edge_diffraction.interaction_point = mean( [ b.interaction_point, a.interaction_point ], 2 );
end
elseif a.main_wedge_face_id == b.opposite_wedge_face_id
error( 'todo' )
elseif a.opposite_wedge_face_id == b.main_wedge_face_id
else
% Not sharing geometric face
end
end
function pps_merged = ita_propagation_paths_merge_anchors( pps, merging_gap )
%ita_propagation_path_merge_anchors Returns an altered set of propagation
% pats with potentially merged anchors where distances between paths are
% smaller than the merging gap
if ~isfield( pps, 'propagation_anchors' ) % not a list but only one path
error( 'Need a propagation path or path list' )
end
if nargin < 2
merging_gap = 17e-3; % wave length of 20 kHz at 340 m/s
end
assert( merging_gap > 0 )
N = numel( pps );
pps_merged = [];
for n=1:N
propagation_path = pps( n );
M = numel( propagation_path.propagation_anchors );
if M == 2
dist_vec = propagation_path.propagation_anchors( 2 ) - propagation_path.propagation_anchors( 1 );
if norm( dist_vec ) < merging_gap
warning( 'Direct sound path smaller than mering gap, skipped in merged paths' );
else
pps_merged( end ) = propagation_path;
end
continue
end
propagation_path_merged = propagation_path;
propagation_path_merged.propagation_anchors = propagation_path.propagation_anchors( 1 );
k = 0; % number of merged anchors
for m = 2:M-1
if isa( propagation_path_merged.propagation_anchors, 'struct' )
from_anchor = propagation_path_merged.propagation_anchors( m - k - 1 );
else
from_anchor = propagation_path_merged.propagation_anchors{ m - k - 1 };
end
dist_vec = propagation_path.propagation_anchors{ m }.interaction_point( 1:3 ) ...
- from_anchor.interaction_point( 1:3 );
if norm( dist_vec ) < merging_gap
propagation_path_merged.propagation_anchors{ m - k } = ita_propagation_merge_anchors( from_anchor, propagation_path.propagation_anchors{ m } );
k = k + 1;
else
propagation_path_merged.propagation_anchors{ m - k } = propagation_path.propagation_anchors{ m };
end
end
end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment