Open this sketch in P5 Web Editor →
Drag the orange rectangle in the canvas below. It must be fully within the beneath zone (under the blue surface) to register as "beneath". Notice the arrows showing the beneath direction.
BENEATH means positioned under something, often with the implication of being covered or hidden. While similar to "below," beneath suggests a closer, more intimate spatial relationship.
To create "beneath" relationships on screen:
let zoneY = surfaceObject.y + surfaceObject.height;
let zoneHeight = 60;
object.y >= zoneY && object.y + object.height <= zoneY + zoneHeight
object.x >= surface.x && object.x + object.width <= surface.x + surface.width
let surfaceObject = {x: 50, y: 100, width: 300, height: 10};
let beneathObject = {x: 170, y: 30, width: 60, height: 40};
let zoneY = surfaceObject.y + surfaceObject.height;
let zoneHeight = 60;
let isFullyBeneath = (beneathObject.y >= zoneY &&
beneathObject.y + beneathObject.height <= zoneY + zoneHeight &&
beneathObject.x >= surfaceObject.x &&
beneathObject.x + beneathObject.width <= surfaceObject.x + surfaceObject.width);
rect(surfaceObject.x, zoneY, surfaceObject.width, zoneHeight); // Zone
line(x, surfaceY, x, zoneY + 25); // Arrow lines