I guess it might make a difference if you mean a 2d line or 3d? Take elevation out of it, and I think it would be (relatively) easy to determine if a straight line passes within x meters of a point. Use the pos array as the center spot, then the bounding box information for the +/- values from that spot. Like, for 2d, you really only want to know whether the line AB intersects a line segment set perpendicular to AB with the center at the position array.
For 3d, it becomes more complicated with the angles, but I think the same principles would apply.
(Sorry if this doesn't really help.)
Thinking about it more, as a function, you could do it by measuring distances from the center position C, and using the vector between A and B.
- check if either A or B is within the bounding box area.
That'll make the routine shorter!
- get vector from A to C, if it isn't within a few degrees* ignore the whole thing
- get distance and vector from A to B; and a distance from A to C and B to C
- pick a spot X half way from A to B on the vector
- check if X is within the bounding box area
- if not, then figure out which is further away from C - either A or B - and replace it with X (that should make sure you keep narrowing on on the point on the line AB that is closest to C
- and get the distance/vector/half way point again
- probably include a check so that if X is only moving by a few meters, then that's the end of the analysis
Oof. That still looks pretty ugly. Hopefully someone else who knows what they're doing will see this.
*
I guess the real trigonometry way would be to start with the vector and distance from A to C, and the size of the object. Figure out how many minutes of angle (? I think that's right) the object takes up. Get the vector from A to B, and if it is within the vector +/- the size of the object, then it intersects.
But, that is stretching the very limits of my math brain. Now, I need a scotch.