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!
Thank you very much for your answer.
I will try something and provide updates if any !
@GiBelle you can take each pair of vertices and convert them into an equation, then you can find where the line intersects the plane (if it happens), check if that point is in the segment between the two vertices, if that is, then we have an intersection.
Some optmizations can be done, like checking if the segment cross the plane before calculating its line equation. But even with that, this would be too slow to do in a GPU.