Created
August 29, 2012 03:15
-
-
Save aoisensi/3506453 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
//http://www5d.biglobe.ne.jp/~tomoya03/shtml/algorithm/IntersectionEX.htm | |
bool IL::ILZBuffer::IsTriangleInPoint(const ILVECTOR2 &A, const ILVECTOR2 &B, const ILVECTOR2 &C, const ILVECTOR2 &P) | |
{ | |
return IsCross(ILSEGMENT2(A,B),ILSEGMENT2(C,P)) && IsCross(ILSEGMENT2(B,C),ILSEGMENT2(A,P)) && IsCross(ILSEGMENT2(C,A),ILSEGMENT2(B,P)); | |
} | |
bool IL::ILZBuffer::IsCross(const ILSEGMENT2 &A,const ILSEGMENT2 &B) | |
{ | |
return !((IsCrossSub(A.a.x,A.b.x,B.a.x,B.b.x)) || (IsCrossSub(A.a.y,A.b.y,B.a.y,B.b.y))) && (((((A.a.x - A.b.x) * (B.a.y - A.a.y) + (A.a.y - A.b.y) * (A.a.x - B.a.x)) * ((A.a.x - A.b.x) * (B.b.y - A.a.y) + (A.a.y - A.b.y) * (A.a.x - B.b.x))) > 0.0F) && (((B.a.x - B.b.x) * (A.a.y - B.a.y) + (B.a.y - B.b.y) * (B.a.x - A.a.x)) * ((B.a.x - B.b.x) * (A.b.y - B.a.y) + (B.a.y - B.b.y) * (B.a.x - A.b.x)) > 0.0F)); | |
} | |
bool IL::ILZBuffer::IsCrossSub(const double &p1, const double &p2, const double &p3, const double &p4) | |
{ | |
return (p1 < p2)?IsCrossSub2(p1,p2,p3,p4):IsCrossSub2(p2,p1,p3,p4); | |
} | |
bool IL::ILZBuffer::IsCrossSub2(const double &p1, const double &p2, const double &p3, const double &p4) | |
{ | |
return (p1 < p3 && p1 < p4) || (p2 < p3 && p2 < p4); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment