How to color grids underneath a curve and also gradient the grids depending on how much is within curve?
2 views (last 30 days)
Show older comments
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])
0 Comments
Answers (1)
Matt J
on 11 May 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]);
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])
0 Comments
See Also
Categories
Find more on Colormaps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!