function polarity_voting(picks_height, picks_angle, picks_segments)
% Find the "average angle" of each segment.  

picks_angle_exp = exp(i * deg2rad(picks_angle));
picks_angle_weighted = picks_height .* picks_angle_exp - picks_antiheight .* picks_angle_exp;

for n=1:n_segments,
  segment_angle_avg(n) = rad2deg(angle(sum(picks_angle_weighted(find(picks_segments == n)))));
end

picks_angle_segavg = segment_angle_avg(picks_segments); %% ??
picks_polarity = cos(deg2rad( picks_angle - picks_angle_segavg ));
picks_polarity_reversed = find(picks_polarity < 0);

% reverse those who have the wrong polarity

% picks_angle(picks_polarity_reversed) = picks_angle(picks_polarity_reversed) + 180;


