01.07.2013, 15:11
pawn Код:
/*
pA,pB - line segments
pC - circle center
radius - well...radius
*/
stock LineIntersectCircle(Float:pA[2], Float:pB[2], Float:pC[2], Float:radius)
{
new Float: a = (pB[0]-pA[0])*(pB[0]-pA[0])+(pB[1]-pA[1])*(pB[1]-pA[1]);
new Float: b = 2*((pB[0]-pA[0])*(pA[0]-pC[0])+(pB[1]-pA[1])*(pA[1]-pC[1]));
new Float: c = pC[0]*pC[0]+pC[1]*pC[1]+pA[0]*pA[0]+pA[1]*pA[1]-2*(pC[0]*pA[0]+pC[1]*pA[1]) - radius*radius;
new Float: konst = b*b-4*a*c;
if(konst <= 0) return 0;
else
{
new Float: e = floatsqroot(konst);
new Float: u1 = (-b+e)/(2*a);
new Float: u2 = (-b-e)/(2*a);
if((u1>=0 || u1>=1) && (u2<=0 || u2<=1)) return 1;
}
return 0;
}