Borrar filtros
Borrar filtros

Using fill to color multiple polygons using input RGB color values.

14 visualizaciones (últimos 30 días)
Mohamed Abd El Raheem
Mohamed Abd El Raheem el 29 de Mzo. de 2021
Comentada: darova el 30 de Mzo. de 2021
Greetings:
I have a problem using "fill" to produce two polygons, each with a color defind by rgb values. The following code defines two matrices, xx and yy, with columns representing the vertices of the two polygons. A 3D matix c, contains the rgb values of the colors.
Using "fill" in the form : fill(x1,y1,c1,x2,y2,c2, ...) to color each polygon, works fine. But using it in the manner fill(xx,yy,c) doesn't produce the correct colors. So, how to fix that to use it in the latter way?
xx = [0 0 1 1 0; 1 1 2 2 1]';
yy = [0 1 1 0 0; 0 1 1 0 0]';
c(1,1,:) = [0.6 0.6 0.8];
c(2,1,:) = [0.3 0.3 0.4];
figure;fill(xx,yy,c);
figure;fill(xx(:,1),yy(:,1),c(1,1,:),xx(:,2),yy(:,2),c(2,1,:));
The output figures of the code are here:

Respuestas (1)

darova
darova el 30 de Mzo. de 2021
Try this
[x,y] = meshgrid(0:2,0:1);
c1(1,1,:) = [0.6 0.6 0.8];
c2(1,1,:) = [0.3 0.3 0.4];
c = [c1 c2 c2;c1 c2 c2];
surf(x,y,x*0,c)
view(0,90)

Categorías

Más información sobre Elementary Polygons en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by