Created
May 21, 2017 06:56
-
-
Save Kogarasi/2721d52887c613add8a2e121db94ccd6 to your computer and use it in GitHub Desktop.
円と線分の交点算出
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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