翻转算法?算法

2023-09-11 06:25:59 作者:嚣张大神

我是新的Andr​​oid的画布上。我创建自定义形状 L形矩形,矩形和一些形状,并使用Android的画布。这是工作的罚款。在我的问题是翻转的自定义形状? previously我使用比例

  canvas.scale(-1.0F,1.0F);
 

它的工作。翻转后,那个形状做一些动作,例如(旋转,调整大小)。但我没有得到任何积分。所以,我搜索翻转算法的基础。我没有得到它。如果您知道请分享您的意见。

解决方案

矩阵是你的朋友。事实是,这是一种凌乱的东西使用,因为它被应用到画布上,这是一种不可思议的方式来看待事情,但一旦你发现计算将成为你的朋友。

首先把它写在纸上,并知道该怎么做才能在画布上把你的形状,你想要的。也许你需要翻译中心向以你为中心塑造,然后旋转,最后,得出。然后回到原来的转变。

如果您按照API you've了 canvas.save() canvas.rotate() canvas.scale() ...他们去当增加了一​​个旋转当前矩阵左右。即使你可以给一个矩阵you've建自己。

算法系列 字符串反转算法实现

I am new in android canvas. I was created custom shape on "L Shaped Rectangle, Rectangle and some shapes" and using android canvas. It was working fine. In my question is Flipping custom Shape? previously i was used scale

canvas.scale(-1.0f, 1.0f);

it's working. after flip, that shape do some action such as( rotate, resize). But i didn't get any points. So i searched flip algorithm for basic. i didn't get it. If you know pls share your comments.

解决方案

Matrix is your friend. The truth is that it is kind of a messy thing to use because it is applied to the canvas and it is a weird way to look at things but it will be your friend once you notice the calculations.

First put it down on paper and know what to do to the canvas to place your shape where you want. Maybe you need to translate the center to the center of you shape, then rotate and, finally, draw. Then go back to the original transformation.

If you follow the API you´ve got canvas.save(), canvas.rotate(), canvas.scale()... And they go as "adds a rotation to the current matrix" or so. Even you can give a matrix you´ve built yourself.