# Help with elastic collision algorithm (need unit vector and velocity)

#### Omnirizon

hello there. this is as much a comp sci question as a physics question, however the comp sci board looked more like a 'computer technology' board, and didn't have much stuff relevant to physics. even though I'm trying to optimize an algorithm for a very specific need, it requires knowledge of the physics algebra (knowledge I don't have and am hoping someone here does...)

I have implemented an elastic collision algorithm, but with one problem. the rest of my code needs a velocity and angle (at the minimum, having the unit vector would be nice too). I can't seem to figure out how to get this out of the elastic collision algorithm without just deriving them from the final product. Isn't there a cheaper way than that? In the course of the algorithm many things are computed (normal vector, normal and tangent unit vector, some scalars...). I've linked the code:

http://paste.pocoo.org/show/144824/" [Broken]

Even if it would be more expensive to get unit vector and velocity, and calculate new vector from those, it might be cheaper than doing final step (lines 18-21, in the paste) and then getting unit vector and velocity from it.

Any smart people in here that can tell me which parameters computed in the course of this algorithm can be used for that? (note: I can see that the vmark.. and v0t/v1t variables can be used to get velocity. now what about unit vector? is there a cheaper way than doing that last step?)

Last edited by a moderator:
Related General Physics Workshop News on Phys.org

"Help with elastic collision algorithm (need unit vector and velocity)"

### Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving