jit.lcd -- How determine if a trapezoid contains an x,y pair?
I need to know how to determine if a specific x,y coordinate exists within a trapezoid defined in a jit.lcd object.
My guess I can get this done with the right formula in an expr object, but I'm wondering if there's a more "Max" way to do it.
I have a jit.lcd that's 640x480.
Within that, I have a trapezoid. It will be different shape (i.e., made of 4 different points) depending on different circumstances.
So, let's say within my 640x480 jit.lcd I have trapezoid defined by the 4 x,y coordinates:
22, 301
40, 419
35, 200
24, 150
Any easy way to determine if another x,y coordinate falls inside this trapezoid (or, conversely, falls outside of it)?
If nothing easy, anyone know the formula(s) I need to use in expr?
Thanks for any help.
Adam
I found a solution that works for me:
getpixel reports the color of each pixel in jit.lcd. I can adapt my program so my trapezoid is against a solid black background. So, using counters, I can use getpixel to report the color of each pixel in jit.lcd, and I can then store each non-black pixel, which is defines the set of pixels within the trapezoid.
This is a limited solution -- It would be shaky if my trapezoid were written on top of an image. Even if I do the opposite logic and only report on the exact color of the trapezoid, it's likely an image would have at least some pixels the same color as the trapezoid.
Would be happy to hear if anyone has better ideas.
Adam
> This is a limited solution -- It would be shaky if my trapezoid were
> written on top of an image. Even if I do the opposite logic and only
> report on the exact color of the trapezoid, it's likely an image would
> have at least some pixels the same color as the trapezoid.
>
> Would be happy to hear if anyone has better ideas.
>
> Adam
forgot what this algorithm is called but it can deal with any shapes
defined as xy pairs.
be warned - quick hack and not thoroughly tested...
#|
fredrikolofsson.com klippav.org musicalfieldsforever.com
|#
Thanks, I'll check it out.
Adam