Making my own physics engine (need help sorta)

Discussion in 'Physics & Math' started by gamelord, Jun 24, 2018.

  1. TheFrogger Registered Senior Member

    Messages:
    752
    You'd have to program the physics of gravity and velocity i.e. life on Earth etc. into the computer and then run the program. ☺
     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. gamelord Registered Senior Member

    Messages:
    661
    Ok I did this. The rotations produced by the cross product seemed off, so I just ran a bunch of Physics based box2d sims of a cube, and saved the data of each test run.

    The numbers output by the cross product do not seem to match the graph output by the box2d cube.
    I also rendered them on top each other and they still do not match.
    What I mean by this is I overlayed the cross-product physics on top of a realistic physics engine and it does not match the ratios. For example, I got the ratio of rotations, when the custom box hit at a certain angle, 30 degrees, and cross referenced it to the realistic physics of a box hitting at 30 degrees. The ratio was 2.38. So I multiplied this to it and then changed the angle, but the ratio did not stay the same. Each new angle produced a new ratio and the cross product graph did not match the graph of the realistic physics.
    Here is the data of the realistic physics, tested on a square colliding with a rectangle, vertical speed -2, horizontal speed 0,:
    angle: richochetspeed angular velocity
    -7.5: -.11 105.10
    -15: .28 104.22
    -22: .77 97.07
    -30: 1.33 78.79
    -37.5: 1.80 45
    -45: 2 0

    If that is confusing, basically to simplify: the graph of the realistic physics looks kind of funky and exponential. The rotation speed doesnt increase linearly in relation to the angle. It would be nice if there was some kind of formula analysis to give me the equation behind this.

    I did not take the time to record all of the data for the homebrew physics, only do some overlay testing and it did not match.

    I don't have Microsoft Excel so if someone could direct me to a graph display app that would be nice.
    Also, if someone could point out a formula analyzer that would be nice, some kind of program that analyzes data and patterns.
    Yes I noticed this but this kind of seems like on the phlebotinum side of the spectrum. I noticed that the linear richochet velocity should lose energy based on the rotational speed. But I dont know the exact equation to determine the linear ricochet velocity and rotational velocity, in regards to the cross product. If there was an exact equation it would be nice.
     
  4. Google AdSense Guest Advertisement



    to hide all adverts.
  5. Neddy Bate Valued Senior Member

    Messages:
    1,680
    I am glad you are still working on this, gamelord. I haven't been able to put much thought into the box scenario, because I have been working on the slightly-easier 'pong' situation that you and I talked about earlier. I remember you said you never quite got the rotation part of it right, and so I have been trying to do that instead.

    I have an Excel spreadsheet which I am using to try to animate the pong ball such that it picks up deflection based on its rotation, and vice-versa. Since you say you do not have Excel, hopefully I will be able to find some other way to share it with you once it is done.

    I have downloaded "screen to gif" which looks like an easy way to capture the animation from the screen, and make it a gif. Perhaps you can use that or something similar to show your progress also. Stay tuned...
     
  6. Google AdSense Guest Advertisement



    to hide all adverts.
  7. RainbowSingularity Valued Senior Member

    Messages:
    1,113
    i dont math, but in theory do you need the values of the wall and the object as mass also with velocity to factor the geometric functions of force & leverage etc ?
    as numerical functions ?
     
  8. gamelord Registered Senior Member

    Messages:
    661
    Thanks.

    As in, you put in some numbers, and it somehow gives you the equation of the function that would produce those numbers (or the closest curve in approximation.)

    And no matter what the mass is it seems to rotate the same. But the wall has stationary so mass is not a factor of the wall.
     
  9. Neddy Bate Valued Senior Member

    Messages:
    1,680
    Below is a screen capture of my Excel animation for a bouncing ball:

    Please Register or Log in to view the hidden image!



    Note that even though the ball appears as an octagon, it is actually modeled as a true circle. So unfortunately this will not help answer the questions in the OP about the rectangular or square box.

    The ball is thrown toward the left with no spin on it. But then, on the first bounce, it picks up some counter-clockwise spin. After bouncing off the left wall, the ball heads back toward the right. So the counter-clockwise spin becomes what I would call "back-spin" because the spin and the direction do not match.

    On the next bounce, the back-spin results in a 'stalled out' type of bounce where the ball loses almost all of its x-velocity toward the right, and the back-spin reverses itself. I consider the reversal of the back-spin to be a special type of bounce that is directed tangentially to the circle. Then on the next bounce, the ball regains x-velocity toward the right.

    I learned at a young age that rubber balls such as super-balls do behave this way when bounced in this manner. So I was careful to make sure that my model did account for this spin behavior.
     
    Last edited: Jul 18, 2018
    Confused2 and Throbber like this.
  10. CptBork Robbing the Shalebridge Cradle Valued Senior Member

    Messages:
    5,777
    Kerbal Space Program, eat your heart out! Well not quite, but that looks pretty good there Ned.
     
    Neddy Bate likes this.
  11. Neddy Bate Valued Senior Member

    Messages:
    1,680
    LOL, thanks, CptB. Below is a smoother version:

    Please Register or Log in to view the hidden image!



    For reference, below is another smooth version, but this time with only 4 sides, like the square that the OP asked about. See if you can find the times where the square should behave differently.

    Please Register or Log in to view the hidden image!



    See if you can find the times where the square should behave differently. You can tell me those times by referring to the "t" variable, or the "ref" variable located at the bottom.

    With everyone's help, maybe we can make it better? Who knows, lol.
     
    Last edited: Jul 22, 2018
  12. gamelord Registered Senior Member

    Messages:
    661
    It's hard to tell from the Gif since I cannot go back and pause it. But around t14 it seems off like it rotates the wrong direction. How did you make this btw?
     
  13. Neddy Bate Valued Senior Member

    Messages:
    1,680
    Sorry gamelord, I did not notice your reply until just now.

    I assume you are talking about the animation with the square/diamond shape, not the one with the octagon. If so, then you are correct! There is a bounce at t=13.60 (ref=68) where the square does appear to rotate the wrong direction. There is also a bounce at t=19.00 (ref=95) where it appears to happen again.

    The reason for that is because my program is designed around the behavior of a round ball. I only made it appear as a square on the screen, but it is really not a square in the program. If you look at t=13.60 (ref=68) and t=19.00 (ref=95) in the octagon animation, it will probably look more correct, because the octagon shape is closer to a round ball.

    I programmed it in Microsoft Excel. Since you don't have that, you can download Open Office for free instead. And then I took the screen captures with another free download called "screen to gif".

    My equations are probably not exact, I used a lot of "IF" statements, and overall it ended up being pretty complicated. Your thread inspired me to make it, but only for a round ball. The square would be even more complicated, so I don't think I will try that any time soon.
     
    Last edited: Aug 15, 2018
  14. Throbber Registered Senior Member

    Messages:
    178
    Pretty impressive. I use excel myself (I recommend it for programmers sincrle Macros on the toolbar uses BASIC.)
     
  15. Neddy Bate Valued Senior Member

    Messages:
    1,680
    Thanks, Throbber. It was a fairly large undertaking, because it involves many layers of nested IF statements. I did keep them in separate cells to avoid creating a formula that would be so huge that it would be impossible to understand. But it was still pretty complicated.

    I have written some macros within Excel before, but I found when I opened the file in Open Office, the macro didn't always behave exactly the same way. It was a while ago, so I don't remember all of the details. But I think the chart would flicker, or it would update very slowly, or something like that.

    So, for this project, I was determined to do it without any macros. That is why you can see me holding my mouse cursor down on a scroll bar. It is the scroll bar which advances the time in the spreadsheet. I also learned that the Form Controls scroll bar does not cause the chart to update in real time (in Excel only, not Open Office), but the ActiveX Controls scroll bar does cause the chart to update in real time in Excel. Good information to know.
     
  16. Throbber Registered Senior Member

    Messages:
    178
    Hello there. Couldn't you use the CELLS function to skip through the calculations instead of holding the mouse on the scroll-bar. For example:

    A1:A2:A3
     
  17. Neddy Bate Valued Senior Member

    Messages:
    1,680
    I'm not familiar with the CELLS function. Is it something used within VBA (Visual Basic)?

    I purposefully made my spreadsheet with no VBA and no macros. It is just a ton of formulas spread out over very many cells, and a standard Excel chart which shows the graphic result.

    The scroll-bar simply advances one cell (labeled "ref") by an increment of 1. I suppose it could be automated in VBA with something like this:

    Code:
    Sub CounterIncrease()
        Sheets("Calcs").Range("A1").Value = Sheets("Calcs").Range("A1").Value + 1
    End Sub
    
    But I did not want to fight with extra code to make the chart update at the correct speed, prevent flicker in the chart, or whatever else might go wrong. So the ActiveX scroll bar did the job for me.
     
  18. Throbber Registered Senior Member

    Messages:
    178
    Ahhh, okay. Yeah there's a, "CELLS ()" function. You just about covered it with the code you wrote.
     

Share This Page