我正在研究以下代码。
boolean convex(double x1, double y1, double x2, double y2,
double x3, double y3)
{
if (area(x1, y1, x2, y2, x3, y3) < 0)
return true;
else
return false;
}
/* area: determines area of triangle formed by three points
*/
double area(double x1, double y1, double x2, double y2,
double x3, double y3)
{
double areaSum = 0;
areaSum += x1 * (y3 - y2);
areaSum += x2 * (y1 - y3);
areaSum += x3 * (y2 - y1);
/* for actual area, we need to multiple areaSum * 0.5, but we are
* only interested in the sign of the area (+/-)
*/
return areaSum;
}
我不明白那个区域是负面的概念。面积不应该总是积极的吗?也许我对这里的术语缺乏一些理解。我试图联系原作者,但这段代码大约有 8 年的历史,我无法联系原作者。这种确定给定顶点 x2y2 是否为凸的方法似乎非常灵活。我真的很想了解它。任何帮助我理解这段代码的方向或参考将不胜感激。
源代码:http ://cgm.cs.mcgill.ca/~godfried/teaching/cg-projects/97/Ian/applets/BruteForceEarCut.java