From: Jonathan B. <jbr...@ea...> - 2004-05-15 03:03:32
|
On Fri, 2004-05-14 at 09:28, Andrew Williams wrote: > 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 Of course, a built-in function. I was only looking in the math module. Thanks for clearing this up. -Jonathan Brandmeyer |