containsPoint does not exist...

edited January 2014 in Questions about Code

I'm currently working on a project, where i've loaded an background image and i want to draw about it when the mouse is pressed. Therefore i've determined an area consisting of four vectors.
If the mouse is pressed and inside the are the user should be able to draw. Instead Processing gives me the error "The funtion containsPoint(PVector[],int,int) does not exist." but i've just this function in another sketch and int worked.

Do you have any hints why i keep getting an error?

Here's the code:

Thank's in advance! :)


  • Answer ✓

    Processing doesn't have a containsPoint() wrapper function, you'll have to write your own or copy it from this thread and paste it at the end of your sketch. ;)

    Or simply take this optimized version:

    boolean containsPoint(PVector[] verts, float px, float py) {
        boolean oddNodes = false;
        for(int i = 0, j = verts.length - 1; i < verts.length; j = i, i++) {
            PVector vi = verts[i];
            PVector vj = verts[j];
            if((vi.y < py && vj.y >= py || vj.y < py && vi.y >= py) && (vi.x + (py - vi.y) / (vj.y - vi.y) * (vj.x - vi.x) < px))
                oddNodes = !oddNodes;
        return oddNodes;
  • Wow, didn't know that. Now it's awesome! Thank you very much! :)

  • No problem. :)

Sign In or Register to comment.