Calculates whether or not a given point (red dot / pointX and PointY) is inside a given shape (shapePoints / purple dots). This algorithm is designed to be used within a GLSL shader and assumes that all given points of the shape are connected via a straight line, sequentially. ---You may use this without credit, it should be very useful for something like a physics engine where hitboxes are arbitrary shapes. Personally, I'm using it to determine what fragments to keep or discard inside of a tri in openGL.
Made this for an engine I'm working on in C++ and OpenGL. Could be optimized better for Scratch, but I'm mostly only using it in GLSL so I may get around to optimizing it or may not. First, it scans through all of the points' X and Y positions and finds the maximum and minimum X and Y values of the shape. This is then used to form a rectangle around the shape. Then, a line segment is created from the top-middle of the rectangle to the point being checked. If this line segment intersects with an odd number of the shape's line segments, then the point is inside the shape. If it intersects an even number of times it is outside of the shape.