2 Replies Latest reply on Apr 21, 2006 2:02 PM by Gionex

    Find where two lines join?

    Gionex
      Hey
      My guy shoots at a tile, this tile is 30 x 30 and is a square. The angle of my shooting dude's gun is known and the bullet will end at the tile. So far I have found which tile my gun's bullet will end at but not the exact edge/point is know so I need to know...
      How do I find where to "theroretical" lines join. I know the start and end cooodinates of each line but I dont know "mathematically" how to find out where they cross? There must be a way! If it is any help one of the lines is always 30 and either horizontal of vertical and I know the start points, end points and angle of the other line.
      Thanks for your help
      Dan
        • 1. Re: Find where two lines join?
          blemmo Level 1
          Hi,

          so you didn't pay attention in geometry class, eh? ; )
          Had to find this out myself not long ago, so here's my solution. Seems to work, but there's a slight chance of dividing through 0, so you should check the result for NaN or Infinity (which will also be returned if the lines don't intersect).
          But if you already know that the lines interset this shouldn't be an issue.
          The 'line' parameters are objects of the form {x1:startX, y1:startY, x2:endX, y2: endY}, the result is an object with a 'x' and 'y' property.

          cheers,
          blemmo

          • 2. Re: Find where two lines join?
            Gionex Level 1
            Thanks, I think ill put this in my "goodies" bag for later on because i need to find which side it needs to calculate which will need another MASSIVE sum.
            Thanks for your help
            Dan