Circle - Segment intersection
#6

Oh yeah, my bad.
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;
    }
}
Also I made a function that returns (X,Y) where the line is entering and/or exiting the circle, if you need that.
Reply


Messages In This Thread
Circle - Segment intersection - by PeppeAC - 01.07.2013, 10:04
Re: Circle - Segment intersection - by Antonio144 - 01.07.2013, 15:11
Re: Circle - Segment intersection - by PeppeAC - 01.07.2013, 15:31
Re: Circle - Segment intersection - by Antonio144 - 01.07.2013, 17:34
Re: Circle - Segment intersection - by PeppeAC - 01.07.2013, 17:48
Re: Circle - Segment intersection - by Antonio144 - 01.07.2013, 18:01
Re: Circle - Segment intersection - by PeppeAC - 01.07.2013, 18:27

Forum Jump:


Users browsing this thread: 2 Guest(s)