# Math Problem using Shaders and GLSL

Hi dear community,

I have a polygon (for simplicity we can assume it is a cube) as shown in Picture 1 where each vertex has an attribute value as indicated in Picture 2. I would like to cut the cube with an infinite plane. The resultant shape is a plane with 4 points. I would like to calculate the resulting attribute value for each point of the plane by linear interpolation (Picture 3).

The end goal is to provide colors (vertex colors or face colors) to this plane based on some color legend.

I suspect the best way to achieve this is through some shaders and GLSL.

Any suggestions from where to start or some similar examples of how to do this.

Thanks a lot

You could do that with shaders and GLSL and stuff, but it would be hard. Why? Because you donâ€™t know ahead of time how many edges/triangles you would need to cut ahead of time, and doing it in a distributed manner just isnâ€™t trivial. You could throw every triangle at the GPU and ask if itâ€™s being cut by the plane, but thatâ€™s not optimal and youâ€™d have to assemble things on the CPU anyway.

Anyway, enough of the reasons why itâ€™s not a good idea, the actual solution is along the lines of â€ścuttingâ€ť or â€śslicingâ€ť a mesh with a plane. Or â€śbisectingâ€ť. Try searching for that, I remember at least a few topic here on the forum that deal with this exact problem as well as a handful of github projects that do the same. Good luck!

1 Like