it helps some times Project the polyhedron in the direction of the ray, and your problem reduces to 2D, and finding which triangle encloses the origin. To test a single triangle, consider whether a given directed line segment (AB) is going clockwise or counterclockwise with respect to the origin. This is easy to determine with a simple cross-product test: it's counterclockwise iff A x (B-A) > 0. If all three sides of a triangle have the same sense (clockwise or counterclockwise) then the triangle encloses the origin and that's the face you want.
How do I draw squares on top of applications, get coordinates/size of the squares, and check to see if the image beneath
wish of those help Using Java, Zoom uses createScreenCapture() to render an enlarged 16 x 16 pixel BufferedImage taken as the mouse is dragged across the screen. Once you have the BufferedImage, you can periodically recapture the screen at the same point and use the getRGB() method to compare. See also Using Timers in Swing Applications.
Running the Optimal Flood Fill on a Grid While Limited to just Non-Intersecting Squares
may help you . Gareth Rees posted a very nice answer to this question that expands on David Eppstein's answer at Math Overflow citing multiple authors. In a sentence, the algorithm, which yields optimal solutions, is first to cut a maximum noncrossing set of lines between concave vertices (found in polynomial time by maximum independent set in a bipartite graph) and then to extend these cuts greedily so that the remaining faces are rectangles. Finding a MIS in a bipartite graph requires a maximum matching algorithm. If this is too much work, then just the greedy step, where a vertical cut is made from each concave vertex, is a 2-approximation.
wish help you to fix your issue Lets think a bit how we could represent the intersecting area between two squares. Surely, one of the ways to do is simply to represent it as another rectangle, whose color we simply change based on the intercepting area. To draw a rectangle, we need to know the coordinates of the upper left corner, the width and the height. Therefore the challenge is to calculate those as we drag our squares around. This should be done in the draw() function. You already have the intersection check implemented, whats left is to calculate the new rectangle upper left point (newX, newY), width (newW) and height (newH).