From: Andrew W. <an...@ph...> - 2004-05-14 13:28:20
|
On Fri, 14 May 2004 08:53:45 -0400, Jonathan Brandmeyer wrote: >All vectors are always floating-point values in VPython. If you need to >truncate the precision to an integer type, you will probably need to >write your own round-to-nearest conversion routine since Python only >directly supports truncation of the decimal part. See math.modf() for >some help here. I'd have thought the 'round' builtin would do just that. It returns a float, but rounded to the specified number of decimal places (if the optional number of decimal places is omitted), so int(round(x)) should always be the nearest integer. Still, I'd test for collision by specifying a tolerance a bit more explicitly - if pos2 and pos1 are both vectors, this is short and very readable: if abs(pos2 - pos1) < 0.01: handle_collision() Andrew |