Skip to content

Instantly share code, notes, and snippets.

@Kogarasi
Created May 21, 2017 06:56
Show Gist options
  • Save Kogarasi/2721d52887c613add8a2e121db94ccd6 to your computer and use it in GitHub Desktop.
Save Kogarasi/2721d52887c613add8a2e121db94ccd6 to your computer and use it in GitHub Desktop.
円と線分の交点算出
// A,Bは線分、Cは円の中心
auto PointA = Vector2();
auto PointB = Vector2();
auto PointC = Vector2();
auto VecAtoB = Vector2( PointB - PointA );
auto VecAtoC = Vector2( PointC - PointA );
auto VecBtoC = Vector2( PointC - PointB );
// 角度の算出
auto N = VecAtoB.x * VecAtoC.y - VecAtoB.y * VecAtoC.x;
auto D = VecAtoB.x * VecAtoC.x + VecAtoB.y * VecAtoC.y;
auto Theta = atan2(N,D);
// 交点座標の算出
auto Length = abs( VecAtoC.length * sin( Theta ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment