Create heatmap on unit sphere based on density of points
Show older comments
Hi everyone,
I want to plot a distribution of orientations represented by quaternions on a unit sphere.
So far, I was able to scatter the orientations on the surface of the sphere:
%% Set up some quaternions
q1 = quaternion(1, 0, 0, 0);
q2 = quaternion(0.990404, 0, -0.138204, 0);
q3 = quaternion(0.7, 0.7, 0.4, 0);
q4 = quaternion(0.977831, -0.086674, 0.078794, -0.17357)
q5 = quaternion(0.782331, -0.131658, -0.607212, -0.043797)
q6 = quaternion(0.968969, -0.185476, -0.14521, 0.074912)
q7 = quaternion(0.95241, -0.283423, 0.030797, -0.107881)
q8 = quaternion(0.991621, -0.001491, -0.004562, -0.129095)
q9 = quaternion(0.99887, -0.00186, -0.004424, -0.047293)
q10 = quaternion(0.981424, -0.101829, -0.143828, -0.075847)
quats = [q1, q2, q3, q4, q5, q6, q7, q8, q9, q10]
pts = rotatepoint(quats,[0 0 1]);
%% Create unit sphere
m=100;
[aa,bb,cc] = sphere(m);
h = surf(aa,bb,cc)
set(h, 'FaceColor',[0 0 1], 'FaceAlpha',0.1,'FaceLighting','gouraud','EdgeColor','none')
hold on;
%% Scatter orientation on unit sphere
scatter = scatter3(pts(:,1),pts(:,2),pts(:,3), 'filled')
alpha = 0.5;
set(scatter, 'MarkerEdgeAlpha', alpha, 'MarkerFaceAlpha', alpha)
%% Plot viewing direction as arrow
quiver3(0,0,0,0,0,1,'linewidth',5)
%% Figure settings
axis equal
xlabel('X')
ylabel('Y')
zlabel('Z')
view([177 -79])
This code results in the following plot:

The desired plot should look similar to this one

Has anyone an idea on how to achieve this ?
2 Comments
From the source paper: "The heatmap denotes the density of samples from the viewing direction determined by a ray from the origin through that point on the sphere."
As far as I can tell, we don't have any samples here, so we wouldn't be able to color the sphere properly. Nevertheless, perhaps seeing how to color the sphere by 1-abs(z) for now will be useful for when you have data from which to make the proper heatmap/coloring.
%% Set up some quaternions
q1 = quaternion(1, 0, 0, 0);
q2 = quaternion(0.990404, 0, -0.138204, 0);
q3 = quaternion(0.7, 0.7, 0.4, 0);
q4 = quaternion(0.977831, -0.086674, 0.078794, -0.17357);
q5 = quaternion(0.782331, -0.131658, -0.607212, -0.043797);
q6 = quaternion(0.968969, -0.185476, -0.14521, 0.074912);
q7 = quaternion(0.95241, -0.283423, 0.030797, -0.107881);
q8 = quaternion(0.991621, -0.001491, -0.004562, -0.129095);
q9 = quaternion(0.99887, -0.00186, -0.004424, -0.047293);
q10 = quaternion(0.981424, -0.101829, -0.143828, -0.075847);
quats = [q1, q2, q3, q4, q5, q6, q7, q8, q9, q10];
pts = rotatepoint(quats,[0 0 1]);
%% Create unit sphere
m=100;
[aa,bb,cc] = sphere(m);
h = surf(aa,bb,cc,1-abs(cc));
% set(h, 'FaceColor',[0 0 1], 'FaceAlpha',0.1,'FaceLighting','gouraud','EdgeColor','none')
set(h,'FaceAlpha',0.5,'FaceLighting','gouraud','EdgeColor','none')
colormap('jet');
colorbar();
hold on;
%% Scatter orientation on unit sphere
scatter = scatter3(pts(:,1),pts(:,2),pts(:,3), 'filled');
alpha = 0.5;
set(scatter, 'MarkerEdgeAlpha', alpha, 'MarkerFaceAlpha', alpha)
%% Plot viewing direction as arrow
quiver3(0,0,0,0,0,1,'linewidth',5)
%% Figure settings
axis equal
xlabel('X')
ylabel('Y')
zlabel('Z')
% view([177 -79])
Korbinian Hoermann
on 29 Jan 2022
Edited: Korbinian Hoermann
on 29 Jan 2022
Answers (0)
Categories
Find more on Color and Styling 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!
