# RE: [pygame] How to rotate a rect

```I think what you described is usually called the Manhattan distance.
(Basically because your measuring the "number of blocks" between objects.)

You're right that you don't necessarily need a Sqrt at the end as you would
for a real Euclidean distance, seeing we just want a relative measure, but I
think you want:
...
distsquared = (object2.x - object1.x) * (object2.y - object1.y) # times
...

Manhattan distance may work okay too, but the bounding box for collisions
will be kind of like a round diamond shape. (It will be smaller at the
diagnals.) Adding the "*" will make the collision area circular as you
suggest.

In all cases above your just picking a point in your box and not really
looking at the orientation of the rotated rect.
One way to do that would be to write similar fn's to Rect's collision
detection methods, but for generalized polygons.

mike

-----Original Message-----
From: owner-pygame-users@seul.org [mailto:owner-pygame-users@seul.org]On
Behalf Of Paul Sidorsky
Sent: Friday, June 29, 2001 8:43 PM
To: pygame-users@seul.org
Subject: Re: [pygame] How to rotate a rect

> Making the box is not the problem but how to make fast collision
detection?

This may not be suitable for your situation but I'll describe it anyhow
since I haven't seen it mentioned yet:

Give each object a radius or size and then use the distance formula.  If
the distance between two objects is less than the combined radiuses (or
half the combined sizes) of the objects, they collide.  To avoid
floating point, use the squared distance.  Here's pseudo code:

limitsize = (object1.size1 + object2.size2) / 2
limitsize *= limitsize
distsquared = (object2.x - object1.x) + (object2.y - object1.y)
if distsquared <= limitsize:
# Boom!

This works great for spherical objects and can work for others if you
don't need 100% precision.  The inaccuracy increases as the sizes get
larger.  I'm not sure how practical this method is in "real" games since
I've only tried it on a small scale, but it might be worth a shot.

--
======================================================================
paulsid@home.com                      http://members.home.net/paulsid/
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org

_________________________________________________________
Do You Yahoo!?