How to generate the hsv cone graph using Matlab?

조회 수: 3 (최근 30일)
Salad Box
Salad Box 2023년 1월 10일
답변: Kevin Holly 2023년 1월 13일
Hi
I saw the hsv cone graph on Mathworks webpage
I am wondering how to generate this graph using Matlab.
Any advices would be great. Doesn't have to be the full code.

답변 (1개)

Kevin Holly
Kevin Holly 2023년 1월 13일
Here is a starting point. I made some modifications from this code:
H = repmat(linspace(0, 1, 100), 100, 1); % 100-by-100 hues
S = repmat([linspace(0, 1, 50) ... % 100-by-100 saturations
linspace(1, 0, 50)].', 1, 100); %'
V = repmat([ones(1, 50) ... % 100-by-100 values
linspace(1, 0, 50)].', 1, 100); %'
hsvImage = cat(3, H, S, V); % Create an HSV image
C = hsv2rgb(hsvImage); % Convert it to an RGB image
% Next, create the conical surface coordinates:
theta = linspace(0, 2*pi, 20); % Angular points
X = [zeros(1, 20); ... % X coordinates
cos(theta); ...
zeros(1, 20)];
Y = [zeros(1, 20); ... % Y coordinates
sin(theta); ...
zeros(1, 20)];
Z = [2.*ones(2, 20); ... % Z coordinates
zeros(1, 20)];
% Finally, plot the texture-mapped surface:
figure
surf(X, Y, Z, C, 'FaceColor', 'texturemap');
axis equal
figure
surf(X(:,1:16), Y(:,1:16), Z(:,1:16), C(1:80,1:80,:), 'FaceColor', 'texturemap');
axis equal
view(30,32) % Adjust camera angle
hold on
patch(X(:,16), Y(:,16), Z(:,16),C(80,80,:)) % add interior purple face
patch(X(:,1), Y(:,1), Z(:,1),[1 0 0]) % add interior red face

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by