gpt4 book ai didi

c# - Circle - Line Intersection 不能正常工作?

转载 作者:太空宇宙 更新时间:2023-11-03 18:45:35 25 4
gpt4 key购买 nike

我在 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;
}

它返回 true 的唯一情况是当 Point2 在圆圈内时。我做错了什么?

最佳答案

float D = p1.X * p2.Y * p2.X - p1.Y;

你在这条线上混淆了你的运算符(operator)。

关于c# - Circle - Line Intersection 不能正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4651248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com