Home > Back-end >  Find the objects that a line intersects in three.js
Find the objects that a line intersects in three.js

Time:11-27

Currently, I'm working on a three.js project where I should select two boxes from a board and draw a straight line connecting them, then I must highlight all the boxes that the line intersects. My big question now is how to to find which boxes the line intersects?

Any help would be appreciated (piece of code, links, material suggestion, math formulas)

CodePudding user response:

What you're describing sounds like you're looking for a Raycast.

You set up your ray (it's position and direction vector), and then use intersectObjects on the objects to get an array of the boxes the ray intersects.

CodePudding user response:

What I really needed in this case was bresenhams line algorithm, with this I can track all different points that the line crosses.

Found at https://www.geeksforgeeks.org/bresenhams-line-generation-algorithm/

Thanks Ivan and Diarmid, I know my code was a big mess and you tried to help me despite that.

  • Related