uploaded by
Zhang Yunzun
When you start to do this problem, you always draw on the draft paper. Infer how many cases, just think that the situation is more, may not consider the overall, beginning I was based on a point as a vertex, and then write the criteria. Later, I wrote it myself and executed it, and the results were all 1. I think I have repeated the situation, my ideas may be biased, including other situations.
if ((Y1>=Y2&&Y1>=Y3&&X3<=X2)//with a as a vertex | | (y2>=y1&&y2>=y3&&x3>=x1)//b for vertex | | (Y3>=Y2&&Y3>=Y1&&X1<=X2)) C is the vertex printf ("1\n"); else if ((y1>=y2&&y1>=y3&&x2<=x3) | | | (y2>=y1&&y2>=y3&&x3<=x1) | | (y3>=y2&&y3>=y1&&x2<=x1)) printf ("0\n");
Later a look at the discussion area, actually has the formula ...
No sense in calculating geometry.
The formulas that have been learned are not used. Take advantage of the cross product we have learned.
the use of vector cross-product inference is counterclockwise or clockwise. With vector P = (x1, y1), Q = (x2, y2), the vector fork product is defined as a signed area of 0,0 consisting of (P1), p2, p1+p2, and parallelogram, i.e. PXQ = x1*y2-x2*y1. The result is a scalar. Obviously there are properties Pxq =-(QXP) and PX (-Q) =-(PXQ).
a very important property of the cross product is the ability to infer a clockwise-counterclockwise relationship between two vectors through its notation:
if PXQ > 0, then P is in the clockwise direction of Q.
if Pxq < 0, then P is in the counterclockwise direction of Q.
if Pxq = 0, P is collinear with Q, but may also be reversed.
explanation:
axb= (AY * bz-by * az, AZ * bx-a X * BZ, AX * by-ay * bx) and since AZ Bz are all 0, so axb= (0,0. AX * By-ay * bx)
According to the right hand system (fork to meet the right hand line), if PXQ > 0,ax * by-ay * bx>0, that is, thumb pointing upward, so P in the clockwise direction of Q. A bit.
Read someone else's blog about the content of the cross-product http://blog.csdn.net/sjl_leaf/article/details/8789785 immediately on the cottage open Ah, more than 10 lines of code to conquer;
#include <cstdio>int main () { int x1,y1,x2,y2,x3,y3; int flag; while (scanf ("%d%d%d%d%d%d", &x1,&y1,&x2,&y2,&x3,&y3)) { if (!x1&&!y1 &&!X2&&!Y2&&!X3&&!Y3) break ; flag= (x2-x1) * (y3-y1)-(y2-y1) * (X3-X1); if (flag<0) printf ("1\n"); else printf ("0\n"); } return 0;}
The three points are converted into vectors for calculation, ab= (x2-x1,y2-y1), ac= (x3-x1,y3-y1);
Their cross-product is |x2-x1,y2-y1|.
|x3-x1,y3-y1|
Use determinant calculations. able to draw flag= (x2-x1) * (y3-y1)-(y2-y1) * (X2-X1);
Value of inferred flag
1.flag<0 Clockwise
2.flag>0 Counter-clockwise
3.flag=0 three-point common line