Say I have this circle here.
What would be an algorithm to check if lines like the green or blue lines intersect the edge of the circle, but not the red line.
So lets say
if(amountOfPointsHit(line, circle) > 1) then return true
else return false

I only know the start and finish points of the lines, and not where the line intersects the circle. So the pseudo code would more be like
if(pointBetweenXYHit(x1, y1, x2, y2, circle) > 1) then return true
else return false
Here is the code I came up with based on the answers...
/**
*@param l1 Line point 1, containing latitude and longitude
*@param l2 Line point 2, containing latitude and longitude
*@param c Center of circle, containing latitude and longitud
*@param r Radius of the circle
**/
Maps.ui.inCircle = function(l1, l2, c, r){
var a = l1.lat() - l2.lat()
var b = l1.lng() = l2.lng()
var x = Math.sqrt(a*a + b*b)
return (Math.abs((c.lat() - l1.lat()) * (l2.lng() - l1.lng()) -
(c.lng() - l1.lng()) * (l2.lat() - l1.lat())) / x <= r);
}
pseudo code for that ^^ is
method inCircle (line1point, line2point, center, radius)
let l1 = line1point
let l2 = line2point
let c = center
let r = radius
x is length between points line1point and line2point
return true if ((c.x - l1.x) * (l2.y - l1.y) - (c.y - l1.y) * (l2.x - l1.x)) / x)
is less then or eqaul to r
You can find the shortest distance from a point to a line using the formula $$\operatorname{distance}(ax+by+c=0, (x_0, y_0)) = \frac{|ax_0+by_0+c|}{\sqrt{a^2+b^2}}. $$ Put $(x_0,y_0)$ = center of circle. If this distance is smaller (or equal) than radius of circle, then your line and circle intersects.
Since you know start point $(x_1,y_1) $ and end point $(x_2, y_2) $, you can get the equation of line using formula $$y - y_1 = \frac{y_2 - y_1}{x_2 - x_1}(x-x_1)$$ Simplifying, we get $$ (x_2 - x_1) y + (y_1 - y_2)x +(x_1-x_2)y_1 + x_1(y_2-y_1) = 0$$ It would be nice to store $a = y_1 - y_2, b = x_2 - x_1, c = (x_1-x_2)y_1 + x_1(y_2-y_1)$
It would be something like
something like $$ \frac{\left | (x_2 - x_1)x_0 + (y_1 - y_2)y_0 + (x_1-x_2)y_1 + x_1(y_2-y_1) \right |}{\sqrt{(x_2 - x_1)^2 + (y_1 - y_2)^2}} \le r$$