hdu2108

叉积(用坐标)能够判断边b是在边a的顺时针方向还是逆时针方向

代码如下:

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 int main()
 5 {
 6     int n, i;
 7     int coordinate[1000][2];
 8     int real( int coordinate[][2], int i );
 9 
10     while( scanf( "%d", &n ), n )
11     {
12 
13         for( i = 0; i < n; i ++ )//逆时针读入坐标
14         {
15             scanf( "%d%d", &coordinate[i][0], &coordinate[i][1] );
16         }
17 
18         coordinate[n][0] = coordinate[0][0];
19         coordinate[n][1] = coordinate[0][1];
20         coordinate[n+1][0] = coordinate[1][0];
21         coordinate[n+1][1] = coordinate[1][1];
22 
23         for( i = 0; i < n; i ++ )
24         {
25             if( real( coordinate, i ) >= 0 )//大于0表示 为顺时针拐
26             {
27                 break;
28             }
29         }
30 
31         if( i == n )
32         {
33             printf( "convex\n" );
34         }
35         else
36         {
37             printf( "concave\n" );
38         }
39     }
40     return 0;
41 }
42 int real( int coordinate[][2], int i )
43 {
44     int x1, x2, y1, y2;
45 
46     x1 = coordinate[i+2][0] - coordinate[i][0];
47     x2 = coordinate[i+1][0] - coordinate[i][0];
48     y1 = coordinate[i+2][1] - coordinate[i][1];
49     y2 =  coordinate[i+1][1] - coordinate[i][1];
50 
51     return - x2 * y1 + y2 * x1;
52 }

 

 

转载于:https://www.cnblogs.com/hacker-hzh/archive/2013/03/23/2976720.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值