Home arrow Articles arrow Flash arrow Collision detection & bouncing part 1: intersection of line segments
Collision detection & bouncing part 1: intersection of line segments Print E-mail
Sunday, 23 April 2006
Article Index
Collision detection & bouncing part 1: intersection of line segments
Slope-Intercept form
Parametric form
Flash demo and sample code

This is the first article in a series about collision detection and bouncing in Flash. Before we get to the real stuff, we need some preliminary knowledge: we need to know how to intersect line segments.
In this article I'll show two ways to calculate the intersection of line segments. First we'll use the Slope-Intercept form of the lines to find their intersection. The second method uses a parametric equation, which will prove to be more elegant and require less time to compute.
Sample code is provided in Flash.

Before we go on, I have to tell you that I was a pretty bad math student in high school because I didn't have clue what all those equations were good for. In college (I have a master degree in Product Design) things started making more sense, since it allowed me to calculate forces or optimize space in my product designs. But still math wasn't my favorite. Only after I started programming, I got into it by reading stuff 10, 100 or 1000 times, untill I got it. So even if you're not a natural talent, math can be learned. Even worse, now I read math books before going to sleep.

Why you need to know about the intersection of line segments

Image
Suppose we want to detect if a moving object is hitting a wall. The wall is obviously a line segment. Our moving object is not, but we can draw a line from it's position at a certain frame (time t) to it's position at the next frame (time t+1). If these line segments intersect, we have a collision.



Comments
Great work on collision detection! I was searching the net for a solution to collision detection with lines and this is the best site so far! The only difficulty i have is understanding the math, particularly Cramer's rule. Other than that, everything else is quite simply explained. Keep it with the good work! :D
  Posted by israel, on Saturday, 10 March 2007 at 4:20

Thank you. it has been much more useful than anything else I found googling around.
M

  Posted by Marco, on Wednesday, 23 May 2007 at 4:54


 1 
Page 1 of 1 ( 2 comments )
©2005 MosCom

Add your comments to this article Collision detection & bouncing part... ...

Name (required)

E-Mail (required)
Your email will not be displayed on the site - only to our administrator
Homepage

Comment