Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the collision of elastic objects in C# simulation test

Shulou Source: shulou.com Published: 2022-06-02 11:43:28 10月03日 Update

This article will explain in detail how to achieve elastic object collision in the C# simulation test. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

When bored, I wrote an elastic object collision simulation with C #. This idea originated from the computer class a few days ago when someone wanted me to do a perspective projection program in the computer room, so I immediately wrote a projection and made a wireframe ball to jump. As a result, I thought, what if the object is elastic? Go back to the dorm and put your ideas into practice.

This program is 2D, using C # mainly because GDI+ is easier to write, at least easier to use than poor MFC, although C # things are slow and take up CPU usage. I swear that the Timer of .NET is not made with WM_TIMER messages, idling occupies such a high CPU, and it can't be reduced with Sleep. Excessive CPU occupancy for too long will lead to an increase in CPU temperature.

There's still something wrong with the program. For example, the classic problem of physics engine: floating point error and collision penetration. It hasn't been dealt with 100% yet, although in most cases it's fine. The second is because elasticity is beyond the scope of my physical knowledge, so the speed of collision is higher, temporarily scribbling, wait a few days to solve a system of ternary quadratic equations, and then change the code.

Put three screenshots first, and then get the code out after the program has been changed. This thing is fun. Hey, hey. Taking gravity into account.

C # simulation (1): two elastic 7 polygons are created

C # Simulation (2): the object on the left hits the wall

C # Simulation (3): the object on the right hits the ground

I used to make the elasticity very small and the number of sides very large, and as a result, there was something like a water-filled balloon.

About how to achieve elastic object collision in the C# simulation test is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Examples elasticity collisions objects programs things knowledge experiments code content objects ideas articles more physics articles results problems projections good Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Information vpn Redmi NVidia