Method and device for simulating electronic movement and computer readable storage medium
By adjusting the number and position of electrons in real time, combining cache and object pool management, the problem of low electronic mobility performance on wires of traditional simulation methods is solved, and efficient and flexible electronic dynamic control is achieved, which is suitable for various electronic physics teaching and scientific research scenarios.
Patent Information
- Application Number
- CN202410898710.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-05
- Publication Date
- 2024-11-15
- Estimated Expiration
- 2044-07-05
AI Technical Summary
Traditional methods of moving electronics on wires cannot achieve efficient and flexible dynamic control, especially on mobile devices with low performance and low flexibility.
By obtaining the wire length, determining the number and position of electrons, adjusting the number and position of electrons on the wire in real time, optimizing the management of electronic objects with cache and object pool, realizing dynamic path and speed updates, and using interpolation calculations and delay initialization to improve performance.
Dynamic control of electron movement is realized, and the electron movement along any path can be efficiently and flexibly simulated, adapting to path length and speed changes, reducing the calculation amount and improving simulation efficiency.
Smart Images

Figure CN118965935A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to computer graphics and simulation technology, and more particularly to a method and device for simulating electron movement and a computer-readable storage medium. Background Art
[0002] In the teaching of electronic engineering and physics, simulating the path of electrons moving in wires is crucial to understanding the working principles of circuits. Traditional simulation methods have limitations, such as the inability to intuitively display the dynamic behavior of electrons.
[0003] In order to simulate the movement of electrons, a common method is to use a particle system. However, the particle system is a component that consumes a lot of CPU, especially on mobile devices, where the performance is very low. Once the particle system is played, the particles can only move according to the original settings, which is not very flexible. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a method, a device and a computer-readable storage medium for simulating the movement of electrons, which can efficiently and flexibly simulate the movement of electrons on a wire.
[0005] In order to solve the above technical problems, a technical solution adopted by the present invention is:
[0006] A method for simulating electron movement, comprising the steps of:
[0007] Obtaining the length of the wire to be simulated, and determining the required number of electrons according to the length of the wire;
[0008] Determine 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 simulate the movement of electrons on the wire according to the position of each electron on the wire;
[0009] The number and position of electrons moving on the wire are adjusted in real time according to the change in the length of the wire.
[0010] Furthermore, the real-time adjustment of the number and position of electrons moving on the wire according to the change in the length of the wire includes:
[0011] Determining the required number of electrons according to the change in the length of the wire as the target number of electrons;
[0012] Determine whether the number of electrons already in the cache is less than the target number of electrons, if so, obtain or recreate the missing electrons from the object pool, if not, determine the number of excess electrons, and transfer the excess number of electrons from the cache to the object pool;
[0013] The electron objects in the cache are traversed, and for each electron, its absolute distance and relative distance are determined, and the position of the electron moving on the wire is adjusted in real time according to the absolute distance and the relative distance.
[0014] Further, the real-time adjustment of the position of the electrons moving on the wire according to the absolute distance and the relative distance includes:
[0015] determining the final position of the electron on the wire based on the absolute distance;
[0016] Determining the time it takes for the electron to move on the wire according to the relative distance;
[0017] Determining the initial position of the electron on the wire according to the duration;
[0018] The position of the electrons moving on the wire is adjusted in real time according to the initial position, final position and speed.
[0019] Furthermore, the method further comprises the steps of:
[0020] receiving a wire path update trigger request;
[0021] Determine an updated path point according to the wire path update trigger request, determine whether the updated path point is the same as the original path point, and if so, execute a speed update step;
[0022] If not, determining the 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 so, executing the speed update step;
[0023] If not, determining 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 so, executing the speed updating step;
[0024] If not, updating the route points on the conductor according to the conductor path update trigger request, and calculating the total route length and total moving time of the updated conductor;
[0025] The number and position of electrons moving on the wire are adjusted according to the total length of the line and the total movement time.
[0026] Furthermore, the speed updating step includes:
[0027] receiving a speed update trigger request;
[0028] Determine whether the speed update timing has been reached; if so, determine whether the updated speed is not zero according to the speed update trigger request, and whether the difference between the updated speed and the original speed is greater than a preset difference; if so, update the speed of each electron on the wire, and determine the time each electron takes to move on the wire according to the updated speed and the original speed.
[0029] Further, when a request for wire path update or speed update is received, the updated path information or speed information is first cached;
[0030] When a wire path update trigger request or a speed update trigger request is received, a corresponding update operation is performed according to the path information or speed information most recently stored in the cache.
[0031] Further, simulating the movement of electrons on the wire according to the positions of the electrons on the wire includes:
[0032] Determine whether the number of points on the wire path is greater than 2, and if so, calculate the current position of each electron on the wire;
[0033] Controlling the electron to move on the wire according to the current position and the speed of the electron;
[0034] Calculating in real time the time it takes for the electron to move on the wire;
[0035] Determine whether the duration is greater than the total movement duration of the wire. If so, reset the position of the electron to its corresponding starting position and the duration of its movement on the wire. If not, update the position of the electron by interpolation calculation.
[0036] Furthermore, the method further comprises the steps of:
[0037] Receive resource recovery requests;
[0038] stopping the animation simulating the movement of the electron in response to the resource recovery request;
[0039] Clearing the path point data of the wire;
[0040] destroying electrons in a cache and emptying said cache;
[0041] The total line length and total movement time of the wire are reset.
[0042] In order to solve the above technical problems, another technical solution adopted by the present invention is:
[0043] A device for simulating electron movement includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the above-mentioned method for simulating electron movement are implemented.
[0044] In order to solve the above technical problems, another technical solution adopted by the present invention is:
[0045] A computer-readable storage medium stores computer program instructions, which implement the steps of the above-mentioned method for simulating electron movement when executed by a processor.
[0046] The beneficial effects of the present invention are as follows: the required number of electrons is determined by acquiring the length of the wire to be simulated, the position of each electron on the wire is determined according to the length of the wire, the number of electrons and the preset electron spacing, the movement of electrons on the wire is simulated according to the position of each electron on the wire, and the number and position of electrons moving on the wire are adjusted in real time according to the change in the length of the wire. The movement of electrons along any given wire path can be dynamically simulated, dynamic control of the movement of electrons is achieved, and efficient and flexible simulation of the movement of electrons on the wire is achieved. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] Figure 1 A flowchart of a method for simulating electron movement according to an embodiment of the present invention;
[0048] Figure 2 Schematic diagram of the structure of a device for simulating electron movement according to an embodiment of the present invention;
[0049] Figure 3 A flowchart of the steps of creating a corresponding number of electrons according to a path length according to an embodiment of the present invention;
[0050] Figure 4 A flowchart of the steps of implementing path updating and speed updating according to an embodiment of the present invention;
[0051] Figure 5 A flowchart of the steps for implementing animation playback according to an embodiment of the present invention;
[0052] Figure 6 The figure is a flow chart of resource recycling steps according to an embodiment of the present invention. DETAILED DESCRIPTION
[0053] In order to explain the technical content, achieved objectives and effects of the present invention in detail, the following is an explanation in combination with the implementation modes and the accompanying drawings.
[0054] The method, device and computer-readable storage medium for simulating electron movement described above in the present application can be applied to various scenarios where the movement of electrons needs to be simulated, such as electronic physics teaching, physics research, etc., and are described below through specific implementation methods:
[0055] In an optional embodiment, if Figure 1 As shown, a method for simulating electron movement comprises the steps of:
[0056] S1. Obtain the length of the wire to be simulated, and determine the required number of electrons according to the length of the wire;
[0057] Wherein, determining the required number of electrons according to the length of the wire comprises:
[0058] Get the spacing between electrons;
[0059] determining the required number of electrons based on the length of the wire and the spacing;
[0060] S2, 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;
[0061] S3, adjusting the number and position of electrons moving on the wire in real time according to the change in the length of the wire;
[0062] In this embodiment, the 3D rendering capability of the Unity engine is used to simulate the movement path of electrons in the wire.
[0063] In another optional embodiment, Figure 3 As shown, the real-time adjustment of the number and position of electrons moving on the wire according to the change in the length of the wire includes:
[0064] Determine the required number of electrons eleCount according to the change in the length of the wire = take the integer (path length / spacing between each electron) as the target number of electrons;
[0065] Determine whether the number of electrons already in the cache is less than the target number of electrons, if so, obtain or recreate the missing electrons from the object pool, if not, determine the number of excess electrons, and transfer the excess number of electrons from the cache to the object pool;
[0066] In specific implementation, a list _eleList can be set to store the information of the electronic objects moving on the wire. If the length of _eleList is less than eleCount, the missing electronic objects are created from the object pool or recreated. If the length of _eleList is greater than eleCount, the redundant electronic objects are placed in the object pool.
[0067] Traverse the electron objects in the cache list _eleList, determine the absolute distance and relative distance of each electron, and adjust the position of the electron moving on the wire in real time according to the absolute distance and relative distance;
[0068] Wherein, adjusting the position of the electrons moving on the wire in real time according to the absolute distance and the relative distance comprises:
[0069] determining the final position of the electron on the wire based on the absolute distance;
[0070] Determine the time it takes for the electron to move on the wire according to the relative distance, which can be set as PassTime;
[0071] Determining the initial position of the electron on the wire according to the duration;
[0072] adjusting the position of the electrons moving on the wire in real time according to the initial position, final position and speed;
[0073] Among them, absolute distance absolutePosition = the position of the current electron in the list _eleList * the distance between each electron;
[0074] Relative distance relativePosition = absolutePosition / total path length, the total path length is the total length of the wire;
[0075] The current electron's PassTime = relative distance * total moving time, where the total moving time is the total moving time of the wire;
[0076] In this embodiment, the absolute position of each electron on the wire path is represented by an absolute distance, which can be calculated by multiplying the index of the electron by the fixed spacing between electrons (represented by EleSpace), so that the absolutePosition of the first electron is 0 (located at the starting point of the path), the absolutePosition of the second electron is EleSpace, and so on;
[0077] The relative position converts the absolutePosition into a proportional value relative to the length of the entire path. It is 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 when the animation starts.
[0078] PassTime represents the time required from the start of the animation until the electron reaches its initial position. By setting this value, you can ensure that each electron is in the correct position at the beginning of the animation and moves smoothly along the path over time.
[0079] In this implementation, the calculation and use of absolutePosition and relativePosition is to evenly distribute the electrons on the path according to the length of the path and the speed of the electrons at the beginning of the animation, and to ensure that a fixed spacing is maintained between them, so that when the electrons move along the path, they will form a continuous and evenly distributed flow effect.
[0080] In another optional embodiment, Figure 4 As shown, the steps include:
[0081] receiving a wire path update trigger request;
[0082] Before updating, it can be determined whether the video is playing (Playing). If not, it is terminated directly. If yes, relevant steps of updating the route point are executed.
[0083] Determine an updated path point according to the wire path update trigger request, determine whether the updated path point is the same as the original path point, and if so, execute a speed update step;
[0084] If not, determining the 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 so, executing the speed update step, wherein the updated content refers to the specific information of each path point;
[0085] If not, determining 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 so, executing the speed updating step;
[0086] If not, then update the line points on the wire according to the wire path update trigger request, and calculate the total line length and total moving time of the updated wire, that is, 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] The number and position of the electrons moving on the wire are adjusted according to the total length of the line and the total moving time. Specifically, the distance ratio is calculated according to the ratio between the new total distance and the old total distance, and the electron list is traversed according to the distance ratio, and the PassTime of each electron is adjusted to be equal to the distance ratio*the old PassTime;
[0088] Wherein, the speed updating step comprises:
[0089] receiving a speed update trigger request;
[0090] Determine whether the speed update timing has been reached, for example, the update can be set to be once every 10 frames. If so, determine whether the updated speed is not zero according to the speed update trigger request, and whether the difference between the updated speed and the original speed is greater than a preset difference, such as the preset difference is 0.01. If so, update the speed of each electron on the wire, and determine the time each electron has spent moving on the wire according to the updated speed and the original speed;
[0091] When the speed is updated, the speed ratio is calculated as old speed_MoveSpeed / new speed_delayInitMoveSpeed, and then the PassTime of the new electron is determined as speed ratio*old PassTime according to the ratio of the old and new speeds.
[0092] In this embodiment, by adjusting the total movement time and the PassTime of each electron, it is ensured that the animation playback of the electron along the wire path can adapt to dynamically changing conditions, such as changes in path length and changes in movement speed. These two factors have a direct impact on the movement of electrons, and therefore need to be adjusted accordingly to maintain the continuity and accuracy of the animation.
[0093] In another optional implementation, when a wire path update or speed update request is received, the updated path information or speed information is first cached, that is, 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 perform delayed initialization in subsequent updates;
[0094] When a wire path update trigger request or a speed update trigger request is received, a corresponding update operation is performed according to the path information or speed information most recently stored in the cache;
[0095] Among them, you can set Unity to automatically trigger it in each frame.
[0096] In this implementation, delayed initialization is used to optimize performance. For example, if a user triggers an update request multiple times within a frame, performing path and speed updates each time will result in significant performance loss. In this implementation, the path information and speed information are first cached into a variable, and the latest data is processed when the update time arrives. By adopting delayed calculation and object reuse mechanisms, the amount of calculation is reduced and the simulation effect is improved.
[0097] In another optional embodiment, Figure 5 As shown, the simulating movement of electrons on the wire according to the positions of the electrons on the wire comprises:
[0098] Determine whether the number of points on the wire path is greater than 2, and if so, calculate the current position of each electron on the wire;
[0099] Controlling the electron to move on the wire according to the current position and the speed of the electron;
[0100] Calculate in real time the time PassTime that the electron spends moving on the wire;
[0101] Determine whether the duration is greater than the total movement duration of the wire. If so, reset the position of the electron to its corresponding starting position and the duration of its movement on the wire. If not, update the position of the electron by interpolation calculation.
[0102] In another optional embodiment, Figure 6 As shown, the steps include:
[0103] Receive resource recovery requests;
[0104] stopping the animation simulating the movement of the electron in response to the resource recovery request;
[0105] Clearing the path point data of the wire;
[0106] destroying electrons in a cache and emptying said cache;
[0107] The total line length and total movement time of the wire are reset.
[0108] The following combination Figure 3-Figure 6 And a specific example is used to illustrate how to simulate the movement of electrons on a wire based on the Unity engine:
[0109] Create an EleMovePath class in Unity. This class inherits MonoBehaviour (in Unity, MonoBehaviour is the base class of all scripts. It provides a series of life cycle functions (such as Start, Update, etc.) and some special functions (such as coroutines. Coroutines are lightweight threads in user mode, mainly used for scheduling and executing asynchronous tasks. It can switch between multiple tasks in one thread) and implement them in the following order:
[0110] 1. Attribute definition
[0111] (1) Define a class Electron to represent the information of an electron. This class has the following properties:
[0112] Go: GameObject instances used to manage electronic performance. In Unity, GameObject is the basis of all entities in the scene, and various components (such as scripts, renderers, colliders, etc.) can be attached to control its behavior and properties.
[0113] PassTime: the time it takes for the electron to move along the wire;
[0114] (2)EleSpace: a constant representing the distance between each electron;
[0115] (3) moveDir: a public integer indicating the direction of electron movement, with a value of 1 or -1;
[0116] (4) Playing: a public Boolean value indicating whether the electronic movement animation is playing;
[0117] (5)_MoveSpeed: A private floating point number that indicates the moving speed of the electron.
[0118] (6)_delayInitMoveSpeed: A floating point number used to delay the change of the moving speed to optimize performance. In fact, when the user updates MoveSpeed, the data will be stored in
[0119] _delayInitMoveSpeed, the real synchronization will be achieved only when the Update method is executed.
[0120] _moveSpeed;
[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: Private Vector3[] property, used to delay the change of path points to optimize performance. In fact, when the user updates the path, the data will be stored here first and will be synchronized to _linePoints when Update is performed.
[0123] (9)_eleList: A private Electron type list that stores information about all electron models.
[0124] (10)_totalDistance and _totalMoveTime: private properties, representing 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 according to the path length. At the same time, this method ensures that if there are electrons moving on the wire, the relative position 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 parameter linePoints of type Vector3[], which contains the coordinates of all points on the wire path;
[0130] Main function: The main function of this method is to start the moving animation of the electron 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 in every frame;
[0133] The Update method first checks the Playing property to determine if the animation is playing. If so, it will continue to process the update of the wire path points and the update 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, the Update method will not perform any operation.
[0134] 3. Animated playback
[0135] Define a LateUpdate method. LateUpdate is a fixed method of MonoBehaviour, which means that Unity automatically triggers 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 electron model. It first ensures that there are enough electron models to cover the entire wire path, then calculates the current position of each electron based on its PassTime and total movement 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 list of electron models, and for each electron model: calculate the current position of the electron based on the PassTime of the electron and the total movement time;
[0139] If the PassTime of the electron exceeds the total moving time, it means that the electron has reached the end of the path. At this time, the position of the electron needs to be reset to the starting point and the PassTime needs to be reset to 0;
[0140] If PassTime does not exceed the total moving time, the Interpolate method is used to calculate the specific position of the electron on the wire path according to the relative position of the electron (interpolation t), and the position of the electron model is updated. For the interpolation operation:
[0141] Assume 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] Assume that passTime = 20, then passTime / _totalMoveTime = 0.2, which means that the distance moved from the starting position is 20%, so the obtained coordinate is (20,0);
[0144] Assume that passTime = 50, then passTime / _totalMoveTime = 0.5, which means that the distance moved from the starting position is 50%, so the obtained coordinate is (50,0);
[0145] The loop continues until all electronic models have been processed;
[0146] 4. Resource recovery
[0147] (1) Define a Stop method
[0148] Main function: The main function of this method is to stop the animation of electrons moving on the wire path. It cleans up all related resources by calling the ClearResources method, 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 lifecycle method of Unity. It 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 functions: The ClearResources method is responsible for specific resource cleanup. It will stop animation playback, destroy all electronic models, clear the electronic model list, and reset path point data and related calculation values.
[0153] The following illustrates the above process by constructing a set of test data:
[0154] 1. Wire paths 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 that the wire starts from the origin, extends 2 units in the positive direction of the x-axis, and then extends 2 units in the positive direction of the y-axis.
[0156] Electron movement speed: set to 0.5 units / second.
[0157] Moving direction: Set to 1 (forward, i.e. moving from the first point of the path to the last point).
[0158] 2. The user calls the Play method
[0159] Operation: The user calls the Play method and passes in the path point of the above wire.
[0160] What happens: The Play method copies the path points to _delayInitPoints, ready for initialization the next time the Update method is called;
[0161] The Playing state is set to true, indicating that the animation starts playing.
[0162] 3.Update method is automatically triggered
[0163] Action: In the next frame, the Update method is automatically triggered by Unity.
[0164] What happens: The Update method detects that there are new path points in _delayInitPoints, so it updates _linePoints and _localLinePoints and calculates the total length and total travel time of the new path;
[0165] Based on the new path length and the spacing between electrons (EleSpace), the Update method determines how many additional electron models need to be created: if the existing number of electron models is not enough to cover the entire path, it creates more electron models and adds them to _eleList. These electron models are initialized and placed at the beginning of the path.
[0166] For existing electron models, if the path length changes, the Update method will adjust their PassTime to ensure that they are correctly distributed on the new path.
[0167] If necessary, adjust the electron's PassTime according to the new movement speed.
[0168] 4. LateUpdate method is automatically triggered
[0169] Action: At a later time in the same frame, the LateUpdate method is automatically triggered by Unity.
[0170] What happens: The LateUpdate method calculates and updates the position of the electrons based on the PassTime of each electron and the total movement time, so that the electrons move along the wire path.
[0171] If the electron reaches the end of the path, its position is reset to the starting point and PassTime is reset accordingly to achieve the effect of circular movement.
[0172] 5. The user calls the Stop method
[0173] Action: At some point, the user decides to stop the animation and calls the Stop method.
[0174] What happens: The Stop method calls ClearResources, stops the animation, destroys all the models, clears the model list, resets the waypoint data, and sets the Playing state to false.
[0175] All animatronics-related resources are properly cleaned up and recycled, ensuring there are no memory leaks.
[0176] In another optional embodiment, Figure 2 As shown, a device for simulating electron movement includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of a method for simulating electron movement described in any one of the above embodiments are implemented.
[0177] In another optional embodiment, a computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed by a processor, the steps of a method for simulating electron movement described in any of the above embodiments are implemented.
[0178] In summary, the present invention provides a method, device and computer-readable storage medium for simulating the movement of electrons, which are independent of the particle system, can dynamically simulate the movement of electrons along any given path, and allow real-time adjustment of the path and the movement speed of the electrons. The method includes three main parts: path processing, speed adjustment and electron model generation. The software algorithm realizes the visualized movement of electrons in three-dimensional space, and utilizes the 3D rendering capability of the Unity engine to simulate the movement path of electrons in the wire. The custom EleMovePath class is used to realize dynamic control of the movement of electrons. The optimization algorithm is used to reduce the amount of calculation and improve the simulation efficiency, so that the movement of electrons on the wire can be simulated efficiently and flexibly.
[0179] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent transformations made using the contents of the present invention's specification and drawings, or directly or indirectly applied in related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A method for simulating electron movement, characterized in that: Includes steps: Obtaining the length of the wire to be simulated, and determining the required number of electrons according to the length of the wire; Determine 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 simulate the movement of electrons on the wire according to the position of each electron on the wire; The number and position of electrons moving on the wire are adjusted in real time according to the change in the length of the wire.
2. A method for simulating electron movement according to claim 1, characterized in that: The real-time adjustment of the number and position of electrons moving on the wire according to the change in the length of the wire comprises: Determining the required number of electrons according to the change in the length of the wire as the target number of electrons; Determine whether the number of electrons already in the cache is less than the target number of electrons, if so, obtain or recreate the missing electrons from the object pool, if not, determine the number of excess electrons, and transfer the excess number of electrons from the cache to the object pool; The electron objects in the cache are traversed, and for each electron, its absolute distance and relative distance are determined, and the position of the electron moving on the wire is adjusted in real time according to the absolute distance and the relative distance.
3. A method for simulating electron movement according to claim 2, characterized in that: The real-time adjustment of the position of the electrons moving on the wire according to the absolute distance and the relative distance comprises: determining the final position of the electron on the wire based on the absolute distance; Determining the time it takes for the electron to move on the wire according to the relative distance; Determining the initial position of the electron on the wire according to the duration; The position of the electrons moving on the wire is adjusted in real time according to the initial position, final position and speed.
4. A method for simulating electron movement according to any one of claims 1 to 3, characterized in that: Also includes the steps: receiving a wire path update trigger request; Determine an updated path point according to the wire path update trigger request, determine whether the updated path point is the same as the original path point, and if so, execute a speed update step; If not, determining the 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 so, executing the speed update step; If not, determining 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 so, executing the speed updating step; If not, updating the route points on the conductor according to the conductor path update trigger request, and calculating the total route length and total moving time of the updated conductor; The number and position of electrons moving on the wire are adjusted according to the total length of the line and the total movement time.
5. A method for simulating electron movement according to claim 4, characterized in that: The speed updating step comprises: receiving a speed update trigger request; Determine whether the speed update timing has been reached; if so, determine whether the updated speed is not zero according to the speed update trigger request, and whether the difference between the updated speed and the original speed is greater than a preset difference; if so, update the speed of each electron on the wire, and determine the time each electron takes to move on the wire according to the updated speed and the original speed.
6. A method for simulating electron movement according to claim 4, characterized in that: When a request for a wire path update or a speed update is received, the updated path information or speed information is first cached; When a wire path update trigger request or a speed update trigger request is received, a corresponding update operation is performed according to the path information or speed information most recently stored in the cache.
7. A method for simulating electron movement according to any one of claims 1 to 3, characterized in that: The step of simulating the movement of electrons on the wire according to the positions of the electrons on the wire comprises: Determine whether the number of points on the wire path is greater than 2, and if so, calculate the current position of each electron on the wire; Controlling the electron to move on the wire according to the current position and the speed of the electron; Calculating in real time the time it takes for the electron to move on the wire; Determine whether the duration is greater than the total movement duration of the wire. If so, reset the position of the electron to its corresponding starting position and the duration of its movement on the wire. If not, update the position of the electron by interpolation calculation.
8. A method for simulating electron movement according to any one of claims 1 to 3, characterized in that: Also includes the steps: Receive resource recovery requests; stopping the animation simulating the movement of the electron in response to the resource recovery request; Clearing the path point data of the wire; destroying electrons in a cache and emptying said cache; The total line length and total movement time of the wire are reset.
9. A device for simulating electron movement, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method for simulating electron movement according to any one of claims 1 to 8 are implemented.
10. A computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the computer program instructions are executed by a processor, the steps of a method for simulating electron movement according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Mobile terminal simulation particle system method
CN106056660A
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
Traffic simulation method for creating an optimized object motion path in the simulator
US20230169228A1
