平面上有序三元组点的方向判断

隐身守侯 提交于 2019-11-27 15:54:49
 1 //compute orientation of an ordered triplet of points in the plane
 2 /*
 3  * counterclockwise, clockwise, colinear
 4 */
 5 
 6 #include<bits/stdc++.h>
 7 
 8 using namespace std;
 9 
10 struct Point
11 {
12     int x,y;
13 };
14 
15 /*
16 use slope to calculate, note the orientation of (p,q,r) is converse to (r,q,p)
17 0--->colinear
18 1--->counterclockwise
19 2--->clockwise
20 */
21 
22 int calOrientation(Point p1,Point p2,Point p3)
23 {
24     int val=(p3.y-p2.y)*(p2.x-p1.x)-(p2.y-p1.y)*(p3.x-p2.x);
25     if(val==0)
26         return 0;
27     return val>0?1:2;
28 }

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!