The cross product determines the positional relationship between two vectors

// Vector product exercise 1 of a general vector

//                                 -→ -→ -→ -→
 // Title: Given two vectors p0p1 and p0p2 with common endpoints, determine whether p0p1 is in the clockwise direction of p0p2

// p1*p2=det[x1 x2]
 //            [y1 y2]
 //        =x1y2-x2y1
 //        =-p2*p1
 // If p1*p2 is positive, it is relative to the origin (0,0) Say, p1 is in the clockwise direction of p2
 // if it is negative, then p1 is in the counter-clockwise direction of p2
 // if == 0, then p1 and p2 are collinear, in the same or opposite direction

// The coordinate system is established with p0 as the origin, then P1=p1-p0, P2=p2-p0,
 // their cross product t=(p1-p0)*(p2-p0)=(x1-x0)*( y2-y0)-(x2-x0)*(y1-y0) 

#include <iostream> 
#include <cstdio> 
#include <cstring> 
#include <cmath> 
#include <algorithm>
 using  namespace std;

struct Point
{
    double x,y;
}p0,p1,p2;

intmain ()
{
    scanf("%lf%lf%lf%lf%lf%lf",&p0.x,&p0.y,&p1.x,&p1.y,&p2.x,&p2.y);
    double t=(p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
    if(t>0)
        puts("Yes");
    else
        puts("No");
    return 0;
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325170908&siteId=291194637