[Numpy-discussion] Distance Formula on an Array

Ian Mallett geometrian@gmail....
Sun Apr 26 18:17:06 CDT 2009


Using http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html, I
came up with:
x0 = numpy.array(#point to collide with)
x1 = #objects' positions
x2 = #objects' previous positions
numerator = numpy.sqrt((numpy.cross((x0-x1),(x0-x2))**2).sum(1))
denominator = numpy.sqrt(((x2-x1)**2).sum(1))
dist = numerator/denominator
collided_indices = numpy.where(dist<1.0)[0] #1.0==radius
Unfortunately, in some cases, it returns indices when it shouldn't--when the
objects clearly don't penetrate the sphere.  I also get the feeling this
will give false positives if the line containing the vector intersects the
sphere, but the vector itself does not, though I don't know.
Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090426/d4b3d073/attachment.html 


More information about the Numpy-discussion mailing list