|
From: Bruce S. <Bru...@nc...> - 2004-05-16 01:36:02
|
I don't understand this syntax. If pos2 and pos1 are intended to stand for something like box1.pos and box2.pos, positions of VPython objects, then what you need is mag(pos2-pos1), not abs(pos2-pos1). Bruce Sherwood Jonathan Brandmeyer wrote: > 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 > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: SourceForge.net Broadband > Sign-up now for SourceForge Broadband and get the fastest > 6.0/768 connection for only $19.95/mo for the first 3 months! > http://ads.osdn.com/?ad_id=2562&alloc_id=6184&op=click > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users |