怎样判断构成三角形的三个点的顺序是螺丝顺时针还是逆时针针

习题解答1-4章_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
习题解答1-4章
上传于||文档简介
&&C​语​言​课​后​题
阅读已结束,如果下载本文需要使用1下载券
想免费下载本文?
定制HR最喜欢的简历
下载文档到电脑,查找使用更方便
还剩12页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢2114人阅读
计算几何(7)
利用矢量叉积判断是逆时针还是顺时针。
& & 设A(x1,y1),B(x2,y2),C(x3,y3),则三角形两边的矢量分别是:
& & AB=(x2-x1,y2-y1), AC=(x3-x1,y3-y1)
& & 则AB和AC的叉积为:(2*2的行列式)
& & |x2-x1, y2-y1|
& & |x3-x1, y3-y1|
& & 值为:(x2-x1)*(y3-y1) - (y2-y1)*(x3-x1)
& & 利用右手法则进行判断:
& & 如果AB*AC&0,则三角形ABC是逆时针的
& & 如果AB*AC&0,则三角形ABC是顺时针的
&&& 如果……& =0,则说明三点共线,
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:149182次
积分:2263
积分:2263
排名:第13106名
原创:102篇
转载:14篇
评论:47条
(1)(1)(1)(2)(1)(1)(1)(1)(1)(2)(3)(1)(6)(2)(2)(13)(3)(12)(4)(1)(10)(1)(1)(2)(2)(15)(7)(2)(1)(1)(4)(8)(4)利用矢量叉积判断是逆时针还是顺时针。
&&&&设A(x1,y1),B(x2,y2),C(x3,y3),则三角形两边的矢量分别是:
&&&&AB=(x2-x1,y2-y1), AC=(x3-x1,y3-y1)
&&&&则AB和AC的叉积为:(2*2的行列式)
&&&&|x2-x1, y2-y1|
&&&&|x3-x1, y3-y1|
&&&&值为:(x2-x1)*(y3-y1) - (y2-y1)*(x3-x1)
&&&&利用右手法则进行判断:
&&&&如果AB*AC&0,则三角形ABC是逆时针的
&&&&如果AB*AC&0,则三角形ABC是顺时针的
&&& 如果……& =0,则说明三点共线,
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:32051次
积分:2074
积分:2074
排名:第14527名
原创:182篇
评论:10条
(30)(7)(5)(3)(7)(18)(21)(106)如何判定多边形是顺时针还是逆时针 - 开源中国社区
当前访客身份:游客 [
当前位置:
1、关于如何判定多边形是顺时针还是逆时针对于凸多边形而言,只需对某一个点计算cross product = ((xi - xi-1),(yi - yi-1)) x ((xi+1 - xi),(yi+1 - yi))&
= (xi - xi-1) * (yi+1 - yi) - (yi - yi-1) * (xi+1 - xi)
如果上式的值为正,逆时针;为负则是顺时针而对于一般的简单多边形,则需对于多边形的每一个点计算上述值,如果正值比较多,是逆时针;负值较多则为顺时针。
2、还有一种说明是取多边形的极点值,多边形的方向和这个顶点与其相邻两边构成的方向相同。
Determining whether or not a polygon (2D) has its vertices ordered clockwise or counterclockwise
Written by Paul Bourke
March 1998
The following describes a method for determining whether or not a polygon has its vertices ordered clockwise or anticlockwise. As a consequence the test can also be used to determine whether or not a polygon is concave or convex. A polygon will be assumed to be described by N vertices, ordered
(x0,y0), (x1,y1), (x2,y2), . . . (xn-1,yn-1)
A convenient definition of clockwise is based on considerations of the cross product between adjacent edges. If the crossproduct is positive then it rises above the plane (z axis up out of the plane) and if negative then the cross product is into the plane.
cross product = ((xi - xi-1),(yi - yi-1)) x ((xi+1 - xi),(yi+1 - yi))
= (xi - xi-1) * (yi+1 - yi) - (yi - yi-1) * (xi+1 - xi)
If the polygon is known to be convex then one only has to consider the cross product between any two adjacent edges. A positive cross product means we have a counterclockwise polygon. There are some tests that may need to be done if the polygons may not be &clean&. In particular two vertices must not be coincident and two edges must not be colinear.
For the more general case where the polygons may be convex, it is necessary to consider the sign of the cross product between adjacent edges as one moves around the polygon. If there are more positive cross products then the overall polygon is ordered counterclockwise. There are pathological cases to consider here as well, all the edges cannot be colinear, there must be at least 3 vertices, the polygon must be simple, that is, it cannot intersect itself or have holes.
A similar argument to the above can be used to determine whether a polygon is concave or convex. For a convex polygon all the cross products of adjacent edges will be the same sign, a concave polygon will have a mixture of cross product signs.
Test for concave/convex polygon
Source Code
Example and test program for testing whether a polygon is ordered clockwise or counterclockwise. For MICROSOFT WINDOWS, contributed by G. Adam Stanislav.
C function by Paul Bourke
& &Return the clockwise status of a curve, clockwise or counterclockwise
& &n vertices making up curve p
& &return 0 for incomputables eg: colinear points
& & & & & CLOCKWISE == 1
& & & & & COUNTERCLOCKWISE == -1
& &It is assumed that
& &- the polygon is closed
& &- the last point is not repeated.
& &- the polygon is simple (does not intersect itself or have holes)
int ClockWise(XY *p,int n)
& &int i,j,k;
& &int count = 0;
& &if (n & 3)
& & & return(0);
& &for (i=0;i&n;i++) {
& & & j = (i + 1) %
& & & k = (i + 2) %
& & & z &= (p[j].x - p[i].x) * (p[k].y - p[j].y);
& & & z -= (p[j].y - p[i].y) * (p[k].x - p[j].x);
& & & if (z & 0)
& & & & &count--;
& & & else if (z & 0)
& & & & &count++;
& &if (count & 0)
& & & return(COUNTERCLOCKWISE);
& &else if (count & 0)
& & & return(CLOCKWISE);
& & & return(0);
Example and test program for testing whether a polygon is convex or concave. For MICROSOFT WINDOWS, contributed by G. Adam Stanislav.
& &Return whether a polygon in 2D is concave or convex
& &return 0 for incomputables eg: colinear points
& & & & & CONVEX == 1
& & & & & CONCAVE == -1
& &It is assumed that the polygon is simple
& &(does not intersect itself or have holes)
int Convex(XY *p,int n)
& &int i,j,k;
& &int flag = 0;
& &if (n & 3)
& & & return(0);
& &for (i=0;i&n;i++) {
& & & j = (i + 1) %
& & & k = (i + 2) %
& & & z &= (p[j].x - p[i].x) * (p[k].y - p[j].y);
& & & z -= (p[j].y - p[i].y) * (p[k].x - p[j].x);
& & & if (z & 0)
& & & & &flag |= 1;
& & & else if (z & 0)
& & & & &flag |= 2;
& & & if (flag == 3)
& & & & &return(CONCAVE);
& &if (flag != 0)
& & & return(CONVEX);
& & & return(0);
共有0个评论
更多开发者职位上
有什么技术问题吗?
zwz2008...的其它问题}

我要回帖

更多关于 判断顺时针 逆时针 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信