Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #51085

Re: Beginner. 2d rotation gives unexpected results.

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!news2.arglkargh.de!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <dwightdhutto@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.017
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'skip:[ 20': 0.04; 'class,': 0.07; 'assuming': 0.09; 'english,': 0.09; 'linear': 0.09; 'translate': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'windows': 0.15; '23,': 0.16; 'biology': 0.16; 'brackets,': 0.16; 'code?': 0.16; 'coordinates': 0.16; 'false:': 0.16; 'left,': 0.16; 'pygame': 0.16; 'pygame,': 0.16; 'rotation': 0.16; 'skip:[ 30': 0.16; 'weird': 0.16; 'student': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'trying': 0.19; 'result.': 0.19; 'skip:p 40': 0.19; 'import': 0.22; 'cc:addr:python.org': 0.22; 'math': 0.24; "haven't": 0.24; 'cc:2**0': 0.24; 'right.': 0.26; 'excel': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'am,': 0.29; 'points': 0.29; "doesn't": 0.30; 'skip:g 30': 0.30; 'message- id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'program,': 0.31; '255,': 0.31; 'clock': 0.31; 'pos': 0.31; 'class': 0.32; 'probably': 0.32; 'url:python': 0.33; 'skip:# 10': 0.33; 'screen': 0.34; 'problem.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'false': 0.36; 'done': 0.36; 'url:listinfo': 0.36; 'method': 0.36; 'url:org': 0.36; 'wrong': 0.37; 'planning': 0.38; 'skip:p 20': 0.39; 'url:mail': 0.40; 'even': 0.60; 'eventually': 0.60; 'black': 0.61; 'lower': 0.61; 'new': 0.61; 'simple': 0.61; 'first': 0.61; 'back': 0.62; 'complete': 0.62; 'p.s.': 0.66; 'subject:. ': 0.67; 'sample': 0.67; 'department.': 0.68; 'jul': 0.74; 'square': 0.74; 'upper': 0.74; 'increase': 0.74; '100': 0.79; 'center.': 0.81; 'all!': 0.84; 'calculations': 0.84; 'much,': 0.84; 'results,': 0.84; 'russia,': 0.91; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=pOaFVgwg/8M3GpRix96xri5HlzdKOD3g3tKn+mJU19o=; b=jn/Oe+Fo3WRn6WALAwGt8OrOnzk0w7RgahT6+ZDiNZ+0MNQkmWKMeK3FsA7lrEquEl hbPffIGzegG/cY10AcuqO9A97QylhZz7VuIKwqKpBZE0Y+Bq8/IFTletJfhJ+LmPez5W bcTNxGdbR1dAzO5OOhXW+HRs547k2vwWRZB8ZK6Il0534YJE2mkWO4B8no/yVKEKG2Tf qe4N1EVonH3XyxOEG6bGt3eSdYitUmXgYZW315sL+sTMHbjY15peABUaQg+12dbBtrzo DOJUo8KHp7ijOeQja0btCk8HlPHmSECvZWYnMdykZjU8Kay9nU5a/z9t2LBjj8EgifrV VDKw==
MIME-Version 1.0
X-Received by 10.224.135.138 with SMTP id n10mr12026310qat.96.1374584667888; Tue, 23 Jul 2013 06:04:27 -0700 (PDT)
In-Reply-To <0a905ff1-199c-4900-81e6-d9b7bb63bb44@googlegroups.com>
References <0a905ff1-199c-4900-81e6-d9b7bb63bb44@googlegroups.com>
Date Tue, 23 Jul 2013 09:04:27 -0400
Subject Re: Beginner. 2d rotation gives unexpected results.
From David Hutto <dwightdhutto@gmail.com>
To enmce@yandex.ru
Content-Type multipart/alternative; boundary=001a11c29762d7ec5a04e22d6ed1
Cc python-list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5003.1374585070.3114.python-list@python.org> (permalink)
Lines 238
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1374585070 news.xs4all.nl 15891 [2001:888:2000:d::a6]:53484
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:51085

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

