Advertisement

Author Topic: line of sight  (Read 285 times)

0 Members and 1 Guest are viewing this topic.

Offline alimag

  • Contributing Member
  • **
  • I'm a llama!
line of sight
« on: 13 Nov 2009, 20:39:22 »
Hi,

Is there a short and efficient way to find if a straight line, from point A to point B, will cross inside a rectangular area like a marker or a house boundingbox for example?

I've tried moving a logic along the line and check every meter if it's in the rectangle and it works most of the time but this is probably the ugliest solution to the problem and it's not reliable.

I should have listen my geometry teacher when I was in college.

Thanks in advance

Cheers
« Last Edit: 13 Nov 2009, 20:41:34 by alimag »

Offline Trexian

  • Members
  • *
Re: line of sight
« Reply #1 on: 13 Nov 2009, 21:00:51 »
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.  :blink:
Sic semper tyrannosauro.

Offline Wolfrug

  • Addons Depot
  • Administrator
  • *****
  • Official OFPEC Old Timer
Re: line of sight
« Reply #2 on: 13 Nov 2009, 22:50:09 »
SPON LOS for ArmA is basically what you want, although I'm not sure how compatible it is with A2. Knowing Spooner though, it's likely to function just fine, since it's mostly math anyway!

I couldn't tell you how to make it work, but as mentioned, the math should be all there. Good luck!

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline alimag

  • Contributing Member
  • **
  • I'm a llama!
Re: line of sight
« Reply #3 on: 14 Nov 2009, 03:08:59 »
Hi,

@ Trexian

Thanks for your answer but to be honest I think I need a scotch to after reading it...

@ Wolfrug

Thank you very much for the link.
Might be in the line of what I need. I'll get a look.

Cheers

EDIT

I just checked the SPON LOS topic and the link to the script/demo is dead.
(404 - Attachment Not Found)
Is there anywhere else I could find this script?

Thanks in advance

PS: This guy seems to know what he is talking about. I will print the topic and read it carefully. Thanks
« Last Edit: 14 Nov 2009, 03:17:38 by alimag »