Circle - Line Intersection工作不正常?

Cob*_*ast 1 c# math intersection

我在http://mathworld.wolfram.com/Circle-LineIntersection.html之后写了这个圆线交叉检测,但看起来好像它或我遗漏了一些东西.

    public static bool Intersect
    (Vector2f CirclePos, float CircleRad, Vector2f Point1, Vector2f Point2)
    {
        Vector2f p1 = Vector2f.MemCpy(Point1);
        Vector2f p2 = Vector2f.MemCpy(Point2);

        // Normalize points
        p1.X -= CirclePos.X;
        p1.Y -= CirclePos.Y;
        p2.X -= CirclePos.X;
        p2.Y -= CirclePos.Y;

        float dx = p2.X - p1.X;
        float dy = p2.Y - p1.Y;
        float dr = (float)Math.Sqrt((double)(dx * dx) + (double)(dy * dy));
        float D = p1.X * p2.Y * p2.X - p1.Y;

        float di = (CircleRad * CircleRad) * (dr * dr) - (D * D);

        if (di < 0) return false;
        else return true;
    }
Run Code Online (Sandbox Code Playgroud)

它返回true的唯一场合是何时Point2使用圆圈.我究竟做错了什么?

Ano*_*on. 7

float D = p1.X * p2.Y * p2.X - p1.Y;
Run Code Online (Sandbox Code Playgroud)

你已经在这条线上混淆了你的运营商.