A Rubik's Cube rotation method, device, electronic device and storage medium
By determining the rotation layer where the three blocks on the Rubik's Cube are located, and obtaining the target position and rotation values of all blocks in the layer, the problem of difficulty in implementing the Rubik's Cube in the existing technology is solved, and the flexible Rubik's Cube rotation function is realized.
Patent Information
- Application Number
- CN202211053096.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-31
- Publication Date
- 2025-07-01
- Estimated Expiration
- 2042-08-31
AI Technical Summary
When implementing the rotation of the existing virtual Rubik's Cube, multiple rotating bodies and complex algorithms are required to set up, resulting in the fixed order of the Rubik's Cube and the difficulty of achieving greater implementation when the order is large.
By determining the three blocks on the Rubik's Cube that are located on the same layer, determine the rotation layer, and obtain the target position and target rotation value of all blocks in the layer, and finally play the rotation animation based on this information.
The flexible rotation of the Rubik's Cube is realized. Regardless of the order of the Rubik's Cube, the rotation layer can be found through this method, simplifying the rotation process of the rotating layer and avoiding the complexity of designing the algorithm alone.
Smart Images

Figure CN115317889B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of electronic technologies, and in particular, to a Rubik's Cube rotation method, apparatus, electronic device, and storage medium. Background Art
[0002] As an intellectual game tool, the Rubik's Cube has strong universality. With the development of social intelligence, many platforms have realized virtual Rubik's Cubes for human-computer interaction, allowing users to play with Rubik's Cubes directly on platforms such as mobile phones and computers, eliminating the need for physical Rubik's Cubes.
[0003] In existing virtual Rubik's Cube games, to achieve the rotation of the Rubik's Cube, a rotating body needs to be set up first. Taking a three-order Rubik's Cube as an example, there are three layers on each of the X-axis, Y-axis, and Z-axis. To achieve the rotation of each layer, 9 rotating bodies need to be set up. When rotating, it is necessary to first find the coordinates of the central block of the rotating body, then find the coordinates of the remaining 8 blocks based on the coordinates of the central block, and then rotate each block. However, since the positions of each rotating body are different, a separate algorithm is required to determine the coordinates of the central block of each rotating body. Therefore, the order of the Rubik's Cube can only be fixed, and if the order of the Rubik's Cube is large and the number of rotating bodies increases, it is more difficult to implement. Summary of the Invention
[0004] The present invention provides a Rubik's Cube rotation method, apparatus, electronic device, and storage medium for realizing the rotation function of the Rubik's Cube in response to user actions.
[0005] In a first aspect, an embodiment of the present invention provides a Rubik's Cube rotation method, including:
[0006] Determine three blocks on the Rubik's Cube, where the three blocks are located on the same layer;
[0007] Determine the rotating layer according to the three blocks;
[0008] Obtain the target positions and target rotation values of all blocks in the rotating layer;
[0009] Play a rotation animation according to the target positions and target rotation values.
[0010] Optionally, the determining three blocks on the Rubik's Cube includes:
[0011] Take the block corresponding to the position at the start of the user's slide as the first block;
[0012] Take the block corresponding to the position at the end of the user's slide as the second block;
[0013] Determine the third block, where the third block is obtained by performing a ray detection from the first block in the negative direction of the vertex normal of the position at the start of the user's slide.
[0014] Optionally, performing a ray detection in the negative direction of the vertex normal at the position when the first square starts to slide towards the user to determine the third square, including:
[0015] Performing a ray detection in the negative direction of the vertex normal at the position when the first square starts to slide towards the user to obtain candidate squares;
[0016] Determining that the first square, the second square, and the candidate square uniquely determine a layer;
[0017] Taking the candidate square as the third square.
[0018] Optionally, the method further includes:
[0019] Generating a search record; the search record includes records of each layer of the Rubik's Cube, and the record of each layer includes the layer number of the corresponding layer and the numbers of all squares in the corresponding layer; the Rubik's Cube includes 3*n layers, namely n layers perpendicular to the X-axis, n layers perpendicular to the Y-axis, and n layers perpendicular to the Z-axis; each layer has n*n squares; where n is the order of the Rubik's Cube and n>1.
[0020] Optionally, the determining the rotation layer according to the three squares includes:
[0021] Traversing the layers in the search record;
[0022] Determining the numbers of the three squares included in the layer to obtain the corresponding layer number;
[0023] Determining the rotation layer according to the layer number.
[0024] Optionally, the obtaining the target positions and target rotation values of all squares in the rotation layer includes:
[0025] Rotating the initial vector of the corresponding square in the rotation layer by a certain rotation angle along the rotation axis to obtain a termination vector;
[0026] Determining the target position; the target position is obtained by adding the center vector and the termination vector;
[0027] Determining the target rotation value; the target rotation value is obtained according to the rotation axis and the rotation angle;
[0028] Wherein, the rotation axis is the normal vector at the center position of the rotation layer; the initial vector is the vector from the world position of the center of the rotation layer to the world position of the square in the rotation layer; the center vector is the vector from the world center to the world position of the center of the rotation layer.
[0029] Optionally, the determining the target rotation value includes:
[0030] Obtain a rotation increment value based on the rotation axis and rotation angle;
[0031] Obtain the target rotation value based on the rotation increment value.
[0032] In a second aspect, an embodiment of the present invention provides a Rubik's Cube rotation device, including:
[0033] A selection module for determining three blocks on the Rubik's Cube, where the three blocks are located on the same layer;
[0034] A first processing module for determining the rotation layer according to the three blocks;
[0035] A second processing module for obtaining the target positions and target rotation values of all blocks in the rotation layer;
[0036] A rotation module for playing a rotation animation according to the target positions and target rotation values.
[0037] In a third aspect, an embodiment of the present invention provides an electronic device, including a memory and a processor. A computer program is stored on the memory, and when the processor executes the program, the method described in any item of the first aspect is implemented.
[0038] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method described in any item of the first aspect is implemented.
[0039] The present invention has the following effects:
[0040] The present invention provides a Rubik's Cube rotation method. The method first determines three blocks on the Rubik's Cube, and the three blocks are located on the same layer; then determines the rotation layer according to the three blocks; then obtains the target positions and target rotation values of all blocks in the rotation layer; and finally plays a rotation animation according to the target positions and target rotation values. In the present invention, the rotation layer is determined according to three blocks located on the same layer. Therefore, regardless of the order of the Rubik's Cube, the rotation layer can be found through this method, and this method does not limit the order of the Rubik's Cube when realizing the rotation of the Rubik's Cube. And the rotation of the entire layer is realized according to the rotation of all blocks in the rotation layer, and no separate algorithm design is required for the rotation layer, and the implementation is relatively simple.
[0041] It should be understood that the content described in the summary of the invention part is not intended to limit the key or important features of the embodiments of the present invention, nor is it used to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In conjunction with the accompanying drawings and with reference to the following detailed description, the above and other features, advantages, and aspects of the embodiments of the present invention will become more apparent. In the drawings, the same or similar reference numerals denote the same or similar elements.
[0043] Figure 1 It is a flowchart of a single rotation of the Rubik's Cube rotation method according to an embodiment of the present invention.
[0044] Figure 2 It is an overall flowchart of the Rubik's Cube rotation method according to an embodiment of the present invention.
[0045] Figure 3 It is a structural diagram of a Rubik's Cube according to an embodiment of the present invention.
[0046] Figure 4 It is a schematic diagram of rotating a Rubik's Cube according to an embodiment of the present invention.
[0047] Figure 5 It is a schematic diagram of determining the normal vector of the rotation layer according to an embodiment of the present invention.
[0048] Figure 6 It is a schematic structural diagram of a Rubik's Cube rotation device according to an embodiment of the present invention.
[0049] Figure 7 It is a structural diagram of an electronic device according to an embodiment of the present invention. Detailed implementation manners
[0050] In order to enable those skilled in the art to better understand the technical solutions in one or more embodiments of this specification, the following will clearly and completely describe the technical solutions in one or more embodiments of this specification in conjunction with the drawings in one or more embodiments of this specification. Obviously, the described embodiments are only a part of the embodiments of this specification, rather than all the embodiments. Based on one or more embodiments of this specification, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of this document.
[0051] It should be noted that the description of the embodiments of the present invention is only for more clearly explaining the technical solutions of the embodiments of the present invention, and does not constitute a limitation on the technical solutions provided by the embodiments of the present invention.
[0052] This embodiment Figure 1 It is a flowchart of a single rotation of the Rubik's Cube rotation method according to an embodiment of the present invention. Refer to Figure 1 The method includes:
[0053] S101. Determine three blocks on the Rubik's Cube, and the three blocks are located on the same layer.
[0054] In the foreground, the user first randomly selects a cube on the Rubik's Cube through an input device, and then slides the cube to any position. Here, the input device can be a mouse, a keyboard, a gamepad, a touch screen, etc.
[0055] In the background, according to the selected cube and the sliding direction of the user, the corresponding layer on the Rubik's Cube is rotated, and then the rotation picture of the Rubik's Cube is played to the user side. In this implementation, in order to rotate the layer in the background, three cubes that can uniquely determine the layer are introduced. When implementing, first determine three cubes on the Rubik's Cube, then determine a unique layer according to the three cubes, and finally realize the rotation of the entire layer.
[0056] This embodiment Figure 2 is the overall flowchart of the Rubik's Cube rotation method of the embodiment of the present invention; see Figure 2 :
[0057] Before step S101, the Rubik's Cube is initialized to initialize the order of the Rubik's Cube and the position of each cube on the Rubik's Cube. When initializing, first determine the distance between the cubes. Assuming that the cube is a cube with a size of 100*100*100 cubic centimeters, the distance between two adjacent cubes is 100 centimeters. Then, the position of the root component needs to be determined. The root component in this embodiment is the rotation center of the entire Rubik's Cube. Finally, relative to the position of the root component, the position of each cube on the Rubik's Cube is initialized.
[0058] Among them, when initializing the position of each cube on the Rubik's Cube, the cubes on the Rubik's Cube are relatively offset at the position of the root component. In this embodiment Figure 3 is the structure diagram of the Rubik's Cube of the embodiment of the present invention. Referring to Figure 3 , taking a three-order Rubik's Cube as an example, the method for initializing the position of each cube on the Rubik's Cube is as follows:
[0059] It can be generated in order according to an axis. When generating, all the cubes are numbered in sequence according to the generated serial numbers. Assuming that it is generated in order according to the Z axis, it is divided into three layers up and down (three layers perpendicular to the Z axis), with 9 cubes in each layer. The first layer is the uppermost layer. Then, the numbers (serial numbers) of the cubes in the first layer are "0, 1, 2, 3, 4, 5, 6, 7, 8" in sequence; the numbers of the cubes in the second layer are "9, 10, 11, 12, 13, 14, 15, 16, 17" in sequence; the numbers of the cubes in the third layer are "18, 19, 20, 21, 22, 23, 24, 25, 26" in sequence. Using Point0 - Point026 to represent the position coordinates of the 1st cube to the 26th cube, the coordinates of all the cubes on the Rubik's Cube are respectively:
[0060] Point0 (X = 100, Y = -100, Z = 100)
[0061] Point1 (X = 100, Y = 0, Z = 100)
[0062] Point2 (X = 100, Y = 100, Z = 100) ...
[0063] Point18 (X = 100, Y = -100, Z = -100) ...
[0064] Considering that the Rubik's Cube rotates layer by layer, not only the three layers perpendicular to the Z-axis can rotate, but also the three layers perpendicular to the X-axis and the three layers perpendicular to the Y-axis can rotate. Therefore, in this embodiment, stratification is also performed for the X-axis and the Y-axis. The three-order Rubik's Cube in this embodiment has a total of 9 layers, including three layers perpendicular to the X-axis, three layers perpendicular to the Y-axis, and three layers perpendicular to the Z-axis.
[0065] Therefore, in this embodiment, the method may further include:
[0066] Generating a search record; the search record includes records of each layer of the Rubik's Cube, and the record of each layer includes the layer number of the corresponding layer and the numbers of all the blocks in the corresponding layer; the Rubik's Cube includes 3*n layers, which are n layers perpendicular to the X-axis, n layers perpendicular to the Y-axis, and n layers perpendicular to the Z-axis respectively; each layer has n*n blocks; where n is the order of the Rubik's Cube and n>1.
[0067] Assuming it is a three-order Rubik's Cube, the first layer, the second layer, and the third layer perpendicular to the Z-axis generated by the above initialization are saved in the search record, and the blocks numbered 0-8 corresponding to the first layer are saved in the first layer in the search record, the blocks numbered 9-17 corresponding to the second layer are saved in the second layer in the search record, and the blocks numbered 18-26 corresponding to the third layer are saved in the third layer in the search record; the three layers perpendicular to the X-axis are respectively defined as the fourth layer, the fifth layer, and the sixth layer; the three layers perpendicular to the Y-axis are respectively defined as the seventh layer, the eighth layer, and the ninth layer. The fourth layer, the fifth layer, and the sixth layer perpendicular to the X-axis are saved in the search record, and the corresponding positioning blocks (according to the numbers and coordinates generated with the Z-axis) of each layer are saved in the corresponding layer; the seventh layer, the eighth layer, and the ninth layer perpendicular to the Y-axis are saved in the search record, and the corresponding positioning blocks (according to the numbers and coordinates generated with the Z-axis) of each layer are saved in the corresponding layer.
[0068] The initialization method of Rubik's Cubes of other orders is the same as the above generation method and will not be elaborated here.
[0069] After the initialization of the Rubik's Cube is completed, the rotation of the Rubik's Cube can be realized according to the above step S101 and the following steps S102-S104:
[0070] Optionally, in step S101, three blocks on the Rubik's Cube are determined, including:
[0071] First step, take the block corresponding to the position at the start of the user's slide as the first block.
[0072] Since the start position of the user's slide is also the position corresponding to the block selected by the user through the input device, in this example, the block selected by the user through the input device can be regarded as the block corresponding to the position at the start of the user's slide. Optionally, capture the operation of the user selecting any block on the Rubik's Cube, regard the position of the block selected by the user as the start position of the slide, and obtain the block corresponding to the start position of the slide as the first block. The obtained first block can be in the form of a number, position coordinates, etc., and save the vertex normal vector of the position at the start of the slide for subsequent determination of the third block.
[0073] Second step, take the block corresponding to the position at the end of the user's slide as the second block.
[0074] The user can slide to any position. Assume that the face displayed in the foreground is the front face, and the first block is displayed on the front face. When the user slides the first block, the user can still slide towards the front face or towards other faces; when the user slides towards the front face, the user can slide to a position in the same row as the first block, or to a position in the same column as the first block, or to a position that is neither in the same row nor in the same column as the first block. At the end of the slide, the background responds to the operation of the user's slide end, and obtains the block corresponding to the position at the end of the user's slide as the second block. The obtained second block can be represented in the form of a serial number, position coordinates, etc.
[0075] Third step, determine the third block. The third block is obtained by performing a ray detection from the first block in the negative direction of the vertex normal of the position at the start of the user's slide.
[0076] Assume that when the user selects the first block, the selected face is the front face of the Rubik's Cube, and the vertex normal of the position at the start of the user's slide is perpendicular to the front face.
[0077] Optionally, perform a ray detection from the first block in the negative direction of the vertex normal of the position at the start of the user's slide to determine the third block, including:
[0078] Step A1. Perform a ray detection from the first block in the negative direction of the vertex normal of the position at the start of the user's slide to obtain candidate blocks.
[0079] Step A2. Determine that the first block, the second block, and the candidate blocks uniquely determine a layer.
[0080] Optionally, determine whether the first square, the second square, and the alternative square are valid. If they are valid, use the alternative square as the third square.
[0081] It is possible to determine whether the first square, the second square, and the alternative square are valid by calculating whether the first square, the second square, and the alternative square are collinear:
[0082] Determine the coordinates of the first square, the second square, and the alternative square;
[0083] Calculate the first vector from the coordinate position of the first square to the coordinate position of the second square;
[0084] Calculate the second vector from the coordinate position of the first square to the coordinate position of the alternative square;
[0085] Calculate the dot product of the first vector and the second vector.
[0086] Refer to Figure 3 :
[0087] In the first case, if the result is 0, for example, the number of the first square is 8, the number of the second square is 7, and the number of the alternative square is 5, it means that the first square, the second square, and the alternative square are not collinear, and the first vector is perpendicular to the second vector. Then, the first square, the second square, and the alternative square can uniquely determine a layer, and it is considered that the first square, the second square, and the alternative square are valid.
[0088] In the second case, if the result is 1 or -1, for example, the number of the first square is 8, the number of the second square is 7, and the number of the alternative square is 6, it means that the first vector and the second vector are collinear, indicating that the first square, the second square, and the alternative square are collinear. The alternative square can be reselected according to the following steps:
[0089] Step B1. Perform a ray detection in the negative direction of the vertex normal at the position where the user slides to the end from the second square to find the alternative square.
[0090] Step B2. Determine whether the first square, the second square, and the alternative square are valid.
[0091] In step B2, calculate the dot product of the vector from the first square to the second square and the vector from the first square to the alternative square. If the result is 0, it is considered that the first square, the second square, and the alternative square are valid; if the result is 1 or -1, it is considered that the first square, the second square, and the alternative square are invalid. If the number of the reselected alternative square is 4, the first square, the second square, and the alternative square are valid.
[0092] In the third case, if the result is other values, for example, the number of the first square is 8, the number of the second square is 16, and the number of the alternative square is 5, it indicates that the first vector and the second vector are not perpendicular, then the first square, the second square, and the alternative square are considered invalid.
[0093] In this embodiment, the first square, the second square, and the third square can be distinguished by the numbers formed during initialization when making the above determination.
[0094] S102. Determine the rotation layer according to the three squares.
[0095] It can be implemented in the following way:
[0096] First step, traverse and search for the layers in the record;
[0097] Second step, determine the numbers of the three squares included in the layer, and obtain the corresponding layer number;
[0098] Third step, determine the rotation layer according to the layer number.
[0099] In this embodiment Figure 3 is the structure diagram of the Rubik's Cube of the embodiment of the present invention. Refer to Figure 3 , assuming that the Rubik's Cube is a third-order Rubik's Cube, assuming that the number of the first square is 8, the number of the second square is 7, and the number of the third square is 5. Assume that the layers in the record are searched in sequence. First, search for the first layer in the record. The first layer contains all the squares of the first layer, and the numbers of all the squares are recorded, which are 0 - 8 respectively. Search in the first layer with the numbers 8, 7, and 5. The squares in the first layer can be traversed in sequence. First, the positioning block with the number 5 is traversed, and the count is 1; then continue to traverse, and the square with the number 7 is found, and the accumulated count is 2; then continue to traverse again, and the square with the number 8 is found, and the accumulated count is 3. When the count reaches 3, the corresponding first layer is used as the rotation layer, and the traversal of all layers of the Rubik's Cube stops.
[0100] Assume that the number of the first square is 8, the number of the second square is 17, and the number of the third square is 5. Then the square with the number 17 cannot be found in the first layer. When the first layer is traversed, the count is 2,
[0101] then continue to traverse all the positioning blocks in the second layer and re - count, and traverse in sequence until a certain layer (the sixth layer), then the corresponding layer (the sixth layer) is used as the rotation layer.
[0102] S103. Obtain the target positions and target rotation values of all the squares in the rotation layer.
[0103] Obtain the numbers of all the squares in the rotation layer from the search record.
[0104] Optionally, obtain the target positions and target rotation values of all the blocks in the rotating layer, including:
[0105] Figure 4 This is a schematic diagram of the rotating Rubik's Cube according to an embodiment of the present invention. Refer to Figure 4 :
[0106] In the first step, rotate the initial vector a of the corresponding block in the rotating layer along the rotation axis b by a certain rotation angle θ to obtain the termination vector c.
[0107] Figure 5 This is a schematic diagram of determining the normal vector of the rotating layer according to an embodiment of the present invention. Refer to Figure 5 :
[0108] Among them, the rotation axis b is the normal vector of the center of the rotating layer, which can be obtained by taking the vector cross product of the three vectors f, i, and j formed by the world positions of three non-collinear blocks in the rotating layer;
[0109] The initial vector a is the vector from the world position of the center of the rotating layer to the world position of the corresponding block, and the rotation angle θ can be a multiple of 90 degrees, such as 90 degrees, 180 degrees, etc.;
[0110] Among them, the world center M, the world position of the center of the rotating layer, and the world position of the block in the rotating layer can all be obtained through the GetWorldLocation function.
[0111] In the second step, determine the target position.
[0112] The target position is obtained by adding the center vector d and the termination vector c. The center vector d is the vector from the world center M to the world position of the center of the rotating layer.
[0113] As Figure 4 shown, the target position is the end position of the vector e obtained by adding the center vector d and the termination vector c.
[0114] In the third step, determine the target rotation value.
[0115] The target rotation value is obtained according to the rotation axis and the rotation angle. Optionally, determining the target rotation value includes:
[0116] Step C1. Obtain the rotation increment value according to the rotation axis and the rotation angle.
[0117] First, convert the rotation axis into a unit vector with a length of 1, then determine the rotation angle of the unit vector (which can be a multiple of 90 degrees, such as 90 degrees, 180 degrees, etc.), and convert the unit vector of the rotation axis and the rotation angle into a quaternion through the following formula:
[0118] ;
[0119] Among them, v is the rotation axis and θ is the rotation angle.
[0120] Then, convert the quaternion back to the FRotator type to obtain the increased rotation value.
[0121] Step C2. Obtain the target rotation value according to the increased rotation value.
[0122] First, record the current rotation value of the block in the rotation layer, and then add the current rotation value and the increased rotation value to obtain the target rotation value.
[0123] Among them, the target rotation value is the rotation value of the block in the rotation layer on the Pitch, Yaw, and Rol axes after rotating to the target position, and can be used to describe the rotation amount of the block in the rotation layer along its own center point.
[0124] In addition, this embodiment may further include:
[0125] Rotate the block in the rotation layer to the target rotation value, save the target rotation value, and then restore the rotation value of the rotating block to the current rotation value of the block in the rotation layer. For example, if the rotation value of the rotating block after rotating to the target rotation value is (100, 100, 100) and the current rotation value of the block in the rotation layer is (0, 90, 0), then restore the rotation value of the rotating block to (0, 90, 0).
[0126] Obtain the target positions and target rotation values corresponding to all the blocks in the rotation layer in the above manner, preparing for playing the rotation animation subsequently.
[0127] S104. Play the rotation animation according to the target position and the target rotation value.
[0128] It is possible to perform interpolation operations on the current rotation value and the target rotation value for all the blocks in the rotation layer respectively, set the playing time, and stop after playing to the target position and the target rotation value within the playing time.
[0129] Among them, performing interpolation operations on the current rotation value and the target rotation value for the blocks in the rotation layer can be achieved through the following methods:
[0130] Position interpolation operation:
[0131] Obtain the initial vector of the block in the rotation layer, rotate the initial vector along the rotation axis by the corresponding rotation angle to obtain the rotated vector, and the rotated position coordinates of the block in the rotation layer can be obtained through the rotated vector. Among them, the rotation angle can be set by oneself, such as 2 degrees. For each degree of rotation, judge the rotated position coordinates until the rotated position coordinates coincide with or are close to the target position.
[0132] Rotation interpolation operation:
[0133] Obtain the rotation axis, rotate by the corresponding angle, and obtain the rotation accumulation value according to the rotation axis and rotation angle. First, convert the rotation axis into a unit vector with a length of 1, then determine the rotation angle of the unit vector (such as 2 degrees), and convert the unit vector of the rotation axis and the rotation angle into a quaternion through the following formula:
[0134] ;
[0135] where v is the rotation axis and θ is the rotation angle.
[0136] Then, convert the quaternion back to the FRotator type to obtain the rotation accumulation value.
[0137] Obtain the cumulative rotation value. The initial value of the cumulative rotation value is 0. When rotating, every time it rotates by one degree (such as 2 degrees), the cumulative rotation value is accumulated once, and the value accumulated each time is the rotation accumulation value. When the cumulative rotation value stops rotating at the position closest to the target rotation value. Among them, when judging that the cumulative rotation value is closest to the target rotation value, the cumulative rotation value can be converted into a vector of the FVector type, then the length of the vector is obtained, and the most suitable length of the vector is obtained through repeated experiments. For example, when the length of the vector is greater than 800, the rotation stops, and both the rotation and displacement will stop near the final value.
[0138] In this embodiment, the method may further include:
[0139] Reset the positions and rotation values of the blocks in the rotation layer.
[0140] Optionally, set the position coordinates of the blocks in all rotation layers to the target positions and the rotation values to the target rotation values. This can ensure that the initial state during the next rotation is correct and avoid misalignment problems caused by cumulative errors.
[0141] This embodiment provides a Rubik's Cube rotation method. The method first determines three blocks on the Rubik's Cube, where the three blocks are located on the same layer. Then, it determines the rotation layer based on the three blocks, and takes all the blocks in the rotation layer as the blocks in the rotation layer. Next, it obtains the target positions and target rotation values of the blocks in the rotation layer. Finally, it plays a rotation animation according to the target positions and target rotation values. In the present invention, first, three blocks on the Rubik's Cube are determined. According to the principle that "three points can determine a unique plane", a unique rotation layer is determined through the three blocks. When rotating, only the rotation layer needs to be rotated, and the blocks in other layers remain unchanged. The rotation layer includes multiple blocks. When realizing the rotation of the rotation layer, first, all the blocks in the rotation layer are obtained as the blocks in the rotation layer, and then the target positions and target rotation values of each block in the rotation layer are obtained. Furthermore, each block in the rotation layer is rotated according to the corresponding target position and target rotation value, and a rotation screen is played, realizing the rotation of the entire rotation layer. In summary, the present invention realizes the rotation function of the Rubik's Cube.
[0142] The above combination Figures 1 - 5 has described in detail the Rubik's Cube rotation method provided by the embodiments of this application. The following combination Figure 6 will describe in detail the Rubik's Cube rotation device for executing the Rubik's Cube rotation method provided by the embodiments of this application.
[0143] This embodiment Figure 6 is a structural schematic diagram of the Rubik's Cube rotation device according to the embodiments of the present invention; as Figure 6 shown, the Rubik's Cube rotation device includes:
[0144] A selection module 601, configured to determine three blocks on the Rubik's Cube, where the three blocks are located on the same layer;
[0145] A first processing module 602, configured to determine the rotation layer according to the three blocks;
[0146] A second processing module 603, configured to obtain the target positions and target rotation values of all the blocks in the rotation layer;
[0147] A rotation module 604, configured to play a rotation animation according to the target positions and target rotation values.
[0148] For the specific implementation of the Rubik's Cube rotation device, refer to the foregoing Rubik's Cube rotation method, which will not be elaborated here.
[0149] The embodiments of the present invention also provide a computer electronic device. Figure 7 is a structural diagram of an electronic device according to the embodiments of the present invention. Refer to Figure 7, the computer electronic device includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 702 or the program loaded from the storage section 708 into the random access memory (RAM) 703. In the RAM 703, various programs and data required for system operation are also stored. The CPU 701, ROM 702, and RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0150] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, a mouse, etc.; an output section 707 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc. and a speaker, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN card, a modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 710 as needed so that a computer program read from it can be installed into the storage section 708 as needed.
[0151] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagram may represent a module, a program segment, or a part of code that contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than marked in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and the combination of blocks in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based system that performs the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.
[0152] The units or modules involved in the embodiments of the present invention can be implemented in software or in hardware. The described units or modules can also be provided in a processor. For example, it can be described as: A processor includes a selection module 601, a first processing module 602, a second processing module 603, and a rotation module 604. Among them, the names of these modules do not constitute a limitation on the module itself in some cases. For example, the first processing module 602 can also be described as "the first processing module 602 for determining the rotation layer according to the three squares".
[0153] As another aspect, the present invention also provides a computer-readable storage medium. The computer-readable storage medium can be the computer-readable storage medium included in the Rubik's Cube rotation device in the above embodiments; or it can exist alone and be a computer-readable storage medium not assembled into an electronic device. The computer-readable storage medium stores one or more programs, and the one or more programs are used by one or more processors to execute the Rubik's Cube rotation method described in the present invention.
[0154] The above description is only a preferred embodiment of the present invention and an explanation of the applied technical principles. Those skilled in the art should understand that the scope of the invention involved in the present invention is not limited to the technical solutions formed by the specific combination of the above technical features, and should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the inventive concept. For example, the technical solutions formed by mutually replacing the above features with the (but not limited to) technical features having similar functions disclosed in the present invention.
Claims
1. A method for rotating a Rubik's Cube, characterized in that, Including: Determine three blocks on the Rubik's Cube, and the three blocks are located on the same layer; Determine the rotation layer according to the three blocks; Obtain the target positions and target rotation values of all blocks in the rotation layer; Play a rotation animation according to the target positions and target rotation values; The determining of the three blocks on the Rubik's Cube includes: Take the block corresponding to the position at the start of the user's slide as the first block; Take the block corresponding to the position at the end of the user's slide as the second block; Determine the third block, and the third block is obtained by performing a ray detection from the first block in the negative direction of the vertex normal of the position at the start of the user's slide.
2. The Rubik's Cube rotation method according to claim 1, wherein The performing of the ray detection from the first block in the negative direction of the vertex normal of the position at the start of the user's slide to determine the third block includes: Perform a ray detection from the first block in the negative direction of the vertex normal of the position at the start of the user's slide to obtain candidate blocks; Determine that the first block, the second block, and the candidate blocks uniquely determine a layer; Take the candidate block as the third block.
3. The Rubik's Cube rotation method according to claim 1, characterized in that, The method further includes: Generate a search record; the search record includes records of each layer of the Rubik's Cube, and the record of each layer includes the layer number of the corresponding layer and the numbers of all blocks in the corresponding layer; the Rubik's Cube includes 3*n layers, namely n layers perpendicular to the X-axis, n layers perpendicular to the Y-axis, and n layers perpendicular to the Z-axis; each layer has n*n blocks; where n is the order of the Rubik's Cube and n>1.
4. The Rubik's Cube rotation method according to claim 3, characterized in that, The determining of the rotation layer according to the three blocks includes: Traverse the layers in the search record; Determine the numbers of the three blocks included in the layer and obtain the corresponding layer number; Determine the rotation layer according to the layer number.
5. The Rubik's Cube rotation method according to claim 1, wherein, The obtaining of the target positions and target rotation values of all blocks in the rotation layer includes: Rotate the initial vector of the corresponding block in the rotation layer by a certain rotation angle along the rotation axis to obtain a termination vector; Determine the target position; the target position is obtained by adding the center vector and the termination vector; Determine the target rotation value; the target rotation value is obtained according to the rotation axis and the rotation angle; Wherein, the rotation axis is the normal vector of the center position of the rotation layer; the initial vector is the vector from the world position of the center of the rotation layer to the world position of the block in the rotation layer; the center vector is the vector from the world center to the world position of the center of the rotation layer.
6. The Rubik's Cube rotation method according to claim 5, characterized in that, The determining of the target rotation value includes: Obtain a rotation increment value according to the rotation axis and the rotation angle; Obtain the target rotation value according to the rotation increment value.
7. A Rubik's Cube rotation device, characterized in that, Including: A selection module, configured to determine three blocks on the Rubik's Cube, and the three blocks are located on the same layer; A first processing module, configured to determine the rotation layer according to the three blocks; A second processing module, configured to obtain the target positions and target rotation values of all blocks in the rotation layer; A rotation module, configured to play a rotation animation according to the target positions and target rotation values; The determining of the three blocks on the Rubik's Cube includes: Take the block corresponding to the position at the start of the user's slide as the first block; Take the block corresponding to the position at the end of the user's slide as the second block; Determine the third block, which is obtained by performing a ray detection in the negative direction of the vertex normal at the position when the first block starts to slide towards the user.
8. An electronic device, comprising a memory and a processor, wherein a computer program is stored on the memory, characterized in that, When the processor executes the computer program, it implements the method according to any one of claims 1-6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the method according to any one of claims 1-6.
Citation Information
Patent Citations
Colorful magic cube
CN105641919A
Magic cube virtual method and system
CN106874631A