Csharp/C#教程:Circle – Line Intersection工作不正常?分享


Circle – Line Intersection工作不正常?

我在https://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; 

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

上述就是C#学习教程:Circle – Line Intersection工作不正常?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/959363.html

(0)
上一篇 2021年11月23日
下一篇 2021年11月23日

精彩推荐