Posted: 28th May 2007 20:34
An interesting challenge is now underway (deadline June 9th) in the DBPro Challenges Thread (stickied above), to create some kind of program which demonstrates the use of 2d line collision and physics. If you've ever played Line Rider http://official-linerider.com/play.html you'll get the idea.

Should be a fun challenge for the more mathematically inclined - 2d line intersection equations and stuff.

Everyone welcome to join in as always, whether to enter the challenge, or just help those of us who are struggling.
Posted: 8th Jun 2007 11:21
2d line intersection equations and stuff


Which should not be that complicated. You learned those in high school. Of course, not everyone here has got there yet I guess (not saying anything about you Ric), so hey. Whatever.

For those who don't know, you can find a the Y of a point on a line using the equation y = mx + b (the equation of a line), where m is the slope and b is the y-intercept (at what Y the line crosses 0 X) The only thing to remember when coding for a computer is that on a graph, point (0,0) is in the lower lefthand corner, whereas on a computer screen (0,0) is the UPPER lefthand corner, and that has to be taken into account.

-ThinkDigital
Posted: 10th Jun 2007 13:30
For those who don't know, you can find a the Y of a point on a line using the equation y = mx + b (the equation of a line), where m is the slope and b is the y-intercept


It's not quite as simple as that though - we know that y=mx+c, and finding the gradient m is easy enough if you know two points on the line - but how do you find the y intercept before you've found the equation of the line? I'm pretty sure even people beyond high school maths would still need to put some thought into that - I know I had to!
Posted: 11th Jun 2007 2:11
Just rewrite the equation to solve for the y-intercept.

y = mx + b

becomes

b = y - mx

So, by knowing a point on the line and the slope, you can find the y-intercept that way. Remember, x and y can be the coordinates of ANY point on the line.

So, say we have a line that passes through points (1,2) and (4,6).
We want to find the Y value for point (3,y), assuming point (3,y) is on the line.

First, like you said, it's easy to find the slope. In our case, it would be 4/3.

Then find the y-intercept using any point on the line. Say we use point (1,2).

b = y - mx -> b = 2 - (4/3)1 -> b = 2 - (4/3)
Since (4/3) comes out to 1.33333..., just leave it at that.

Then just plug that into y = mx + b and solve, and this time the X and Y variables are the point you're trying to find (3,y):
y = (4/3)3 + [2 - (4/3)]
y = 4 + [2 - (4/3)]
comes out to about 4.67

You can use any point on the line to find the y-intercept because the line's y-intercept should obviously never change.

-ThinkDigital
Posted: 11th Jun 2007 3:04
This might help.