Help on Optimization Problem for Tennis Ball Physics + prediction

Started by
41 comments, last by kenBlade 5 years, 1 month ago
Advertisement

Yes, get it. I can not really help, but what i would do is this:

Use the simple analytic solution as proposed to make an initial guess.

Create a mini simulator that measures the error (using large timesteps and analytic segments, adding drag and magnus in each step)

Adjust the target using the found error and do some iterations over all of this, making the timesteps smaller each time so accuracy increases.

 

I assume drag and magnus have small effect and analytic segments / large timesteps are possible. (But i'm no sportsman :) )

Otherwise replicate PhysX integrator (RK4?) and use small timesteps should be still fast enough for a single ball.

Usually physics engines also allow to create a second dummy world to do such stuff more easily, if that's an option with Unity.

@JoeJ, your comments are helpful. I will be using the RK4 integration.

The code is posted up on GitHub. I'll be updating the code frequently over the next couple of days, while I work on it. So far all it does it draw the court and net.

https://github.com/sjhalayka/tennis

P.S. My code is in C++, and it uses GLUT (freeglut works well).

Included below is an illustration. The court surface is orange, and the net is transparent blue. The ball is the white dot; the white line represents the ball's initial velocity, the black line represents the ball's initial angular velocity, and the gray line shows where on the court the ball is hovering above.

court.png

 

The next step is to get the path that the ball takes, depending on the initial velocities, while accounting for gravitation and the Magnus force.

Wow this looks awesome! Thanks for the tips everyone, and for the code Taby.

 

To pitch in what little I can, here's a link to my Unity project with full source code, and another link to scripts only. The C# scripts are the .cs files. I will only keep this link up for a week. Perhaps Taby, could you please add my TennisBallPhysics.cs to a folder in your repo? It should save you some time, but since it is a bit buggy atm (ball spins barely affect a life sized ball, but scaling the throwball prefab to.25 X/Y/Z scale yields good results) and it's all C#, not C++, no worries if you decide not to use it.

Full project link - 

https://drive.google.com/file/d/1FtvFsMVpZDUEYsUECUEgH-Hoe3-Mialb/view?usp=sharing

Scripts only -

https://drive.google.com/open?id=1H0enf_CAiiQ6oalJUnARsPE7VVE1JpQG

 

WIP video tutorials -

https://www.youtube.com/watch?v=gXmA37uDTUE&list=PLqXAcOsVnsHtyRhTjHveqCe0cjq9lPCRv&index=4

https://www.youtube.com/watch?v=dVBn1gRy3co&list=PLqXAcOsVnsHtyRhTjHveqCe0cjq9lPCRv&index=5

 

Related project based on Python I found on GitHub:

https://github.com/laispc/MagnusEffect/blob/master/README.md

So I have the physics working, and collision detection with the surface and the net.

court.png

Next thing to do is to specify the desired location on the opponent's side of the court. From there I can come up with an initial guess. From there I can refine the guess using gradient descent. It will only take another day or two to complete the task.

I'm very new to C++, OpenGL and Glut/freeGlut, but I followed a tutorial to set up the project and run your code, and here are the errors I got when I attempted to run the project in Visual Studio 2017:

 

image.thumb.png.45ebaa02ab353bdb111dc9d5cc57ba29.png

 

Not sure if it's easily resolved or not. But would be nice to test out your scene.

It looks like the cpp files aren't being compiled.

I put an .sln file up for you at https://github.com/sjhalayka/tennis/raw/master/tennis_sln.zip

Fortunately, the C++ code will be relatively small, and will be easy to port over to C#. I won't use anything like lambdas or function pointers or anything fancy like that. :)

still an error:

 

image.png.edd8a953ec0f305f822e03150885c8d4.png

 

This is after opening your .sln file, then main.cpp file and clicking the Debug/compile button (is this the same thing?) in Visual Studio 2017.

Did the includes in solution explorer -> properties -> c/c++, and linker. included the include folder, the lib folder, and the freeglut.lib file according to this tutorial (

 

image.thumb.png.12f11fdaed33520b15172b347a901582.png

 

I'm using freeglut btw.

This topic is closed to new replies.

Advertisement