Question

Is there a Java graphics library that will rasterize a triangle given the coordinates of the vertices?

I'm trying to analyse the pixel values of an image for the triangular region defined by three points. I have the pixel values in memory, so I just want to figure out which pixels are in the triangle and iterate through them. The order of iteration is irrelevant, so long as I visit each pixel once.

I've done some searching for algorithms, and I think I could implement my own code based on Triangle Rasterization for Dummies, or an Introduction to Software-based Rendering, but I'd feel stupid if I overlooked some library that already implements this.

I briefly looked at getting Java to talk to the GPU, but that seems to be too much hassle.

Was it helpful?

Solution

You can use Polygon Shape to represent the tringle. Then use one of the contains() method passing Point2D or just two doubles params.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top