# Find where two lines join?

**URL:** <https://forum.kirupa.com/t/find-where-two-lines-join/186498>\
**Category:** programming\
**Created:** [April 21, 2006, 7:10pm UTC](https://forum.kirupa.com/t/find-where-two-lines-join/186498 "2006-04-21T19:10:19Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![GNXDan](https://avatars.discourse-cdn.com/v4/letter/g/f05b48/32.png) [@GNXDan](https://forum.kirupa.com/u/GNXDan)\
**Post date:** [April 21, 2006, 7:10pm UTC](https://forum.kirupa.com/t/find-where-two-lines-join/186498/1 "2006-04-21T19:10:19Z")

</div>

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 😃

---

<div class="post-metadata">

**Author:** ![joran420](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joran420/32/2329_2.png) [@joran420](https://forum.kirupa.com/u/joran420)\
**Post date:** [April 21, 2006, 7:49pm UTC](https://forum.kirupa.com/t/find-where-two-lines-join/186498/2 "2006-04-21T19:49:11Z")

</div>

I need to figure this out for my program too…

A quick google got me  
[http://id.mind.net/~zona/mmts/intersections/intersectionOfTwoLines1/intersectionOfTwoLines1.html](http://id.mind.net/~zona/mmts/intersections/intersectionOfTwoLines1/intersectionOfTwoLines1.html)

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [April 21, 2006, 8:20pm UTC](https://forum.kirupa.com/t/find-where-two-lines-join/186498/3 "2006-04-21T20:20:35Z")

</div>

It’s some basic math, you need to find the slope and y intercept of each line then set the equations equal to each other.

**Equation of a Line**  
y = mx + b  
[LIST]  
[_]m is slope  
[_]b is y intercept[/LIST] **Finding Slope From Two Endpoints**  
m = (y2 - y1) / (x2 - x1)

Simply plug the coordinates of your end points into that equation and you have your slope.

**Finding Y Intercept**  
Using the equation of a line, you can calculate the y intercept of the function.

b = y / mx  
[LIST]  
[_]m is slope  
[_]y is the y component of any coordinate on the line (you can use the endpoints)  
[\*]x is the x component of that same coordinate[/LIST] **Finding X Component of Intersection**  
At the intersection of two lines, the Y and X components are equal so all you need to do is set the equations of the two lines equal to each other and solve.

x = (b1 - b2) / (m2 - m1)

**Finding Y Component of Intersection**  
Now just sub the newly found X value into either of the equations and solve for Y.

Hope this helps 🙂

---

<div class="post-metadata">

**Author:** ![joran420](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joran420/32/2329_2.png) [@joran420](https://forum.kirupa.com/u/joran420)\
**Post date:** [April 21, 2006, 9:15pm UTC](https://forum.kirupa.com/t/find-where-two-lines-join/186498/4 "2006-04-21T21:15:39Z")

</div>

\<3 im not the OP but thanks canadian u just made my life easier

---

<div class="post-metadata">

**Author:** ![GNXDan](https://avatars.discourse-cdn.com/v4/letter/g/f05b48/32.png) [@GNXDan](https://forum.kirupa.com/u/GNXDan)\
**Post date:** [April 21, 2006, 9:30pm UTC](https://forum.kirupa.com/t/find-where-two-lines-join/186498/5 "2006-04-21T21:30:14Z")

</div>

Thanks i tried this other one and it works but I think ill have to do a “cheapy” way because its like impossible to find the correct side to check against.  
Thanks for your help again  
Dan

---

<div class="post-metadata">

**Author:** ![dbarbarian](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/dbarbarian/32/609_2.png) [@dbarbarian](https://forum.kirupa.com/u/dbarbarian)\
**Post date:** [April 22, 2006, 3:26am UTC](https://forum.kirupa.com/t/find-where-two-lines-join/186498/6 "2006-04-22T03:26:17Z")

</div>

Vectors. Give that a shot and see if it helps.

> **['The Pass' has a Bunch of Browser Based Games - To NY pa...](http://tonypa.pri.ee/pass-browser-based-games/)**
>
> This page has interesting information regarding 'The Pass' which has nothing but fun browser based and all sorts of other games all around New York City.

---

<div class="post-metadata">

**Author:** ![joran420](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joran420/32/2329_2.png) [@joran420](https://forum.kirupa.com/u/joran420)\
**Post date:** [April 22, 2006, 5:44am UTC](https://forum.kirupa.com/t/find-where-two-lines-join/186498/7 "2006-04-22T05:44:33Z")

</div>

wow that link is nice man

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [April 22, 2006, 9:46am UTC](https://forum.kirupa.com/t/find-where-two-lines-join/186498/8 "2006-04-22T09:46:33Z")

</div>

You may also want to look at this:  
[http://www.kirupa.com/forum/showthread.php?t=195433](http://www.kirupa.com/forum/showthread.php?t=195433)

:s:

---

<div class="post-metadata">

**Author:** ![GNXDan](https://avatars.discourse-cdn.com/v4/letter/g/f05b48/32.png) [@GNXDan](https://forum.kirupa.com/u/GNXDan)\
**Post date:** [April 22, 2006, 1:07pm UTC](https://forum.kirupa.com/t/find-where-two-lines-join/186498/9 "2006-04-22T13:07:53Z")

</div>

Wow im using the tonypa engine as a guide, but I dont like some features of it + I have made it simpler+better+added shooting which I will submit somewhere when i finish. I never seen that part of the tonypa site before, thanks!

---

<div class="post-metadata">

**Author:** ![cobrasniper555](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@cobrasniper555](https://forum.kirupa.com/u/cobrasniper555)\
**Post date:** [April 22, 2006, 7:00pm UTC](https://forum.kirupa.com/t/find-where-two-lines-join/186498/10 "2006-04-22T19:00:23Z")

</div>

Ok…I’m confused, how would you use the slope-intercept method of getting a line to slope?  
How would the slope-int. be written out? Like this?

```auto
line._y = m*line._x+b;

```

and have the line repeat itself in an enterFrame listener? All I want to know is how to draw a line with the slope-intercept method. I know how to with other methods, but this one is…more interesting.

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [April 22, 2006, 8:17pm UTC](https://forum.kirupa.com/t/find-where-two-lines-join/186498/11 "2006-04-22T20:17:28Z")

</div>

You have to plot it with incremented values of x:

```auto
var m:Number = 1;
var b:Number = 0;
this.lineStyle(1);
for (var x:Number = 0; x < Stage.width; x++) {
 this.lineTo(x, m * x + b);
}

```

Or I suppose if you wanted to you could just find two points along the line and draw between them:

```auto
var m:Number = 1;
var b:Number = 0;
var sx:Number = 0;
var ex:Number = Stage.width;
this.lineStyle(1);
this.moveTo(sx, m * sx + b);
this.lineTo(ex, m * ex + b);

```

You also have to remember that Flash’s y-axis is reversed, so down is positive. You can compensate for this if you want:

```auto
var m:Number = 1;
var b:Number = 0;
var sx:Number = 0;
var ex:Number = Stage.width;
this.lineStyle(1);
this.moveTo(sx, -m * sx + (b + Stage.height));
this.lineTo(ex, -m * ex + (b + Stage.height));

```

Hope this helps :sc:

---

<div class="post-metadata">

**Author:** ![cobrasniper555](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@cobrasniper555](https://forum.kirupa.com/u/cobrasniper555)\
**Post date:** [April 22, 2006, 9:10pm UTC](https://forum.kirupa.com/t/find-where-two-lines-join/186498/12 "2006-04-22T21:10:16Z")

</div>

Someone should have a tutorial on shooting with this.
