Create heatmap on unit sphere based on density of points

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])
Thanks Benjamin!
I used the slerp function to create some artificial traces of viewing angles between some quats:
%% Set up some quaternions
q1 = quaternion(0.890505,0.01626, 0.454606, 0.008301);
q2 = quaternion(0.881841, -0.167178, -0.431224, 0.09196);
q3 = quaternion(0.931789, -0.35778, 0.024018, 0.056444)
q4 = quaternion(0.931726,0.163413,0.266357,0.18503)
q5 = quaternion(0.897511, -0.3042, 0.31732, 0.035267)
T = 0:0.01:1;
quats = [slerp(q1,q2,T) slerp(q2,q3,T) slerp(q3,q4,T), slerp(q4,q5,T), slerp(q5,q2,T) slerp(q2,q4,T)];
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([180 -73])
The desired output would be, that the area in which those traces are on the sphere is marked yellow - red on the colormap. (The red arrow is only used to visualize the viewing angle without any manipulation.)

Sign in to comment.

Answers (0)

Categories

Products

Release

R2021b

Asked:

on 29 Jan 2022

Edited:

on 29 Jan 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!