How to color grids underneath a curve and also gradient the grids depending on how much is within curve?

2 visualizaciones (últimos 30 días)
Hi,
I have a grid that exists underneath an arc. I want to color each grid underneath the arc any color. If the entire grid is under the curve, I want the color to be max intensity. If the grid is on the edge of the arc, I want the grid to be varying levels of intensity in color shade. For example, if it is 50% above the curve and 50% below the curve, I will have the greyscale at half the color of the grid that is fully underneath the curve. What is a good way to do this?
here is my simple code that has the grid and the arc curve :)
xCenter = 10;
yCenter = 10;
radius = 10;
theta = linspace(180, 270, 50);
x = radius * cosd(theta) + xCenter;
y = radius * sind(theta) + yCenter;
plot(x, y);
axis ([ 0 24 0 24]);
grid on;
set(gca,'DataAspectRatio',[1 1 1])
xticks(0:1:10)
yticks([0:1:10])

Respuestas (1)

Matt J
Matt J el 11 de Mayo de 2021
One way,
xCenter = 10;
yCenter = 10;
radius = 10;
theta = linspace(180, 270, 50);
x = radius * cosd(theta) + xCenter;
y = radius * sind(theta) + yCenter;
pgon=polyshape([x,flip(x)],[y,0*y]);
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
plot(pgon,'FaceAlpha',area(pgon)/100);
axis ([ 0 24 0 24]);
grid on;
set(gca,'DataAspectRatio',[1 1 1])
xticks(0:1:10)
yticks([0:1:10])

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by