Coloring in MATLAB

I try to animate the ball by bouncing, but without having the problem of creating the main multi-color ball, I can then rotate as a whole in each frame. I have 512 points on the circumference of a ball divided into 8 sectors, each of which has a different color. So far I have 2 matrices that are 8x64, representing the x and y coordinates of the points along the circumference of the ball, each of which is its own sector.

I want to know how to fill these β€œranges” in a circle so that it looks like a beach ball, creating a function to do this using two coordinate matrices x and y as input. Your help will be greatly appreciated!

The main skeletal function:

% Expects 8xN x and y point matrices
function draw_ball(x,y)
% Draw the 8 sectors filling them with unique colors

end
+3
source share
2

PATCH draw_ball. , , 8xN, 8 , .

, :

function pH = drawBall(x,y)

%# count sectors
nSectors = size(x,1);

%# create a colormap
ballColors = jet(nSectors);

%# set hold-state of current axes to 'on'
set(gca,'nextPlot','add')

%# initialize array of plot handles
pH = zeros(nSectors,1);

%# add [0,0] to every sector
x = [x,zeros(nSectors,1)];
y = [y,zeros(nSectors,1)];

%# plot patches
for s = 1:nSectors
   %# plot sectors with black lines. If there shouldn't be lines, put 'none' instead of 'k' 
   pH(s) = patch(x(s,:),y(s,:),ballColors(s,:),'EdgeColor','k');
end
+2

(x, y) () , . matlab cart2pol

, 8 ... - floor(polar_anle_in_radians/(2*pi)*8)

0

Source: https://habr.com/ru/post/1775922/


All Articles