反映沿x和y轴的对象对象

2023-09-09 21:52:41 作者:槿夜浅凉

需要反映一组包含的物体如上图。

我有什么,我在我的最新进展做了样本图像。

目标:物体的反射应沿X轴和Y轴按照下面的图片来完成

解决方案

简单的code是这样的:

  copiedDisplayObject.scaleY = -1;
copiedDisplayObject.alpha = 0.4;
 

这是真的反射通过线,其中所述线恰好是x轴的一个具体例子。 (即Y = 0X + 0)如果你想反映过来另一条线,你可以用一个矩阵。下面的显示对象上preserves previous变换的code,并反映过来一条通过原点。

  VAR M:数= 0.25; //例如坡 - 来自行:表达式y = mx + 0
VAR tmpMatrix = copiedDisplayObject.transform.matrix;
VAR relectMatrix:矩阵=新的Matrix(1-m * m的,2 * M,2 * M,M * M-1);
tmpMatrix.concat(relectMatrix);
copiedDisplayObject.transform.matrix = tmpMatrix;
 
如图,直线y 2x 2与x轴交于点A,与y轴交于点B,把 AOB沿y轴翻折,点A落到点C,过点B的抛物线y x 2 b

我发现了矩阵式浏览: math.stackexchange问​​题

Need to reflect a group containing objects as shown in picture.

I have a sample image for what i have done in my current progress.

Objective: Reflection of objects should be done along x and y axis as per the below image

解决方案

The simple code looks like this:

copiedDisplayObject.scaleY = -1;
copiedDisplayObject.alpha = 0.4;

That is really a specific example of reflection over a line, where the line happens to be the x axis. (ie y = 0x + 0) If you want to reflect over another line, you can use a matrix. The code below preserves previous transformations on the display object, and reflects it over a line passing through the origin.

var m:Number = 0.25; //example slope -- from line: y = mx + 0
var tmpMatrix = copiedDisplayObject.transform.matrix;
var relectMatrix:Matrix = new Matrix(1-m*m, 2*m, 2*m, m*m -1);
tmpMatrix.concat(relectMatrix);
copiedDisplayObject.transform.matrix = tmpMatrix;

I found the matrix formula here: math.stackexchange question.