/***********************************************************<br />** Description: http://acm.fzu.edu.cn/contest/problem.php?cid=113&sortid=4<br />** Analysis:(1)判斷線段與三角形是否相交<br />1.相交<br />1.共線相交<br />2.非共線相交<br />2.不相交<br />可以通過一個點在三角形內/外來判斷<br />1.在三角形內<br />2.在三角形外<br />** Source: FZU April D<br />** 2011-04-17 18:51:25<br />***********************************************************/<br />#include <iostream><br />#include <stdio.h><br />using namespace std;<br />struct pot {<br />int x, y;<br />};</p><p>pot operator - (pot a, pot b) {<br />pot c;<br />c.x = a.x-b.x;<br />c.y = a.y-b.y;<br />return c;<br />}</p><p>int MIN(int,int);<br />int MAX(int,int);<br />int chaji(pot,pot);// 求兩向量叉積<br />bool INTERSECT(pot,pot,pot,pot);//判斷是否相交<br />int DIRECTION(pot,pot,pot);//求三點的叉積<br />bool ONSEG(pot,pot,pot);//判斷點是否在直線上,前提是有共線<br />bool INSIDE(pot,pot,pot,pot);//判斷點是否在地區內<br />bool ONELINE(pot,pot,pot,pot);//判斷是否共線,且有公用部分</p><p>int main() {<br />freopen("d.in", "r", stdin);<br />pot t1, t2, t3, a1, a2;<br />int n, i;<br />while (scanf("%d %d", &t1.x, &t1.y) == 2) {<br />scanf("%d %d", &t2.x, &t2.y);<br />scanf("%d %d", &t3.x, &t3.y);<br />scanf("%d", &n);<br />for (i = 0; i < n; i++) {<br />scanf("%d %d", &a1.x, &a1.y);<br />scanf("%d %d", &a2.x, &a2.y);<br />if (INTERSECT(a1,a2,t1,t2) || INTERSECT(a1,a2,t1,t3) || INTERSECT(a1,a2,t2,t3)) {<br />if (ONELINE(a1,a2,t1,t2) || ONELINE(a1,a2,t1,t3) || ONELINE(a1,a2,t2,t3)) {<br />printf("ON_EDGE/n");<br />} else {<br />printf("SIM_INT/n");<br />}<br />} else {<br />if (!INSIDE(t1,t2,t3,a1) || !INSIDE(t2,t1,t3,a1) || !INSIDE(t3,t1,t2,a1)) {//OUT_LINE<br />printf("OUT_SIDE/n");<br />} else {<br />printf("IN_SIDE/n");<br />}//INLINE<br />}<br />}<br />}<br />}</p><p>int MIN(int a, int b) {<br />if (a < b) return a; else return b;<br />}<br />int MAX(int a, int b) {<br />if (a < b) return b; else return a;<br />}<br />bool INTERSECT(pot p1, pot p2, pot p3, pot p4) {<br />int d1 = DIRECTION(p3,p4,p1);<br />int d2 = DIRECTION(p3,p4,p2);<br />int d3 = DIRECTION(p1,p2,p3);<br />int d4 = DIRECTION(p1,p2,p4);<br />if ( ((d1 > 0 && d2 < 0) || (d1 < 0 && d2 > 0)) &&<br /> ((d3 > 0 && d4 < 0) || (d3 < 0 && d4 > 0)) )<br />return true;<br />if (d1 == 0 && ONSEG(p3,p4,p1)) return true;<br />if (d2 == 0 && ONSEG(p3,p4,p2)) return true;<br />if (d3 == 0 && ONSEG(p1,p2,p3)) return true;<br />if (d4 == 0 && ONSEG(p1,p2,p4)) return true;<br />return false;<br />}<br />int chaji(pot a, pot b) {<br />return a.x*b.y-a.y*b.x;<br />}<br />int DIRECTION(pot p1, pot p2, pot p3) {<br />return chaji(p2-p1,p3-p1);<br />}<br />bool ONSEG(pot i, pot j, pot k) {<br />if (MIN(i.x,j.x) <= k.x && k.x <= MAX(i.x,j.x) &&<br />MIN(i.y,j.y) <= k.y && k.y <= MAX(i.y,j.y))<br />return true;<br />else return false;<br />}<br />bool INSIDE(pot a, pot b, pot c, pot r) {<br />int d1 = DIRECTION(a,b,r);<br />int d2 = DIRECTION(a,r,c);<br />if ((d1 > 0 && d2 > 0) || (d1 < 0 && d2 < 0)) return true; else return false;<br />}<br />bool ONELINE(pot a,pot b, pot c, pot d) {<br />int d1 = DIRECTION(a,b,c);<br />int d2 = DIRECTION(a,b,d);<br />if (d1 == 0 && d2 == 0) {<br />if (ONSEG(a,b,c) || ONSEG(a,b,d) || ONSEG(c,d,a) || ONSEG(c,d,b))<br />return true;<br />else<br />return false;<br />} else return false;<br />}<br />