Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I'm trying to give shapes in my physics engine roundness/ curvature.

I am aware of various methods for mathematically defining curvature such as bezier-curves, ellipses, etc; but I'm not sure which methods are most appropriate for use in a physics engine. I must consider the speed, flexibility, and difficulty of constructing/joining the curves when choosing my approach. The ideal is a system where a user could easily construct and collide a large amount of curved, aesthetic polygon bodies together, yet I could still maintain a satisfactory framerate. However it's inevitable that ease-of-use and other attributes will suffer.

NOTE: my physics engine is continuous, which means I must pre-calculate the times at which polygons will collide. Keep in mind that the curve's route my not be linear.


For each suggestion please give the positives/negatives!

  • What techniques are there for mathematically defining a 2D curve?

  • Advantages/Disadvantages (speed, flexibility, ease of construction/use)?

  • Is the technique feasible for an engine where predictability of collisions is crucial?

share|improve this question
1  
Piecewise linear curves are speedy, easy to handle and able to approximate smooth and non-smooth curves... –  Dirk Dec 14 '11 at 7:54
2  
"a system in which a user can easily form fairly complex curves, but still make the intersection calculations simple and fast." - this sounds very Scylla and Charybdis to me... –  J. M. Dec 14 '11 at 7:56
    
If you have the curve's equation, several software tools would allow you to find the intersection easily specially if the curves are functions in one variables. If you have data points and you want to find curves that represent them (interpolation, extrapolation,etc.), again, there are tools for that. Assuming that the process is manual, I could point you to some sources if you are interested or you could simply search the net. –  Emmad Kareem Dec 14 '11 at 9:26
    
@Emmad That would be great! What software/ math libs do you suggest for finding intersections? I'm pretty sure I can get the movement of all the edges of my bodies down to a single equation that depends on time. –  Griffin Dec 14 '11 at 17:25
    
Are your bodies getting deformed? –  Jayesh Badwaik Aug 17 '12 at 6:27

2 Answers 2

If you can get your functions in the form of:

f(t)=... and

g(t) =...

and you want the intersection, all you have to do is use Desmos Graphs

You could also do something like f(t)-g(t) = 0 and the graph of the result will show the intersection as well.

After the graph is displayed, you can place the mouse on the graph to show the point of interest. It helps when you color the graphs.

Example

share|improve this answer
    
That's some useful software, but do you know of any libraries that i can actually incorporate into my physics engine? –  Griffin Dec 14 '11 at 23:53
    
@Griffin, what language do you want to use? Do you want the software to show graphs or solve the equations? –  Emmad Kareem Dec 15 '11 at 8:24
    
Solve the equations, and I use c++ –  Griffin Dec 15 '11 at 22:44
1  
I am not an expert in C++ but you could check these: en.wikipedia.org/wiki/NAG_Numerical_Libraries and en.wikipedia.org/wiki/List_of_numerical_libraries also, MATLAB can be called from C++ to the best of my knowledge. I hope this answers your questions. –  Emmad Kareem Dec 15 '11 at 23:57

TL;DR If you want to specify a curve for computation in a computer system, use actual points rather than equations. It will be better anytime. And for analysis, use piecewise linear (polygonal) models.

NOW THE LONGER PART

Stick with piecewise linear as far as possible. Why? Absolutely simple to construct, good speed, large flexibility. Accuracy can be easily improved using a higher resolution.

Your ease of use seems to be a problem. The solution to that will be to make an interface so that user has to specify only the points of the boundary of the body with a sufficient accuracy. He can use whatever methods he wants to do so. Once that is done, you can take those points and design whatever curves you want from it. As in this case, you can see, piecewise linear is quiet simpler than other curves and also, it imposes least restriction on the user.

There are many other advantages of piecewise linear. You can use mesh libraries to construct a matrix based description of your system, and then use it predict crashes. Once the crash has occured, if your bodies are not getting deformed, great, you can just reuse the descriptions but with a little change in the equations.

share|improve this answer
    
Of course you can construct the curves with any method, and then approximate them as piecewise linear curves in the desired accuracy. That way you can produce the curves with whatever method is appropriate for the user interface, while still having the simplicity and speed of piecewise linear curves during the calculation. –  celtschk Aug 17 '12 at 6:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.