Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flex 如何获得旋转组件的可视宽度和高度?_Apache Flex_Actionscript 3_Math_Geometry_Flex4 - Fatal编程技术网

Apache flex 如何获得旋转组件的可视宽度和高度?

Apache flex 如何获得旋转组件的可视宽度和高度?,apache-flex,actionscript-3,math,geometry,flex4,Apache Flex,Actionscript 3,Math,Geometry,Flex4,我在玩这样的代码: <s:Button id="test" label="test" transformX="{Math.floor(test.width/2)}" rotationY="20" x="20" y="20" /> object.transform.perspectiveProjection = new PerspectiveProjection(); 按钮在Y轴上旋转,旋转枢轴位于按钮的中间。 这将创建一个类似以下内容的按钮: <s:Button id=

我在玩这样的代码:

<s:Button id="test" label="test" transformX="{Math.floor(test.width/2)}" rotationY="20" x="20" y="20" />
object.transform.perspectiveProjection = new PerspectiveProjection();

按钮在Y轴上旋转,旋转枢轴位于按钮的中间。

这将创建一个类似以下内容的按钮:

<s:Button id="test" label="test" transformX="{Math.floor(test.width/2)}" rotationY="20" x="20" y="20" />
object.transform.perspectiveProjection = new PerspectiveProjection();

(来源:)

在视觉上,旋转按钮填充的空间与您认为的x、y、高度和宽度值不同

我的图像中的“A”值是按钮的高度。但是,我想用于计算和放置的是B值

另外,我想对宽度进行类似的计算;获取从右上角到左下角的宽度

我该怎么做



我放了一个例子来展示人们提出的各种计算方法。源代码也很简单。没有什么比我想象的更有效的了。例如,将旋转滑块旋转到85。这个按钮实际上是看不见的,但所有的方法仍然赋予它高度和宽度

我的数学可能有点生疏,但我会这样找到答案:

您可以将一个直角三角形从按钮的右边缘延伸到图表的最底部点(a-B)。然后可以使用正弦定律得到三个角度:90',20'和70'(90将始终存在,然后变量-180表示第三个角度)

然后,您可以使用以下公式找到您的答案:

B = ((button.width * sin(button.rotationY)) / (sin(90 -button.rotationY)) + (button.height)
getBounds(..)和getRect(..)应该是获取变换对象的宽度和高度的方法


还没有在Flex 4中尝试过它们,但它们在Flex 3中一直对我有效。

答案在James Ward对这个问题的评论中,位于此处

博客文章没有提到的一点是,在许多情况下,所讨论的类上transform属性的perspectiveProjection属性将为null。“链接到”示例通过将
maintainProjectionCenter
属性设置为true来解决这个问题。但是,您也可以创建一个新的透视投影对象,如下所示:

<s:Button id="test" label="test" transformX="{Math.floor(test.width/2)}" rotationY="20" x="20" y="20" />
object.transform.perspectiveProjection = new PerspectiveProjection();
我将evtimmy中的函数包装到一个类中:

/**
 * DotComIt/Flextras 
 * Utils3D.as
 * Utils3D
 * jhouser
 * Aug 5, 2010
 */
package com.flextras.coverflow
{
    import flash.geom.Matrix3D;
    import flash.geom.PerspectiveProjection;
    import flash.geom.Rectangle;
    import flash.geom.Utils3D;
    import flash.geom.Vector3D;

    public class TransformUtilities
    {
        public function TransformUtilities()
        {
        }


    //--------------------------------------------------------------------------
    //
    //  Methods
    //
    //--------------------------------------------------------------------------

    //----------------------------------
    //  projectBounds
    //----------------------------------
    // info from 
    // http://evtimmy.com/2009/12/calculating-the-projected-bounds-using-utils3dprojectvector/

    /**
     * Method retrieved from  
     * http://evtimmy.com/2009/12/calculating-the-projected-bounds-using-utils3dprojectvector/
     * 
     * @param bounds:  The rectangle that makes up the object
     * @param matrix The 3D Matrix of the item
     * @param the projection of the item's parent.
     */
    public static function projectBounds(bounds:Rectangle,
                                         matrix:Matrix3D, 
                                         projection:PerspectiveProjection):Rectangle
    {
        // Setup the matrix
        var centerX:Number = projection.projectionCenter.x;
        var centerY:Number = projection.projectionCenter.y;
        matrix.appendTranslation(-centerX, -centerY, projection.focalLength);
        matrix.append(projection.toMatrix3D());

        // Project the corner points
        var pt1:Vector3D = new Vector3D(bounds.left, bounds.top, 0); 
        var pt2:Vector3D = new Vector3D(bounds.right, bounds.top, 0) 
        var pt3:Vector3D = new Vector3D(bounds.left, bounds.bottom, 0);
        var pt4:Vector3D = new Vector3D(bounds.right, bounds.bottom, 0);
        pt1 = Utils3D.projectVector(matrix, pt1);
        pt2 = Utils3D.projectVector(matrix, pt2);
        pt3 = Utils3D.projectVector(matrix, pt3);
        pt4 = Utils3D.projectVector(matrix, pt4);

        // Find the bounding box in 2D
        var maxX:Number = Math.max(Math.max(pt1.x, pt2.x), Math.max(pt3.x, pt4.x));
        var minX:Number = Math.min(Math.min(pt1.x, pt2.x), Math.min(pt3.x, pt4.x));
        var maxY:Number = Math.max(Math.max(pt1.y, pt2.y), Math.max(pt3.y, pt4.y));
        var minY:Number = Math.min(Math.min(pt1.y, pt2.y), Math.min(pt3.y, pt4.y));

        // Add back the projection center
        bounds.x = minX + centerX;
        bounds.y = minY + centerY;
        bounds.width = maxX - minX;
        bounds.height = maxY - minY;
        return bounds;
    }

    }

}

虽然这是我问题的答案,但我不确定这是否是我问题的解决方案。谢谢大家

可能的复制品听起来很相似;但我不明白任何答案;这个问题早于Flex 4以及我正在使用的“transformX”和“rotationY”属性。Flex 4的附加功能听起来像是一个很好的理由来回答这个问题;这听起来正是我要找的。但是,他们似乎没有按照我预期的方式工作。没有变换。宽度为70,高度为21。var bounds1:Rectangle=test2.getRect(this.test2);宽度为72,高度为23。如果我开始轮换物品;结果似乎更不正确。我收集了一个样本来展示人们建议的各种方法:James发布的博客看起来很有希望,但实际上我认为如果getBounds没有返回正确的边界,那就是一个错误……这也没有达到我的预期。如果旋转度为零,则工作正常;但除此之外,事情会变得混乱。我收集了一个样本来展示人们建议的各种方法: