Last active
December 6, 2015 03:19
-
-
Save hiroakioishi/d56c78671f0b0d7c9e34 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
/// <summary> | |
/// ポリゴン上に点が含まれるかを判定 | |
/// </summary> | |
bool detectPointIsEnclosedByPolygon (Vector3 p, Vector3 v0, Vector3 v1, Vector3 v2) { | |
Vector3 n = Vector3.Normalize (Vector3.Cross (v1 - v0, v2 - v1)); | |
Vector3 n0 = Vector3.Normalize (Vector3.Cross (v1 - v0, p - v1)); | |
Vector3 n1 = Vector3.Normalize (Vector3.Cross (v2 - v1, p - v2)); | |
Vector3 n2 = Vector3.Normalize (Vector3.Cross (v0 - v2, p - v0)); | |
if ((1.0f - Vector3.Dot (n, n0)) > 0.001f) return false; | |
if ((1.0f - Vector3.Dot (n, n1)) > 0.001f) return false; | |
if ((1.0f - Vector3.Dot (n, n2)) > 0.001f) return false; | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment