Shape intersection (or a way to do raster)


I have a set of vectorial shapes (in processing, p5, inkscape…) that combined form a image. All shapes have solid colors and a layer ranking (I know which one is on top).

All I want to do is, setting a new (“random” like a square, or circle…) shape, discover the average color of the intersection (I can’t trust the monitor pixel size like in raster options).

I did an extensive researched and I have talked to everyone I know but i have no clue on how to solve this, can someone give me a hint?

Thank you

Is this data in a p5 sketch, e.g. with PShapes, or is this in an SVG file, or something else?

What intersection? Can you give a concrete example? You said you have layer ranking, so there are many shapes. If you add a random shape, won’t it have many intersections? Are you trying to find color for only the intersection(s) with the next shape down in the stack, or all intersections with all shapes?

Thank you for the reply.

I’ll add an image and try to explain it better.

Consider a vector image (represented by the yellow rectangle, blue circle and red star).
I have the information for all the shapes in the figure (ideally an .svg file).

Consider 3 square regions of interest (ROI), A, B, and C.

Region A is filled only with the background color, so the average color is yellow.
Region B is filled only with blue, and althought there is “yellow” under it, the average color “on top” is blue.
Region C is in the intersection of 3 shapes. What I want is the average color based on the “percentage” filled by each color.


Now, imagine that instead of this vector image I have a really complex one with more than 1000 shapes and, instead of a square, the ROI were a circle, or a star…

My question is: How to code this?
My only idea is to check all shapes superposition manually with the ROI, do several boolean operations to separate only the “visible on top” part, calculate each area and do the color average math manually.

I bet there is an easier way.

Thank you!

PS: The average color math is easy (