[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Rotate image around another point?
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Rotate image around another point?
- From: altern <altern2@xxxxxxxxx>
- Date: Thu, 19 Apr 2007 10:36:52 +0200
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Thu, 19 Apr 2007 04:37:15 -0400
- Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding; b=in6Y1yi/wFp2WlmI1cSCVGgwCceI5hFlGvvgHFqBP+ABfUos15p/vu7lkK0Wv9rBaWzMn3MrBxfkmMbHqV1ROzAZldcRgn6NMqHQbbamjX03aMmk0WrtIrhyS3fv2RCm1m+7oA1LjMiRCFtx2ofuWq9t9iY+Us7VEi1zgPuECvk=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding; b=uM0l4QLxPqQzVtZcFWVlTgtmAXzSGvYoymlBhE1hEFIZXy1tz08A3NUQVP7OC94ske5Zfk+YaH0VGvGOYGb9sLrxF0Sj11eju12qEEkb6M9Yoxj8fo1Q9k20Q23PHF34H0y0nLhHimJ7PeeRfKTw7Dni4EoW2BQEeO5U5oP+1Qc=
- In-reply-to: <1176969199.6550.3.camel@localhost>
- References: <1176969199.6550.3.camel@localhost>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
- User-agent: Thunderbird 2.0.0.0 (X11/20070326)
hi john
John Eriksson(e)k dio:
Hi,
The rotate function in the transform module rotates an image about its
center. But what if I want to use another point?
Is there another solution than to modify the size of the image to change
its center point?
I think something like this should do what you are looking for.
from math import *
def rotPoint(point, axis, ang):
""" Orbit. calcs the new loc for a point that rotates a given num
of degrees around an axis point,
+clockwise, -anticlockwise -> tuple x,y
"""
x, y = point[0] - axis[0], point[1] - axis[1]
radius = sqrt(x*x + y*y) # get the distance between points
RAng = radians(ang) # convert ang to radians.
h = axis[0] + ( radius * cos(RAng) )
v = axis[1] + ( radius * sin(RAng) )
return h, v
myimage.center = rotPoint(myimage.center, (300,300), 45)
this line should rotate myimage.center around point (300,300) by 45 degrees
Best Regards
/John Eriksson