I am looking to identify the indexes [x, y]
for grid cells that intersect with a quadrilateral shape characterized by its corner coordinates;
- each grid cell measures
128 x 128 px
grid cells are assigned an integer index between
[-nx, -ny]
and[nx, ny]
(the maximum area covered is a square measuring(2nx * 128) * (2ny * 128) px
)the quadrilateral's shape is delineated by corner points with pixel-space coordinates
(qx, qy)
supplied in the order of(tl, tr, br, bl)
- This task is integrated into a three.js scene:
- The corner points/coordinates are determined via raycasting from the camera on a base THREE.PlaneBufferGeometry
How can I efficiently obtain all intersecting tiles using JavaScript?
Currently, my approach involves calculating perimeter tiles by traversing each edge of the quadrilateral utilizing mx + b
with a step equal to the tile dimension (128px
); then, I add interior tile indexes row by row. However, this method seems somewhat cumbersome, which could be due to coding skills. I am considering using THREE.Raycaster to acquire the perimeter tile indexes, but I am unsure of the process.
I am in search of a more optimized solution algorithmically; whether it be basic formulas, pseudo code, concepts, or definitive solutions.