我给自己写了一个公式,让正多边形(甚至可能是不规则多边形)的点围绕定向点旋转。该公式似乎适用于离散编码的矩形:
tempShape.points = [[0,0],[wid,0],[wid,hig],[0,hig]];但不是在公式生成的多边形上:
tempShape.points = [[len,0]];
for(var i=1; i < poin; i++){
if(gen){
tempShape.points[i] = [0,0];
tempShape.points[i][0] = len*Math.cos(angle*i);
tempShape.points[i][1] = len*Math.sin(angle*i);
}
}这是我的轮换公式:
for(var i2 = 0; i2 < displayList[i].points.length; i2++){
displayList[i].points[i2][0] = (displayList[i].pointsRot[i2][0] + displayList[i].oPoint[0]) * Math.cos(displayList[i].rotation) - (displayList[i].pointsRot[i2][1] + displayList[i].oPoint[1]) * Math.sin(displayList[i].rotation);
displayList[i].points[i2][1] = (displayList[i].pointsRot[i2][1] + displayList[i].oPoint[1]) * Math.cos(displayList[i].rotation) + (displayList[i].pointsRot[i2][0] + displayList[i].oPoint[0]) * Math.sin(displayList[i].rotation);
}其中displayListi是形状,.points是包含所有点的数组,.rotation是形状的旋转,.oPoint是方向点。我希望你能帮忙,提前谢谢。凯尔。
编辑:我只是尝试而不是增加旋转,我将静态旋转设置为0.01,但这使它表现得像正常的旋转增加0.01,所以在某个地方(我不知道在哪里)它一定像是通过设置的旋转增加我的旋转,我只需要弄清楚它。我可以把我的全部代码给别人看吗?
发布于 2014-06-05 12:39:40
您在第二个公式中使用的值displayList[i].pointsRot[i2][0]已在第一个公式中更改。只需记住临时变量中的原始值并使用它。
编辑:我好像被你的龙龙龙名字缠住了。你的公式要匹配的С:
NewX = CenterX + (OldX-CenterX)*Cos(Fi) - (OldY-CenterY)*Sin(Fi)
NewY = CenterY + (OldX-CenterX)*Sin(Fi) + (OldY-CenterY)*Cos(Fi)其中(CenterX,CenterY)是旋转点
https://stackoverflow.com/questions/24045036
复制相似问题