1
http://mathworld.wolfram.com/Circle-LineIntersection.html 다음에이 원선 교차 감지를 작성했지만 그 것처럼 보이거나 뭔가 빠졌습니다. Point2
가 원을 withing에 때원선 교차로가 제대로 작동하지 않습니까?
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를 돌려주는 유일한 기회입니다. 내가 도대체 뭘 잘못하고있는 겁니까?
float D = p1.X * p2.Y * p2.X - p1.Y impromore – Instantsoup
제곱근을 취한 다음 다시 정사각형 ('dr')으로 바보처럼 보인다. –