我试图检测任意多边形中的角是凹的还是凸的。我制作了下面的函数来计算所有边对之间的角度。但是,人们永远不知道它返回的是内角还是外角。我不知道该怎么做。任何帮助表示赞赏!!!!
function findConvexCorner (pt){
var isCornerConvex = [];
for (var i =0; i < pt.length ;i++)
{
var lastPt = pt.length -1;
if (i==0){
var vec1 = vec3.createXYZ( pt[lastPt].x - pt[i].x , pt[lastPt].y - pt[i].y ,0.0);
var vec2 = vec3.createXYZ( pt[i].x - pt[i+1].x , pt[i].y - pt[i+1].y ,0.0);
vec3.normalize(vec1);vec3.normalize(vec2);
isCornerConvex.push(Math.acos(vec3.dot(vec1,vec2))*180/Math.PI);}
else if(i == lastPt){
var vec2 = vec3.createXYZ( pt[i-1].x - pt[i].x , pt[i-1].y - pt[i].y ,0.0);
var vec1 = vec3.createXYZ( pt[0].x - pt[i].x , pt[0].y - pt[i].y ,0.0);
vec3.normalize(vec1);vec3.normalize(vec2);
isCornerConvex.push(Math.acos(vec3.dot(vec1,vec2))*180/Math.PI);}
else{
var vec1 = vec3.createXYZ( pt[i-1].x - pt[i].x , pt[i-1].y - pt[i].y ,0.0);
var vec2 = vec3.createXYZ( pt[i+1].x - pt[i].x , pt[i+1].y - pt[i].y ,0.0);
vec3.normalize(vec1);vec3.normalize(vec2);
isCornerConvex.push(Math.acos(vec3.dot(vec1,vec2))*180/Math.PI);}
}
console.log("Angle: "+ isCornerConvex);
}