Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That's what one of my undergrad mechanics classes was. Actually that was just a project in the course, along with all of the usual theory, lectures, assignments etc.

I don't think that's terribly unusual.



Cool! Which school was that? Did they just assume you knew coding to begin with or did they teach the programming aspect also?

Did you keep any lecture notes/code from that project? I'm working on something along those lines[1], but not sure how to do the collisions and contact forces.

The source code of box2D is very useful and I have some other physics engine resources but something with a more physics-lesson flavour could be very handy as inspiration.

[1] https://github.com/ivanistheone/phys.js


Hey, sorry I didn't see this for a week. Another victim of the short halflife of HN threads ;-)

Anyhow, I suspect that code still exists somewhere, but offhand I can't see where that is; likely a backup somewhere. It was some time ago. As for lecture notes, I'm not sure they'd help very much. I should have been more accurate: my mechanics course was just a mechanics course where we had to pick a project. I chose to make a physics simulator, so all the research therein was not part of the course.

There are a number of ways to do collision detection. If memory serves I used a bisection method with bounding volume intersection trees. I believe this is a known technique you can look up. If not, it basically amounts to dividing up your objects into a series of adjacent bounding volumes, for example divide the bounding volume into octants. Then at each simulated time step, you run through tree structure which shows all of the locations where two octants belonging to different objects intersect. Any one of these intersections essentially means that a collision has already happened, and you've simulated your way into an impossible situation (assuming non-deformable bodies). So what you have to do is find out the time step when the collision actually occurred at that locale. One way to do this is to backtrack and use a bisection method[1] to zero in on your collision time, and then begin simulating again from there. At each collision point you need to determine the time of collision (face-face, face-vertex, etc.) and calculate the contact forces iteratively until everything is resolved.

Calculating the contact forces is actually the tricky bit, and there's been a good deal of research on that topic. The trouble is that the contact forces are interdependent, so you can't just solve them in parallel, or exactly. It pretty much boils down to a Quadratic Optimization problem, which needs a non-convex optimizer to solve (I believe cvxopt has one, but if you're working in JS...). The details of that method get hairy pretty quickly, and are far out of scope for a HN reply, unfortunately.

You probably knew most of that already, but in any case, there it is. Let me know if you have any more specific questions.

EDIT: The school was the University of British Columbia, and the course was like the second classical mechanics course or something. It didn't teach any programming or computer science aspects. They knew that most of the class was capable of the required feats because of the prereqs for the course and the programs people were in, so they pretty much just threw us into the deep end.

[1] http://en.wikipedia.org/wiki/Bisection_method




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: