The origin is the rotation’s fixed point unless stated otherwise. In a 90 degree clockwise rotation, the point of a given figure’s points is turned in a clockwise direction with respect to the fixed point. However, in this case, if all you want to optimize is rotation, you can do better. The 90-degree clockwise rotation represents the movement of a point or a figure with respect to the origin, (0, 0). The two dimensional name would be Matrix. Also, a vector is a name for something one dimensional. Making Vector and vector mean different things is confusing. If you had written out the name, it would have been trivial for me to tell that this was using std::swap. One of the advantages of namespaces is that they make it simple to tell the source of a piece of code. But if I look for std::swap, I can find it easily. When I first read this line, I started looking for a function called swap in your code. More details at Why is using namespace std bad practice? swap(image, image) Ĭase in point.
#90 DEGREE CLOCKWISE ROTATION CODE#
Since we are expected to not create another array, we are going to modify the input array directly.Try to avoid importing namespaces like this, as it makes the code less readable and harder to maintain. Since we have figured out the range and the implementation, we have wrap up our programming function rotate(matrix) The vector (1,0) rotated +90 deg CCW is (0,1). We can see that j is likely to run from i to n-1-i. The X,Y equations listed are for CW rotations but the calculator tells you to define CCW as positive. (4) EC: In the above graph (draw this on your own graph paper). rotate(90deg) A positive value of the rotation angle rotates the element in the clockwise direction while a negative value rotates the element in the anti-clockwise direction. Click and drag the blue dot to see its image after a 90 degree clockwise rotation (the green dot). The value of the rotation angle can be specified in degrees.
Basically we have for (let i = 0 i definite not let j run from j. The rotate() function allows you to rotate any HTML element in a 2-dimensional space. The question here is “What are the range for each loop?” and “What are we going to implement in each loop cycle?”. Since this is a 2D array, so obviously we will need one iteration inside another. When the object is rotating towards 90 anticlockwise then the given point will change from (x,y) to (-y,x). The second row turns into the second-last columnĪnd there are two square cycles which are // first cycle 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 // second cycle 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Rule of 90 Degree Rotation about the Origin When the object is rotating towards 90 clockwise then the given point will change from (x,y) to (y,-x).The first row turns into the last column.First let's examine the example and we can see that there is a pattern here When we rotate a figure of 90 degrees clockwise, each point of the given figure has to be changed from (x, y) to (y, -x) and graph the rotated figure.