Take the 2-minute tour ×

I'm trying to program a simulation of people, and one thing I'd like to do is simulate personal-space buffers. To do this, I need to check one point pt1 to see if it needs to be repelled by another point pt2. I want the scaling of the resistance of pt1 to model a hyperbola such as 1 / (distance + 1) where the +1 ensures that at small distances the force does not go to infinity.

I have most of this figured out, but I can not figure out how to get a force vector which relative to pt1 is a normalized vector of the force against it. Can anybody here good with vector math help me? Thank you!

share|improve this question
Should your hyperbola describe the force or the energy? Why do you want to have the resulting vector normalized? The general idea is to compute the resulting forces as the sum of pairwise forces, where each pairwise force is a unit length direction vector multiplied by the force as computed from the distance. –  MvG Jun 6 '13 at 6:48
add comment

1 Answer

Not sure if I understood your question correctly, but I'm assuming this: you have a list of points, let's say in an array of pairs of coordinates:

[[x0, y0], [x1, y1], [x2, y2], ... [xn, yn]]

Then, if you need to calculate the resulting force vector on the point #k you need this:

force_vector = [0, 0]
for i from 0 to n:
    skip if i = k
    x_force = xk - xi
    y_force = yk - yi
    // Resulting force vector for i-k pair will be aligned as [x_force, y_force]
    // we just need to normalize it
    vector_modulo = square_root(x_force^2 + y_force^2)
    normalized_vector = [x_force/vector_modulo, y_force/vector_modulo]
    dist_ik = square_root((xk-xi)^2 + (yk - yi)^2)
    force_vector[0] += normalized_vector[0]/(dist_ik + 1)
    force_vector[1] += normalized_vector[1]/(dist_ik + 1)        

At the end you will have force_vector with x and y values of a "force" for #k point.

share|improve this answer
add comment

Your Answer


