[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Re: Hexagonal collision detection?
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Re: Hexagonal collision detection?
- From: Ian Mallett <geometrian@xxxxxxxxx>
- Date: Tue, 15 Sep 2009 07:35:54 -0700
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Tue, 15 Sep 2009 10:36:18 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:content-type; bh=gzEMVrmjqHeWfcGBdJn7rqpbyBJqxEJV+ZhwrT0toF8=; b=TINKhcxNAeVsijzUWJxthYmx6tJsAG8WUtwGBRt+NY6REPMMvsjcw3tMRzJ3fxZQAk 0qpz+XNUDyYqHflhfBB6uVD2Mlvgik3B2CkCMCsmKzIHI1Ac+5OBBESRhxHOLj1Jg9Rw xtc6wGAjNuB/m5igQRXstRKu+q4A+AjXGIv0U=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=pmDBadcIGGii5hzM1b2GCUsBhU44eStqiB2LcVntzJ/kmAmvzNRDAHpKe+UBONn4Qg S8f5h5oRAmVvIg0W6QTWWk8peZzoKJsv0V7MhOIpxDDQZrVPbr9Y1dY5z3rQT443rVKS 1TELRrco3uaowli4RC/iUaRSd/GLPKQwtXPfg=
- In-reply-to: <4AAF85A3.8080300@xxxxxxxxxxxxx>
- References: <4AAF85A3.8080300@xxxxxxxxxxxxx>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
As used in my project http://www.pygame.org/project/649/.
def pointtest(self,point):
#drawpoints is a list containing points defining your polygon
#point is the mouse position
#if it doesn't work, list them in opposite order.
#works for arbitrary convex geometry
x = point[0]
y = point[1]
Lines = []
index = 0
for index in xrange(len(drawpoints)):
p0 = drawpoints[index]
try: p1 = drawpoints[index+1]
except: p1 = drawpoints[0]
Lines.append([p0,p1])
for l in Lines:
p0 = l[0]
p1 = l[1]
x0 = p0[0]; y0 = p0[1]
x1 = p1[0]; y1 = p1[1]
test = (y - y0)*(x1 - x0) - (x - x0)*(y1 - y0)
if test < 0: return False
return True
Ian