[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Re: [Tutor] Fastest (x,y) distance calculation
- To: "Raymond Hettinger" <python@rcn.com>
- Subject: [pygame] Re: [Tutor] Fastest (x,y) distance calculation
- From: "Zak Arntson" <zak@harlekin-maus.com>
- Date: Fri, 12 Sep 2003 13:01:42 -0700 (PDT)
- Cc: "Magnus Lycka" <magnus@thinkware.se>, tutor@python.org,pygame-users@seul.org
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Fri, 12 Sep 2003 16:02:11 -0400
- Importance: Normal
- In-reply-to: <00cb01c378d7$0cea76a0$5234c797@oemcomputer>
- References: <think001_3f601bad51cb8@webmail.thinkware.se> <00cb01c378d7$0cea76a0$5234c797@oemcomputer>
- Reply-to: pygame-users@seul.org
- Sender: owner-pygame-users@seul.org
- User-agent: SquirrelMail/1.4.1
> [Raymond Hettinger]
>> > Distance calculations are much cheaper if you store the coordinates
>> > as complex numbers and use abs().
I don't know the concept behind using complex numbers and abs to determine
distance. How does that work?
> Executive summary: abs(z1-z2) beats the (deltax**2 + deltay**2)
> approach
(deltax * deltax) + (deltay * deltay) beats the **2 approach, but only
decreases ~0.8 times when I tried it.
I'm also considering creating some sort of data structure that aids in
nearest-point calculating. Any suggestions?
--
Zak Arntson
www.harlekin-maus.com - Games - Lots of 'em