Plotting a spherical "heatmap" onto a sphere divided into segments of equal surface area
10 views (last 30 days)
Show older comments
I'm brand new to Matlab so I apologize in advance if I don't seem to articulate my problem well enough, but please bare with me. I have sets of data points described in spherical coordinates that need to be mapped onto a unique spherical surface, that is segmented in roughly equal "bins" of surface area, rather than segmented equally by degrees which seems to be Matlab's default.
Using some older code I'm able to generate the sphere I'm talking about and get the data plotted onto the surface (see attached images). However, I need to transform the point-by-point map into some type of "heatmap," where each of those bins on the sphere is colored according to how many of those data points fall within it. I'm totally lost on how to go about approaching a problem like this, and I'm grateful for any help I can get on this.
0 Comments
Answers (1)
Alistair Jones
on 23 Sep 2020
Hi Lmac,
It isn't possible to have a coordinate system which has orthogonal axis and is shap preserving.
I came across a similar problem when trying to visualise the distribution of surface orientation for triangulation. My approach was to just normalise by the area instead. (little bit of a hack but had a good effect )
function [xs,ys,zs,as] = sphereHeatmap(az,el,w,n)
%% Function returns points for a heatmap mapped onto a unit sphere surface
% Inputs: az (n by 1) - azimuth (radians), el (n by 1) - elevation (radians)
% w (n by 1) - weighted value of points, n - number of bins is 2*n (integer)
% Outputs are of size (n+1) by (n+1)
% outputs can be used as surf(xs,ys,zs,as):
n_n = (-n:1:n);
%Round points to nearest integer n
azInt = round(az*2*n);
elInt = round(el*2*n);
%Generate spherical meshgrid
sintheta = sin(n_n*pi/n); sintheta(1) = 0; sintheta(2*n+1) = 0;
cosphi = cos(n_n'*pi/(2*n)); cosphi(1) = 0; cosphi(2*n+1) = 0;
xs = cosphi*cos(n_n*pi/n);
ys = cosphi*sintheta;
zs = sin(n_n'*pi/(2*n))*ones(1,2*n+1);
as = (cosphi*ones(1,2*n+1)); %Area of local small surface
indi = n_n==az;
indj = n_n==el;
for i = 1:2*n+1
for j = 1:2*n+1
if as(i,j)~=0
area_temp = sum(w((indi(:,i).*indj(:,j))==1),'all');
if as(i,j)~=0 % Ignore faces with zero surface area
as(i,j) = 100*area_temp./(sum(w)*(as(i,j))); %Normalise
end
end
end
end
end
1 Comment
iontrap
on 24 Apr 2024
Edited: iontrap
on 24 Apr 2024
Hi Alistair,
I am trying to produce a plot similar to what you've attached. I am trying your code - what are the input vectors in your function? How can I relate my 3D scatter data to this function? Maybe if it is possible, you could include either the code or txt file of data used to acquire the image you attached?
I attach an image of the data for which I'd like to make a heatmap. The 3D points are confined to a spherical surface of arbitrary radius. Data in three dimensions of cartesion x, y, and z coordinates are vectors of arbitrary length.
Thanks,
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!