![]() So from 0 degrees you take (x, y) and make them negative (-x, -y) and then you've made a 180 degree rotation. By default its the same size as the parent square. Since rotation in Unitys UI happens after all sizing and positioning is done, the corners of this square stick outside the maximum area. ![]() Its a square, and will be rotated 45 degrees. Specify appropriate parameters and press OK. When you rotate by 180 degrees, you take your original x and y, and make them negative. Background: Im creating a UI element in Unity and need to rotate it. When component has not rotated yet right click on the component and select 'Fanout' function from submenu. If you have a point on (2, 1) and rotate it by 180 degrees, it will end up at (-2, -1) We do the same thing, except X becomes a negative instead of Y. ![]() If you understand everything so far, then rotating by -90 degrees should be no issue for you. Our point is as (-2, -1) so when we rotate it 90 degrees, it will be at (1, -2)Īnother 90 degrees will bring us back where we started. What about 90 degrees again? Same thing! But remember that a negative and a negative gives a positive so when we swap X and Y, and make Y negative, Y actually becomes positive. Our point is at (-1, 2) so when we rotate it 90 degrees, it will be at (-2, -1) What if we rotate another 90 degrees? Same thing. So from 0 degrees you take (x, y), swap them, and make y negative (-y, x) and then you have made a 90 degree rotation. When you rotate by 90 degrees, you take your original X and Y, swap them, and make Y negative. If you have a point on (2, 1) and rotate it by 90 degrees, it will end up at (-1, 2) The required points / coordinates are marked as Red color circles in Figure 3.In case the algebraic method can help you: So that I can implement the resizing of my components correctly? Let me know is there is any mathematics that can be applied? How do I calculate the Bounds / Center of the Yellow Rectangle. To do this, I’ll grab my rectangle tool (red arrow in the image above), left-click on a color in the Swatches panel (blue arrow) to select a color for the rectangle, and will click and drag my mouse on the canvas to draw the rectangle. Bounds of Re-sized rectangle at Rotation = -45 degrees. Method 1: Rotate On-Canvas with Rotation Handles Let’s start by drawing an object.Bounds of Actual (Not re-sized) rectangle at Rotation = -45 degrees.Bounds of Actual (Not re-sized) rectangle.The obtained rectangle Pink color is shifted upwards compared to the Green rotated rectangle and that is varying depends on the Angle of rotation. ![]() In Figure 3 the yellow color rectangle is the Expected/Required out put. Comparison of the obtained and expected rectangle is shown in Figure 3. So the Figure 2's Pink Rectangle should have Left, Right, and Bottom coordinates same as Figure 1's Green Rectangle. Remember I am doing resizing while the component is at rotation angle -45 degrees, so while dragging Top Edge rectangle's Left, Right and Bottom positions should not be changed. The rotated Rectangle is also shown in pink color. Now going to re-size the Top edge of the rectangle and displayed in next Figure 2.įrom the Figure 2 it is understood that the Y position is reduced to 4 from 6. ![]() rotated by -45 Degrees, Center is (10,10). Consider the Green Rect as the components initial bounds, ie. The following Figure displays two rectangles whose bounds are also known and displayed in respective colors. I can explain it with the help of some images. I need a math solution to find out the x,y coordinates of a rotated rectangle with respect to the actual rectangle's bounds. If you are using the Photos App, if you rotate an image, it is not really rotated, it is just marked as rotated. The problem is while resizing top edge, the Let, Right and Bottom edges should be fixed, and I cannot able to fix it if the rotation angle is other than 0 degrees. I am using RectF to keep the bounds of the component, For rotation I am using canvas.rotate(angle, bounds.centerX(),bounds.centerY()) method. Consider creating an image view its Top,Right,Bottom, and Left edges are scalable by touching and dragging the required edge. The components are re-sizable and rotatable by touching. I am trying to create custom components in Android using Surfaceview and canvas drawing. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |