【发布时间】:2011-07-29 00:49:31
【问题描述】:
我正在尝试计算矩形旋转时的左下角。我试图用谷歌搜索它,但显然我错过了一些东西。我正在尝试使用转换矩阵来计算点。
对于我的设置,我有一个名为“test”的矩形剪辑和一个名为“pnt”的剪辑,我试图将其保留在左下角。这是我的演示代码。我刚刚把它扔到时间线的第一帧来测试:
//declare initial position of points
pnt.x = (test.x - test.width/2);
pnt.y = (test.y + test.height/2);
//distance between corner and center
var dx:Number = pnt.x - test.x;
var dy:Number = pnt.y - test.y;
addEventListener(Event.ENTER_FRAME,rotate);
//x' = xc + dx cos(theta) - dy sin(theta)
//y' = yc + dx sin(theta) + dy cos(theta)
function rotate(e:Event):void{
test.rotation++;
// use the transformation matrix to calculate the new x and y of the corner
pnt.x = test.x + dx*Math.cos(test.rotation*(Math.PI/180)) - dy*Math.sin(test.rotation*(Math.PI/180));
pnt.y = test.y + dx*Math.sin(test.rotation*(Math.PI/180)) + dy*Math.cos(test.rotation*(Math.PI/180));
trace("X: " + Math.cos(rotation));
trace("Y: " + pnt.y);
// calculate the new distance to the center
dx = pnt.x - test.x;
dy = pnt.y - test.y;
}
【问题讨论】:
-
您是否尝试过将“pnt”添加为“test”的子对象并将它们作为一个对象旋转?
-
这是一个尝试解决问题的演示。实际问题存在于我不能依赖嵌入的影片剪辑的物理引擎中。
标签: flash actionscript-3 algorithm geometry