Filter löschen
Filter löschen

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

14 Ansichten (letzte 30 Tage)
Mohamed Abd El Raheem
Mohamed Abd El Raheem am 29 Mär. 2021
Kommentiert: darova am 30 Mär. 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:

Antworten (1)

darova
darova am 30 Mär. 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)

Kategorien

Mehr zu Elementary Polygons finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by