haven't used pygame that much, but it sounds like you drew Z. You have
[0,0],[0,100],[100,0],[100,
100]
0,0 is the top left, if I recall 0, 100 would be the lower left, then you
move to100, 0 which would go diagonal to the top right, and then 100,100 to
the lower right, this is assuming 0,0 is the upper left. for a square you
would go,[0,0],[0,100],[100,100],[100,0]then back to [0,0] to complete the
square. This is assuming that 0,0 is the upper left, the coords are x,y in
the brackets, and the increase in x takes you the right, and the increase
in y takes you down.

If that doesn't work,I'll download it later, and try it out.


On Tue, Jul 23, 2013 at 8:34 AM, <enmce@yandex.ru> wrote:

> Hello!
> This is my first post, nice to meet you all!
> I`m biology student from Russia, trying to learn python to perform some
>
> simple simulations.
>
> Here`s my first problem.
> I`m trying to perform some simple 2d vector rotations in pygame, in order
>
> to learn the basics of linear algebra and 2d transformations. So far i
>
> understand matrix multiplication pretty well, and probably all my math is
>
> right. Eventually i`m planning to write Poly class, and use it to rotate
>
> and translate some simple shapes. But when i try and write it in the
>
> program, i get very weird results, like all points of rectangle with
>
> coordinates [0,0],[0,100],[100,0],[100,100] start to go spiral and
>
> eventually shrink to the center. Although even Excel calculations with
>
> this formulas give me right result.
> I use Python 3.3 on Windows Xp.
> What is wrong with my code?
>
> [code]import pygame
> import math as m
>
> black = ( 0, 0, 0)
> white = ( 255, 255, 255)
> green = ( 0, 255, 0)
> red = ( 255, 0, 0)
>
> class Poly():
>     pos = [100,100] #x and y coordinates of a point
>     rot = m.radians(1) #rotation in degrees
>     def draw(self): #draw point
>         pygame.draw.circle(screen,white,self.pos,10,0)
>     def rotate(self): # rotation method
>         sin = m.sin(self.rot) #calculationg sin and cos
>         cos = m.cos(self.rot)
>         x_rot = int(self.pos[0]*cos-self.pos[1]*sin) #mulpitplicating
>
> vector to rotation matrix
>         y_rot = int(self.pos[0]*sin+self.pos[1]*cos)
>
>         self.pos[0] = x_rot #set new coordinates to a point
>         self.pos[1] = y_rot
>
> a = Poly() #Some simple sample points giving rectangle
> b = Poly()
> c = Poly()
> d = Poly()
>
> b.pos = [0,100]
> c.pos = [100,0]
> d.pos = [0,0]
>
> pygame.init()
> size = [700,500]
> screen = pygame.display.set_mode(size)
> done = False
> clock = pygame.time.Clock()
> while done == False:
>     for event in pygame.event.get():
>         if event.type == pygame.QUIT:
>             done = True
>
>     a.rotate() #perform rotation
>     b.rotate()
>     c.rotate()
>     d.rotate()
>
>     screen.fill(black)
>
>     a.draw() #draw point
>     b.draw()
>     c.draw()
>     d.draw()
>     pygame.display.flip()
>     clock.tick(30)
>
> pygame.quit()[/code]
>
> P.S. Sorry for my english, bit rusty in that department.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Beginner. 2d rotation gives unexpected results. enmce@yandex.ru - 2013-07-23 05:34 -0700
  Re: Beginner. 2d rotation gives unexpected results. Peter Otten <__peter__@web.de> - 2013-07-23 15:11 +0200
    Re: Beginner. 2d rotation gives unexpected results. Nobody <nobody@nowhere.com> - 2013-07-23 16:20 +0100
  Re: Beginner. 2d rotation gives unexpected results. David Hutto <dwightdhutto@gmail.com> - 2013-07-23 09:04 -0400
  Re: Beginner. 2d rotation gives unexpected results. Joshua Landau <joshua@landau.ws> - 2013-07-24 22:17 +0100
  Re: Beginner. 2d rotation gives unexpected results. Terry Reedy <tjreedy@udel.edu> - 2013-07-24 19:55 -0400

csiph-web