1

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.

Community
  • 1
  • 1
Don Kirkby
  • 53,582
  • 27
  • 205
  • 286

1 Answers1

3

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

StanislavL
  • 56,971
  • 9
  • 68
  • 98