01.07.2013, 18:01
Oh yeah, my bad.
I got the LM line segment to return right:
Also I made a function that returns (X,Y) where the line is entering and/or exiting the circle, if you need that.
I got the LM line segment to return right:
pawn Код:
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;
printf("konst = %f",konst);
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))
{
if((u1<0 && u2<0) || (u1>1 && u2>1)) return 1;
else return 0;
}
else return 1;
}
}