Note that there are some explanatory texts on larger screens.

plurals
  1. POrotation of 2d shape clockwise direction
    primarykey
    data
    text
    <p>I am new to python and graphics but have programmed before. According to <a href="http://en.wikipedia.org/wiki/Transformation_matrix#Rotation" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Transformation_matrix#Rotation</a> ,</p> <blockquote> <p>For rotation by an angle θ anticlockwise about the origin, the functional form is x' = xcosθ − ysinθ and y' = xsinθ + ycosθ</p> </blockquote> <p>But the following python code rotates it in the clockwise direction. Could somebody explain this?. Also translating the rectangle to the origin and back to the center seems to be an overhead. Is there any way to avoid this?. Thanks in advance.</p> <p>PS: I have looked at <code>pygame.transform.rotate</code> which does this but I would like to start from scratch to get better idea about the graphics. Is there a way to see the source of this method from python interpreter?</p> <pre><code>import pygame, sys, time from math import * from pygame.locals import * co_ordinates =((200,200),(400,200),(400,300),(200,300)) window_surface = pygame.display.set_mode((500,500),0,32) BLACK=(0,0,0) GREEN=(0,255,0) RED=(255,0,0) window_surface.fill(BLACK) ang=radians(30) """orig=pygame.draw.polygon(window_surface,GREEN,co_ordinates) n_co_ordinates = tuple([(((x[0])*cos(ang)-(x[1])*sin(ang)),((x[0])*sin(ang)+(x[1])*cos(ang))) for x in n_co_ordinates]) n_co_ordinates = tuple([((x[0]+300),(x[1]+250)) for x in n_co_ordinates]) print(n_co_ordinates) pygame.draw.polygon(window_surface,RED,n_co_ordinates)""" pygame.display.update() while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() for i in range(360): ang=radians(i) if i&gt;=360: i=0 n_co_ordinates = tuple([((x[0]-300),(x[1]-250)) for x in co_ordinates]) n_co_ordinates = tuple([((x[0]*cos(ang)-x[1]*sin(ang)),(x[0]*sin(ang)+x[1]*cos(ang))) for x in n_co_ordinates]) n_co_ordinates = tuple([((x[0]+300),(x[1]+250)) for x in n_co_ordinates]) window_surface.fill(BLACK) pygame.draw.polygon(window_surface,RED,n_co_ordinates) pygame.display.update() time.sleep(0.02) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload