조회 수 5 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 수정 삭제
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 수정 삭제
俄罗斯色情 - https://www.blackcurve.com/casino-non-gamstop/reviews/li-bet/;

俄罗斯方块旋转算法 Baeldung中文网


1. Overview


In this tutorial, we’ll discuss the algorithm behind rotating Tetris pieces. We’ll start by discussing the equation for rotating a shape in general. Then, we’ll define a data structure that can be used to manipulate the Tetris pieces’ rotations.

Christmas of the Blessed Virgin Cathedral aerial view around residential city block. Religious and travel attractions and destinations

Finally, we’ll present the algorithm to rotate a Tetris piece and finish with a quick conclusion.


2. Rotating a Shape


First, let’s define the problem from a logical and mathematical point of view. Then, we can extract the general equations to rotate a point in the cartesian coordinate system.


The Tetris game consists of the following 7 main shapes:


Drawing4-1-1024x257.png


Each shape can be rotated and then put on top of others to form straight lines. The allowed rotations for each piece are 90, 180, 270, and 360 degrees, which is the original orientation of the shape. This tutorial discusses the general algorithm to rotate any of the mentioned pieces.


The algorithm should rotate a given Tetris piece by 90 degrees. Calling the algorithm multiple times will generate all the possible rotations for the given piece. As a start, let’s discuss the general rotation equations and then see how to apply them in the intended algorithm.


Since each Tetris piece is a polygon, rotating each of the polygon’s corners alone should give us the resulting rotated piece. Therefore, in this section, we’ll discuss the equations to rotate a point around the origin of the cartesian coordinate axis.


Let’s take a look at the following figure:


Drawing2-1024x825.png


In the coordinates above, we have point quicklatex.com-b6856ac0ab0200ef2ba6287c8 forming an angle quicklatex.com-5f44d9bbc8046069be4aa2989 with the x-axis. For simplicity, we’ll consider the point as a vector with magnitude quicklatex.com-01bcf7e9e043561da78fecf71. Using this representation, we can define equations for quicklatex.com-7e5fbfa0bbbd9f3051cd156a0 and quicklatex.com-38461fc041e953482219abf5d as follows:


    quicklatex.com-5db8fd594df578c9c768b6d2c


    quicklatex.com-4a878e5b1659c780ebc19f1ce


After defining the equations to represent a point in the coordinate axis, let’s rotate the point quicklatex.com-b6856ac0ab0200ef2ba6287c8 to new coordinates quicklatex.com-59f11e327864bfd0dfb602e43. The rotation is shown in the following shape:


Drawing1-1024x825.png


The original point was rotated by quicklatex.com-0f39b655b53423e80558c68b8 degrees to the new coordinates quicklatex.com-59f11e327864bfd0dfb602e43 having a new magnitude of quicklatex.com-ebee390253a45105959c2bc4c. We can see that the new point forms an angle quicklatex.com-b7847fbf11b2aa11799e33624 with the x-axis. Likewise, we can define equations for quicklatex.com-59f11e327864bfd0dfb602e43 as follows:


    quicklatex.com-17e19de9822aa541042581683


    quicklatex.com-f419abceb484246c1d72f1517


To find the rotation equations, we need to find quicklatex.com-7e9240d4beef863c91299bf5e and quicklatex.com-64a0a8e8f9cf320aa10cf6e5c as functions to the original coordinates quicklatex.com-2234c4dc1f3099131d36c7e7f and quicklatex.com-4149db711c9e681cd65bbdb52. To do this, we’ll use the following known equations of quicklatex.com-f9be6c4b03749d6dff440419d and quicklatex.com-d3762ae196ab67f79666c057e for the sum of two angles:


    quicklatex.com-89a753a6da38fbbd2305d29c3


    quicklatex.com-c2fa76ce228dfda73d160505d


Additionally, rotating a vector doesn’t change its magnitude. Therefore, the following equation applies:


    quicklatex.com-9ca1d85754543ceb277253df8


Now, we can use the above equations to rewrite our formula for quicklatex.com-b4a147f08046ded14d94e9286 and quicklatex.com-e3860fc68d5fca7cb5a4fdd0e:


    quicklatex.com-46b968e7c6df26ccf18976386


    quicklatex.com-656347a9fb7b527d62491a62a


We can simplify them using the equations we defined in section 2.2 to the following ones:


    quicklatex.com-4d7ebddbf7165f776e7f1f533


    quicklatex.com-78a9edd83e9a4718937dbfb61


Now, we can use these equations to create an algorithm that can rotate a Tetris piece. Let’s start by defining the data structure to store the pieces.


3. Structure Definition


We need to define the structure that will store the Tetris pieces. To do that, we can define each shape as a set of points which are the corners of the shape. In addition, the structure must support rotating the Tetris pieces.


It’s worth noting that Tetris pieces are rotated around their origin. Therefore, we need to define the center point for each shape as well. Take a look at the following figure that shows the different rotations of each shape along with its origin:


Drawing3-1-1024x666.png


Therefore, for each shape, we’ll have an array quicklatex.com-639d86127b094ce8bbe81128a containing the shape’s corner points and a variable quicklatex.com-d450e5d51eb316725457ede5e containing the shape’s origin. Now that we defined the structure, we can move into implementing the rotation algorithm.


4. Algorithm


To implement a rotation algorithm, we only need one function called quicklatex.com-8f1b273ba5e45c0a34affba15, which rotates the given shape by the given angle. Note that the piece is not initially located at the coordinated axis’s center. Therefore, the algorithm must shift the shape to the center of the coordinate axis, perform the rotations, and then shift the point back.


Let’s take a look at the algorithm:


The function takes the array of points, the origin of the shape, and the rotation angle quicklatex.com-349fdc9f5f41a6ecbf5e500a9 as input. We start by defining quicklatex.com-2795d6cdf89a6089128d4299f, which will hold the resulting rotated points. Note that the origin stays the same after the rotation, so we don’t need to return it.


Next, we iterate over all the points of the shape. We need to shift each point as if the shape’s origin is moved to the centre of the coordinate axis. If the origin is moved to the centre, then it shifts to point quicklatex.com-e6f462232b138f5ab691a1230. At this time, the point will also shift with the same amount. Therefore, we shift the point by quicklatex.com-0ac9845abea641290db727c47. As a result, we define quicklatex.com-e6e1c3611728e9db0e52bb648 and quicklatex.com-2b1ce6fe7664ef728c0428024, which are the shifted coordinates.


Then, we perform the rotation by defining quicklatex.com-606a5fa3feb8ab19bd3c2da65 and quicklatex.com-4e8d5da324a650dffbf976bdf which are the coordinates for the rotated point, by applying the equations from section 2. After that, we shift the new points quicklatex.com-606a5fa3feb8ab19bd3c2da65 and quicklatex.com-4e8d5da324a650dffbf976bdf back away from the centre of the coordinate axis. Finally, we add the new points to the list of rotated points we created.


In the end, we return the resulting quicklatex.com-2795d6cdf89a6089128d4299f as the new shape corder points after performing the rotation.


5. Conclusion


In this article, we discussed the algorithm for rotating Tetris pieces. We started by discussing the rotation problem in general and then moved to define the structure that stores the Tetris pieces and the algorithm for rotating them.


List of Articles
번호 제목 조회 수
7882 Three Lies 电报telegram纸飞机s Tell 4
7881 Post New Release Pornography Sites - Tail It Be A Goldbrick? 11
7880 Are Men's Sexual Health Supplements Condom? 6
7879 ����Ҫ��ô��ǿ�Լ�����������ץ������6��׳���˶���_���Խ���_����_99������ 67
7878 Packers and Movers Adambakkam – Budget Relocation Solutions with 1 BHK House Shifting in Adambakkam, Bike Shifting Services in Adambakkam & Safe Packing Service Near Me | Top 10 Packers And Movers in Adambakkam | Check Packers and Movers Charges 0
7877 Shameful Facts Approximately Scoop Tribade Sexual Activity Sites Told By A Job 2
7876 Adverbs More Or Less "best" , "the Best" , And "most" English Lyric Learners Deal Exchange 1
7875 Scoop Pizza Eating House In Melbourne Metropolis CBD 0
7874 7 Lies 电报telegram纸飞机s Tell 10
7873 Administration immobilière à Saguenay : Une administration professionnelle pour vos biens 1
7872 L'immobilier de lieux de travail sur le Québec : Tendances, opportunités et gestion 0
7871 ТОП вебкам сайтов 2025 и альтернативы 1
7870 Finding 最佳蓝色犀牛药 EPL Alliance 1
7869 Ways To Use Of Goods And Services Scoop Ladyboy Sites 2
7868 What Virtually Hoi Polloi Are Locution Just About Steal Viagra Citrate Is Utter Legal Injury And Why 6
7867 anyofai anyofai github.io: 最新ChatGPT Plus开通攻略:如何在国内充值订阅ChatGPT Plus会员?如何购买ChatGPT Plus账号和ChatGPT Pro账号?如何使用GPT-5-Codex?本文会为大家重点介绍五种升级ChatGPT Plus会员的方法:拼车合租ChatGPT Plus账号、购买ChatGPT Plus独立账号、为你的ChatGPT Plus代充值、使用苹果Apple礼品卡充值ChatGPT Plus会员、使用国外的虚拟信用卡订阅C 0
7866 Five Lies 电报telegram纸飞机s Tell 12
7865 Лучшие платные подписки на порно 1
7864 самолучший новоиспечённый порносайт 2022 1
7863 Your Journey To Find Wholesale Bulk T-shirts Is A Straightforward Job If You Recognize Where To Look. If Your Closet Is Filled Exclusively With Blue Jeans, White T-shirts And Black Leather-based Jackets, Or The One Sort Of Music You Take Heed To Star 1
Board Pagination Prev 1 ... 352 353 354 355 356 357 358 359 360 361 ... 751 Next
/ 751