A method, apparatus and computer readable storage medium for simulating electronic movement
By obtaining the wire length and electron spacing, and utilizing the 3D rendering capabilities of the Unity engine, the number and position of electrons on the wire are dynamically adjusted, solving the problem of low electron movement performance in traditional simulation methods and achieving efficient and flexible electron simulation effects.
Patent Information
- Application Number
- CN202410898710.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-05
- Publication Date
- 2025-12-12
- Estimated Expiration
- 2044-07-05
AI Technical Summary
Traditional methods of simulating electron movement in wires cannot efficiently and flexibly represent the dynamic behavior of electrons, especially on mobile devices where they are inefficient and lack flexibility.
The number of electrons is determined by obtaining the length of the wire, and the position and number of electrons on the wire are adjusted in real time according to the electron spacing and position. By utilizing the 3D rendering capabilities of the Unity engine and combining path and speed update mechanisms, the movement of electrons is dynamically controlled.
It enables efficient and flexible simulation of electron movement along a wire path, dynamically adjusting the path and speed, reducing computational load, and improving simulation efficiency, making it suitable for electronic physics teaching and research.
Smart Images

Figure CN118965935B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to computer graphics and simulation technology, in particular to a method, device and computer readable storage medium for simulating electron movement. BACKGROUND
[0002] In electronic engineering and physics teaching, simulating the movement path of electrons in a wire is crucial to understanding the working principle of a circuit. Traditional simulation methods have limitations, such as being unable to visually display the dynamic behavior of electrons.
[0003] To simulate electron movement, a common method is to use a particle system, however, a particle system is a very CPU-intensive component, especially on mobile devices, with very low performance, and once the particle system is played, the particles can only move according to the original settings, with low flexibility. SUMMARY
[0004] The technical problem to be solved by the present application is to provide a method, device and computer readable storage medium for simulating electron movement, which can efficiently and flexibly simulate the movement of electrons on a wire.
[0005] To solve the above technical problems, the present application adopts a technical solution:
[0006] A method for simulating electron movement, comprising the steps of:
[0007] obtaining the length of a wire to be simulated, and determining the number of electrons needed according to the length of the wire;
[0008] determining the position of each electron on the wire according to the length of the wire, the number of electrons and a preset electron spacing, and simulating the movement of electrons on the wire according to the position of each electron on the wire;
[0009] adjusting the number and position of moving electrons on the wire in real time according to the change in the length of the wire.
[0010] Further, the adjustment of the number and position of moving electrons on the wire in real time according to the change in the length of the wire comprises:
[0011] determining the number of electrons needed as a target number of electrons according to the change in the length of the wire;
[0012] determining whether the number of existing electrons in the cache is less than the target number of electrons, if so, obtaining or recreating the missing electrons from the object pool, if not, determining the number of excess electrons, and transferring the excess number of electrons from the cache to the object pool;
[0013] traversing the electronic objects in the cache, determining the absolute distance and relative distance of each electronic object, and adjusting the position of the electronic object moving on the wire in real time according to the absolute distance and relative distance.
[0014] Further, the adjusting the position of the electronic object moving on the wire in real time according to the absolute distance and relative distance comprises:
[0015] determining the final position of the electronic object on the wire according to the absolute distance;
[0016] determining the time length of the electronic object moving on the wire according to the relative distance;
[0017] determining the initial position of the electronic object on the wire according to the time length;
[0018] adjusting the position of the electronic object moving on the wire in real time according to the initial position, final position and speed.
[0019] Further, the method further comprises the steps of:
[0020] receiving a wire path update trigger request;
[0021] determining an updated path point according to the wire path update trigger request, judging whether the updated path point is the same as the original path point, and if yes, performing a speed updating step;
[0022] if no, determining an updated path length and updated content according to the wire path update trigger request, judging whether the updated path length and updated content are the same as the original path length and original content, and if yes, performing the speed updating step;
[0023] if no, judging whether the difference between the updated path length and the original path length and the difference between the updated content and the original content are both less than a preset value, and if yes, performing the speed updating step;
[0024] if no, updating the wire path point according to the wire path update trigger request, and calculating the total length of the wire path and the total moving time of the updated wire;
[0025] adjusting the number and position of the electronic objects moving on the wire according to the total length of the wire path and the total moving time.
[0026] Further, the speed updating step comprises:
[0027] receiving a speed update trigger request;
[0028] determining whether the speed updating time is reached, if yes, determining whether the updated speed is not zero and the difference between the updated speed and the original speed is greater than a preset difference according to the speed updating trigger request, if yes, updating the speed of each electron on the wire and determining the time length of each electron moving on the wire according to the updated speed and the original speed.
[0029] Further, when receiving the request of wire path updating or speed updating, the updated path information or speed information is cached first;
[0030] When receiving the wire path updating trigger request or the speed updating trigger request, the corresponding updating operation is performed according to the latest stored path information or speed information in the cache.
[0031] Further, the simulation of the movement of the electron on the wire according to the position of the electron on the wire comprises:
[0032] determining whether the number of points on the wire path is greater than 2, if yes, calculating the current position of each electron on the wire;
[0033] controlling the movement of the electron on the wire according to the current position and the speed of the electron;
[0034] calculating the time length of the movement of the electron on the wire in real time;
[0035] determining whether the time length is greater than the total movement time length of the wire, if yes, resetting the position of the electron to the corresponding starting position and the time length of the movement of the electron on the wire, if no, updating the position of the electron by interpolation calculation.
[0036] Further, the method further comprises the steps of:
[0037] receiving a resource recycling request;
[0038] stopping the animation of simulating the movement of the electron according to the resource recycling request;
[0039] emptying the path point data of the wire;
[0040] destroying the electron in the cache and emptying the cache;
[0041] resetting the total length of the wire and the total movement time of the wire.
[0042] In order to solve the above technical problems, another technical solution adopted by the present application is:
[0043] An apparatus for simulating movement of an electron comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method for simulating movement of an electron when executing the computer program.
[0044] To solve the above technical problems, another technical solution adopted by the present application is:
[0045] A computer readable storage medium having computer program instructions stored thereon, wherein the computer program instructions, when executed by a processor, implement the steps of the method for simulating movement of an electron.
[0046] The present application has the beneficial effect that by obtaining the length of the wire to be simulated to determine the number of electrons needed, determining the position of each electron on the wire according to the length of the wire, the number of electrons and the preset distance between the electrons, simulating the movement of the electrons on the wire according to the position of each electron on the wire, and adjusting the number and position of the moving electrons on the wire in real time according to the length change of the wire, the movement of the electrons along any given wire path can be dynamically simulated, the dynamic control of the movement of the electrons is realized, and the movement of the electrons on the wire is efficiently and flexibly simulated. BRIEF DESCRIPTION OF DRAWINGS
[0047] Figure 1 A step flow chart of a method for simulating movement of an electron according to an embodiment of the present application;
[0048] Figure 2 A structural schematic diagram of an apparatus for simulating movement of an electron according to an embodiment of the present application;
[0049] Figure 3 A step flow chart of creating a corresponding number of electrons according to the path length according to an embodiment of the present application;
[0050] Figure 4 A step flow chart of implementing path update and speed update according to an embodiment of the present application;
[0051] Figure 5 A step flow chart of implementing animation playing according to an embodiment of the present application;
[0052] Figure 6 A step flow chart of resource recycling according to an embodiment of the present application. DETAILED DESCRIPTION
[0053] To explain the technical content, the achieved purposes and effects of the present application in detail, the following will be described in conjunction with the embodiments and the accompanying drawings.
[0054] The method, device and computer readable storage medium for simulating movement of an electron described above can be applied to various scenarios requiring simulation of movement of an electron, such as electron physics teaching, physics research, and the like, which will be described below through a specific implementation.
[0055] In an optional implementation, as shown in Figure 1 a method for simulating movement of an electron includes the steps of:
[0056] S1, obtaining a length of a wire to be simulated, and determining a number of electrons required according to the length of the wire;
[0057] wherein the step of determining the number of electrons required according to the length of the wire includes:
[0058] obtaining a spacing between the electrons;
[0059] determining the number of electrons required according to the length of the wire and the spacing;
[0060] S2, determining positions of the electrons on the wire according to the length of the wire, the number of the electrons and a preset spacing between the electrons, and simulating movement of the electrons on the wire according to the positions of the electrons on the wire;
[0061] S3, adjusting the number and positions of the moving electrons on the wire in real time according to a change in the length of the wire;
[0062] In this implementation, the 3D rendering capability of the Unity engine is used to simulate a movement path of the electron in the wire.
[0063] In another optional implementation, as shown in Figure 3 the step of adjusting the number and positions of the moving electrons on the wire in real time according to the change in the length of the wire includes:
[0064] determining the number of electrons required according to the change in the length of the wire, i.e., eleCount = floor(pathLength / spacingBetweenElectrons), as a target number of electrons;
[0065] determining whether the number of the existing electrons in the cache is less than the target number of electrons, if yes, obtaining or recreating the missing electrons from an object pool, and if no, determining a number of redundant electrons, and transferring the redundant electrons from the cache to the object pool;
[0066] In a specific implementation, a list_eleList can be set to store information of the moving electronic objects on the wire, if the length of the list_eleList is less than eleCount, the missing electronic objects are created from the object pool or re-created, if the length of the list_eleList is greater than eleCount, the redundant electronic objects are put into the object pool;
[0067] The electronic objects in the list_eleList are traversed, for each electronic object, its absolute distance and relative distance are determined, and the position of the moving electronic object on the wire is adjusted in real time according to the absolute distance and the relative distance;
[0068] The absolute distance and the relative distance are determined according to the following formulas:
[0069] The final position of the electronic object on the wire is determined according to the absolute distance;
[0070] The time length of the movement of the electronic object on the wire is determined according to the relative distance, which can be set as PassTime;
[0071] The initial position of the electronic object on the wire is determined according to the time length;
[0072] The position of the moving electronic object on the wire is adjusted in real time according to the initial position, the final position and the speed;
[0073] The absolute distance absolutePosition is the position of the current electronic object in the list_eleList multiplied by the interval between each electronic object;
[0074] The relative distance relativePosition is the absolute distance divided by the total path length, which is the total length of the wire;
[0075] The PassTime of the current electronic object is the relative distance multiplied by the total movement time, which is the total movement time of the wire;
[0076] In the embodiment, the absolute position of each electronic object on the wire path is represented by the absolute distance, which can be calculated by multiplying the index of the electronic object by the fixed interval between electronic objects (represented by EleSpace), so that the absolutePosition of the first electronic object is 0 (located at the starting point of the path), the absolutePosition of the second electronic object is EleSpace, and so on;
[0077] The relative position is a proportional value relative to the total length of the path, calculated by dividing the absolutePosition by the total length of the path (_totalDistance). This proportional value (between 0 and 1) is used to calculate where the electron should be on the path at the start of the animation.
[0078] PassTime represents the time it takes for the electron to reach its initial position from the start of the animation. By setting this value, we can ensure that each electron is in the correct position at the start of the animation and moves smoothly along the path over time.
[0079] In this embodiment, the calculation and use of absolutePosition and relativePosition are to evenly distribute the electrons on the path according to the length of the path and the speed of the electrons at the start of the animation, and to ensure that they maintain a fixed distance between them. This way, when the electrons move along the path, they will form a continuous and evenly distributed flow effect.
[0080] In another optional embodiment, as shown in Figure 4 the steps include:
[0081] Receiving a wire path update trigger request;
[0082] Before updating, it can be determined whether it is playing (Playing). If not, it is directly ended. If yes, the relevant steps of line point updating are executed;
[0083] According to the wire path update trigger request, determine the update path point, judge whether the update path point is the same as the original path point, if yes, execute the speed updating step;
[0084] If not, determine the update path length and update content according to the wire path update trigger request, judge whether the update path length and update content are the same as the original path length and original content, if yes, execute the speed updating step, wherein the update content refers to the specific information of each path point;
[0085] If not, judge whether the difference between the update path length and the original path length and the difference between the update content and the original content are both less than a preset value, if yes, execute the speed updating step;
[0086] If not, update the line points on the wire according to the wire path update trigger request, and calculate the total length and total moving time of the updated wire, i.e., update the line points, convert the updated line points into local coordinate points, calculate the new total distance and the new total moving time, if the old total distance is greater than 0, further execute the subsequent steps, otherwise, directly execute the speed update step;
[0087] Adjust the number and position of the moving electrons on the wire according to the total length and total moving time of the line, specifically, calculate the distance ratio according to the ratio between the new total distance and the old total distance, traverse the electron list according to the distance ratio, and adjust the PassTime of each electron as distance ratio * old PassTime;
[0088] The speed update step includes:
[0089] Receive a speed update trigger request;
[0090] Determine whether the speed update timing is reached, such as setting to update once every 10 frames, if yes, determine whether the updated speed is not zero according to the speed update trigger request, and the difference between the updated speed and the original speed is greater than a preset difference value, such as a preset difference value of 0.01, if yes, update the speed of each electron on the wire, and determine the time length of each electron moving through the wire according to the updated speed and the original speed;
[0091] When the speed is updated, calculate the speed ratio = old speed_MoveSpeed / new speed_delayInitMoveSpeed, and then determine the PassTime of the new electron as speed ratio * old PassTime according to the ratio of the new and old speeds.
[0092] In this embodiment, by adjusting the total moving time and the PassTime of each electron, it is ensured that the animation playback of the electron along the wire path can adapt to the dynamically changing conditions, such as the change of the path length and the change of the moving speed, which have a direct impact on the movement of the electron, so it is necessary to adjust accordingly to maintain the coherence and accuracy of the animation.
[0093] In another optional embodiment, when receiving the request for wire path update or speed update, the updated path information or speed information is first cached, i.e., the data points of the incoming updated path can be copied to the _delayInitPoints array, and the incoming updated speed value can be copied to the _delayInitMoveSpeed array, so as to delay the initialization in the subsequent update;
[0094] When receiving the wire path update trigger request or the speed update trigger request, the corresponding update operation is performed according to the latest stored path information or speed information in the cache;
[0095] In which, the Unity can be set to be automatically triggered at each frame.
[0096] In the embodiment, the delay initialization is used for optimizing performance. For example, if the user triggers the update request multiple times within a frame, the path update and the speed update are performed every time, which will cause great performance loss. In the embodiment, the path information and the speed information are cached in a variable, and the latest data is processed when the update time comes. The delay calculation and the object reuse mechanism are used to reduce the calculation amount and improve the simulation effect.
[0097] In another optional embodiment, as shown in Figure 5 The simulation of the movement of the electron on the wire according to the position of the electron on the wire includes:
[0098] Judging whether the number of points on the wire path is greater than 2, if yes, calculating the current position of each electron on the wire;
[0099] Controlling the movement of the electron on the wire according to the current position and the speed of the electron;
[0100] Calculating the time length PassTime of the movement of the electron on the wire in real time;
[0101] Judging whether the time length is greater than the total movement time length of the wire, if yes, resetting the position of the electron to its corresponding starting position and the time length of the movement of the electron on the wire, if not, updating the position of the electron by interpolation calculation.
[0102] In another optional embodiment, as shown in Figure 6 It further includes the steps of:
[0103] Receiving a resource recycling request;
[0104] Stopping the animation of the simulation of the movement of the electron according to the resource recycling request;
[0105] Emptying the path point data of the wire;
[0106] Destroying the electron in the cache and emptying the cache;
[0107] Resetting the total length of the wire and the total movement time of the wire.
[0108] The following will be described in combination with Figures 3-6 and a specific example to illustrate how to realize the simulation of the movement of the electron on the wire based on the Unity engine:
[0109] Create an EleMovePath class in Unity, which inherits MonoBehavior (where MonoBehavior is the base class of all scripts in Unity, providing a series of life cycle functions such as Start, Update, etc., and some special functions such as coroutines, which are user-level lightweight threads mainly used for asynchronous task scheduling and execution, allowing multiple tasks to be executed in a thread), and implement the following sequence:
[0110] 1. Property definition
[0111] (1) Define a class Electron to represent the information of an electron. This class has the following properties:
[0112] Go: used to manage the GameObject instance representing the electron's behavior, where GameObject is the basis of all entities in the scene in Unity, and various components such as scripts, renderers, and colliders can be attached to control their behavior and properties;
[0113] PassTime: the time length of the electron moving through the wire;
[0114] (2) EleSpace: a constant representing the distance between each electron;
[0115] (3) moveDir: a public integer representing the direction of electron movement, taking values of 1 or -1;
[0116] (4) Playing: a public boolean value indicating whether the electron movement animation is playing;
[0117] (5) _MoveSpeed: a private float representing the speed of electron movement.
[0118] (6) _delayInitMoveSpeed: a float used to delay changing the movement speed to optimize performance. In fact, when the user updates MoveSpeed, the data is first stored in _delayInitMoveSpeed, and when the Update method is executed, it is actually synchronized to _moveSpeed.
[0119]
[0120]
[0121] (7) _linePoints and _localLinePoints: private Vector3[] properties that store the global and local coordinates of all points on the wire path, respectively;
[0122] (8) _delayInitPoints: a private Vector3[] property used to delay changing the path points for performance optimization. In practice, when the user updates the path, the data is first stored here and then synchronized to _linePoints during the Update.
[0123] (9) _eleList: a private list of Electron type that stores information about all electron models.
[0124] (10) _totalDistance and _totalMoveTime: private properties that represent the total length of the current curve and the total time required for the electron to move along the entire curve, respectively.
[0125] 2. Initialization
[0126] (1) Define a CreateEleList method
[0127] Main function: This method generates electron objects based on the path length. It also ensures that if there are already electrons moving on the wire, the relative positions of the previous electrons will continue to be maintained, which is very important for user experience;
[0128] (2) Define a Play method
[0129] Parameters: The Play method accepts a Vector3[] type parameter linePoints, which contains the coordinates of all points on the wire path;
[0130] Main function: The main function of this method is to start the electron movement animation on the wire path. It copies the incoming path points to the _delayInitPoints array for delayed initialization in the subsequent Update method. At the same time, it sets the Playing property to true, indicating that the animation is playing;
[0131] (3) Define an Update method
[0132] Update is a fixed method of MonoBehaviour, which means Unity will automatically trigger it every frame;
[0133] The Update method first checks the Playing property to determine if the animation is playing, if it is, it will proceed to handle the updating of the wire path points and the updating of the movement speed, these two processing steps ensure that the electronic model can move correctly on the wire path according to the latest path points and speed, if the Playing property is false, indicating that the animation has stopped, then the Update method will not perform any operations.
[0134] 3. Play animation
[0135] Define a LateUpdate method, LateUpdate is a fixed method of MonoBehavior, which means that Unity will automatically trigger it at the last time point of each frame.
[0136] The LateUpdate method is called at the end of each frame to update the position of the electronic model. It first ensures that there are enough electronic models to cover the entire wire path, then calculates the current position of each electronic based on its PassTime and total move time, and updates its position:
[0137] First, check if the number of path points is greater than 2 to ensure the validity of the path.
[0138] If the condition is met, loop through the electronic model list, for each electronic model: calculate the current position of the electronic based on its PassTime and total move time;
[0139] If the PassTime of the electronic exceeds the total move time, it means that the electronic has reached the end of the path, at this time you need to reset the position of the electronic to the starting point and reset the PassTime to 0;
[0140] If the PassTime does not exceed the total move time, calculate the specific position of the electronic on the wire path according to its relative position (interpolation t) using the Interpolate method, and update the position of the electronic model, for interpolation operation:
[0141] Assuming the path is a straight line from (0,0) to (100,0), and the speed is 1, so:
[0142] _totalDistance = 100; MoveSpeed = 1; _totalMoveTime = 100 / 1 = 100;
[0143] Assuming passTime = 20, at this time passTime / _totalMoveTime = 0.2, which means moving 20% of the distance from the starting position, so the resulting coordinates are (20,0);
[0144] Assuming passTime = 50, which means passTime / _totalMoveTime = 0.5, which means the electron has moved 50% of the total distance from the start position, so the resulting coordinates are (50, 0);
[0145] The loop continues until all electronic models are processed;
[0146] 4. Resource recycling
[0147] (1) Define a Stop method
[0148] Main function: The main function of this method is to stop the movement animation of the electron on the wire path. It calls the ClearResources method to clean up all related resources, including hiding or destroying all electron models, and setting the Playing property to false.
[0149] (2) Define the OnDestroy method
[0150] Main function: The OnDestroy method is a Unity lifecycle method that is called when the EleMovePath component is destroyed. Its main job is also to call the ClearResources method to clean up all related resources.
[0151] (3) Define the ClearResources method
[0152] Main function: The ClearResources method is responsible for specific resource cleanup work. It will stop the animation, destroy all electron models, clear the electron model list, and reset the path point data and related calculation values.
[0153] The following illustrates the above process by constructing a set of test data:
[0154] 1. Wire path and electron movement configuration
[0155] Suppose there is a wire whose path points are [(0, 0, 0), (2, 0, 0), (2, 2, 0)], which means the wire starts from the origin, extends 2 units in the positive x direction, and then extends 2 units in the positive y direction.
[0156] Electron movement speed: set to 0.5 units per second.
[0157] Moving direction: set to 1 (positive direction, i.e. moving from the first point to the last point of the path).
[0158] 2. User calls the Play method
[0159] Operation: The user called the Play method, passing in the path points of the above wire.
[0160] What happened: The Play method copied the path points into _delayInitPoints, preparing for initialization on the next Update method call.
[0161] The Playing state was set to true, indicating that the animation started playing.
[0162] 3. Update method is automatically triggered
[0163] Operation: In the next frame, the Update method is automatically triggered by Unity.
[0164] What happened: The Update method detected new path points in _delayInitPoints, so it updated _linePoints and _localLinePoints, and calculated the total length of the new path and the total movement time.
[0165] Based on the new path length and the spacing between electrons (EleSpace), the Update method decided how many new electron models needed to be created: if the existing number of electron models was not enough to cover the entire path, it created more and added them to _eleList. These electron models were initialized and placed at the starting position of the path.
[0166] For existing electron models, if the path length changed, the Update method adjusted their PassTime to ensure they were correctly distributed on the new path.
[0167] If necessary, adjust the PassTime of the electrons according to the new movement speed.
[0168] 4. LateUpdate method is automatically triggered
[0169] Operation: In the same frame at a later time, the LateUpdate method is automatically triggered by Unity.
[0170] What happened: The LateUpdate method calculated and updated the position of each electron based on its PassTime and the total movement time, making the electrons move along the wire path.
[0171] If an electron reaches the end of the path, its position is reset to the starting point, and the PassTime is also reset accordingly to achieve the effect of circular movement.
[0172] 5. User calls the Stop method
[0173] Operation: At a certain moment, the user decides to stop the animation and calls the Stop method.
[0174] What happens: The Stop method calls ClearResources, stops the animation from playing, destroys all the electron models, empties the list of electron models, resets the path point data, and sets the Playing state to false.
[0175] All resources related to the electronic animation are properly cleaned up and recycled, ensuring that there is no memory leak.
[0176] In another optional embodiment, as shown in Figure 2 A device for simulating the movement of an electron, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the method for simulating the movement of an electron according to any one of the above embodiments.
[0177] In another optional embodiment, a computer-readable storage medium having stored thereon computer program instructions, wherein the computer program instructions are executed by a processor to implement the steps of the method for simulating the movement of an electron according to any one of the above embodiments.
[0178] In summary, the method, device, and computer-readable storage medium for simulating the movement of an electron provided by the present application do not rely on a particle system, can dynamically simulate the movement of an electron along any given path, and allow real-time adjustment of the path and the movement speed of the electron, including three main parts: path processing, speed adjustment, and electron model generation. The visualization of the movement of the electron in three-dimensional space is achieved through software algorithms, the movement path of the electron in the wire is simulated using the 3D rendering capability of the Unity engine, the dynamic control of the movement of the electron is achieved through the custom EleMovePath class, and an optimization algorithm is used to reduce the amount of calculation and improve the simulation efficiency, enabling efficient and flexible simulation of the movement of the electron on the wire.
[0179] The above description is only an embodiment of the present application and does not limit the patent scope of the present application. Any equivalent transformation or direct or indirect application in related technical fields based on the content of the specification and drawings is also included in the patent protection scope of the present application.
Claims
1. A method of simulating electronic movement, characterized by, The method comprises the steps of: acquiring the length of a wire to be simulated, and determining the number of electrons required according to the length of the wire; determining the position of each electron on the wire according to the length of the wire, the number of electrons and a preset electron spacing, and simulating the movement of the electrons on the wire according to the position of each electron on the wire; adjusting the number and position of the moving electrons on the wire in real time according to the change of the length of the wire; The method further comprises the steps of: receiving a wire path update trigger request; determining an updated path point according to the wire path update trigger request, and judging whether the updated path point is the same as an original path point, if yes, performing a speed updating step; if no, determining an updated path length and updated content according to the wire path update trigger request, and judging whether the updated path length and updated content are the same as an original path length and original content, if yes, performing the speed updating step; if no, judging whether the difference between the updated path length and the original path length and the difference between the updated content and the original content are both less than a preset value, if yes, performing the speed updating step; if no, updating the path points on the wire according to the wire path update trigger request, and calculating the total length and total moving time of the updated wire; adjusting the number and position of the moving electrons on the wire according to the total length and total moving time; The speed updating step comprises: receiving a speed update trigger request; judging whether a speed updating occasion is reached, if yes, determining whether the updated speed is not zero and the difference between the updated speed and the original speed is greater than a preset difference value according to the speed update trigger request, if yes, updating the speed of each electron on the wire, and determining the time length of the movement of each electron on the wire according to the updated speed and the original speed.
2. The method of simulating electronic movement of claim 1, wherein, The step of adjusting the number and position of the moving electrons on the wire in real time according to the change of the length of the wire comprises: determining the number of electrons required according to the change of the length of the wire as a target number of electrons; judging whether the number of existing electrons in a cache is less than the target number of electrons, if yes, acquiring or re-creating the missing electrons from an object pool, if no, determining the number of redundant electrons, and transferring the redundant electrons from the cache to the object pool; traversing the electronic objects in the cache, for each electron, determining its absolute distance and relative distance, and adjusting the position of the moving electron on the wire in real time according to the absolute distance and relative distance.
3. A method of simulating electronic movement according to claim 2, wherein, The step of adjusting the position of the moving electron on the wire in real time according to the absolute distance and relative distance comprises: determining the final position of the electron on the wire according to the absolute distance; determining the time length of the movement of the electron on the wire according to the relative distance; determining the initial position of the electron on the wire according to the time length; adjusting the position of the moving electron on the wire in real time according to the initial position, final position and speed.
4. The method of simulating electronic movement of claim 1, wherein, When receiving a request for wire path update or speed update, the updated path information or speed information is cached first; The updating operation is performed according to the latest stored path information or speed information in the cache when the wire path updating trigger request or the speed updating trigger request is received.
5. A method of simulating electronic movement according to any one of claims 1 to 3, wherein, The movement of the electron on the wire is simulated according to the position of the electron on the wire, and the movement of the electron on the wire comprises: determining whether the number of points on the wire path is greater than 2, if yes, calculating the current position of each electron on the wire; controlling the movement of the electron on the wire according to the current position and the speed of the electron; calculating the time length of the movement of the electron on the wire in real time; determining whether the time length is greater than the total movement time of the wire, if yes, resetting the position of the electron to its corresponding starting position and the time length of the movement of the electron on the wire, if not, updating the position of the electron by interpolation calculation.
6. A method of simulating electronic movement according to any one of claims 1 to 3, wherein, Further comprising steps of: receiving a resource recycling request; stopping the animation of simulating the movement of the electron according to the resource recycling request; emptying the path point data of the wire; destroying the electron in the cache and emptying the cache; resetting the total length of the wire and the total movement time of the wire.
7. An apparatus for simulating electronic movement, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the computer program comprises instructions for: The processor executes the computer program to realize the steps of the method for simulating the movement of the electron according to any one of claims 1 to 6.
8. A computer-readable storage medium having stored thereon computer program instructions, wherein, The computer program instructions are executed by the processor to realize the steps of the method for simulating the movement of the electron according to any one of claims 1 to 6.
Citation Information
Patent Citations
Visualization method, device and equipment of steady flow field vector data and medium
CN115859755A
Motion control method and device of virtual object and electronic equipment
CN116758191A