Skip to content

Instantly share code, notes, and snippets.

@CitizenInsane
Created July 20, 2012 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CitizenInsane/3150662 to your computer and use it in GitHub Desktop.
Save CitizenInsane/3150662 to your computer and use it in GitHub Desktop.
Failing to emphase some region using transparency on a spherical surface
%% Main function
function [] = EmphaseSelectedRegion()
%[
% Create data
[X, Y, Z, Data] = createTestData();
% Select max - xxdB region
maxData = max(max(Data));
W = ones(size(Data));
W(Data < (maxData/1.2)) = 0;
% Plots
figure(1)
subplot(2, 2, 1)
surf(X, Y, Z, Data); shading interp; title('The data'); colorbar;
subplot(2, 2, 2)
surf(X, Y, Z, W); shading interp; title('The selected area'); colorbar;
subplot(2, 2, 3)
WAlpha = 0.5 + 0.5*W; % non selected => alpha = 0.5, selected ==> alpha = 1.0
surf(X, Y, Z, WAlpha); shading interp; title('Alpha value'); colorbar;
subplot(2, 2, 4); %%%%% Here non selected area is not appearing with an alpha = 0.5 %%%%%
surf(X, Y, Z, Data, 'AlphaData', WAlpha, 'FaceAlpha', 'interp'); shading interp; title('Emphased data (not working)'); colorbar;
%]
%% Function for creating test data
function [X, Y, Z, Data] = createTestData()
%[
DEG2RAD = pi / 180;
% Define spherical measurement grid
azimuths = linspace(0, 360, 361) * DEG2RAD;
elevations = linspace(0, 180, 181) * DEG2RAD;
% Define spots location and spreading
spotAzim = [45 180 -45] * DEG2RAD;
spotElev = [45 90 135] * DEG2RAD;
spotSigma = [45.0 35.0 55.0] * DEG2RAD;
% Transform grid to cartesion
[A, E] = ndgrid(azimuths, elevations);
X = cos(A) .* sin(E);
Y = sin(A) .* sin(E);
Z = cos(E);
% Define the data
Data = zeros(size(A));
count = length(spotAzim);
for ki = 1 :count,
% Transform spot to cartesion
xspot = cos(spotAzim(ki)) .* sin(spotElev(ki));
yspot = sin(spotAzim(ki)) .* sin(spotElev(ki));
zspot = cos(spotElev(ki));
% Compute angle between spot and each point in measurement grid
DP = X * xspot + Y * yspot + Z * zspot;
CPX = Y * zspot - Z * yspot;
CPY = Z * xspot - X * zspot;
CPZ = X * yspot - Y * xspot;
CP = CPX .* CPX + CPY .* CPY + CPZ .* CPZ;
Delta = atan2(CP, DP);
% Create spot values
ll = exp(- Delta.^2 / (2*spotSigma(ki)^2));
ll = ll / max(max(ll));
Data = Data + ll;
end
%]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment