I won't provide code at this point, but here is a simple strategy that you might use.
First, apply an AffineTransform
rotation to the image so that the "green" line in your sketch is aligned on the horizontal axis, and the provided point is at the origin. Then crop the image to a single pixel height. Then obtain the image's raster in a specific encoding that will be easy to work with. And finally, walk each pixel in the Raster
, until you reach the first pixel of the given color. You might then need some adjustment of that distance in order to account for the rotation angle.