I've tried searching for a javascript function that will detect if two lines intersect each other.
The function will take the x,y values of both the start end points for each line (we'll call them line A and line B).
Is to return true if they intersect, otherwise false.
Example of the function. I'm happy if the answer uses a vector object instead.
Function isIntersect (lineAp1x, lineAp1y, lineAp2x, lineAp2y, lineBp1x, lineBp1y, lineBp2x, lineBp2y)
{
// JavaScript line intersecting test here.
}
Some background info: this code is for a game I'm trying to make in html5 canvas, and is part of my collision detection.
For all folks who would like to have a solutions ready for coldfusion, here is what I adapted from http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/java/awt/geom/Line2D.java#Line2D.linesIntersect%28double%2Cdouble%2Cdouble%2Cdouble%2Cdouble%2Cdouble%2Cdouble%2Cdouble%29
the imporants functions are ccw and linesIntersect from java.awt.geom.Line2D and I wrote them into coldfusion, so here we go:
I hope this can help for adapting to other laguages?
First, find intersection coordinates - here it's described in detail: http://www.mathopenref.com/coordintersection.html
Then check if the x-coordinate for intersection falls within the x ranges for one of the lines (or do the same with y-coordinate, if you prefer), i.e. if xIntersection is between lineAp1x and lineAp2x, then they intersect.