2D vector graphics Problem

F. GEIGER f.geiger at vol.at
Sun May 29 11:13:18 EDT 2005


>  xRel, yRel = self.relPoint # The rotation should be relative to this

Shouldn't it be

x -= xRel
y -= yRel
xR = x * cos(phi) - y * sin(phi)
yR = x * sin(phi) + y * cos(phi)

then?

Regards
Franz GEIGER


"Karl Max" <karlmax at tiscalinet.it> schrieb im Newsbeitrag
news:4299c4de$0$17099$5fc30a8 at news.tiscali.it...
> Hi all,
>
> I'm new here. Name's Max from tuscany, and I don't speak english very well
> :-) I am not veteran at coding, I am most like an "artisan coder" since
> commodore 64 times.
>
> Now the problem:
> I would like to have a little 2d engine to calculate and trace segments
and
> poly's and their collisions, rotations and trasformations. I didn't
> understand too much in tutorials (you're all high school coders, well
> informed in maths and programming theory!!! :-))) so I took my old school
> books on Cartesian space and had a refresh. Proceeding in this not too
> optimized way of coding my needs, I took down some generic classes to
> describe primitive objects in space (vertexes, segments, poly's etc...).
>
> Now I try to make a point rotate around another point.
> Here's my piece of code:
>
> def rotate(self, w):
>  # This method belongs to the class Vertex
>  # w = angle expressed in radiants
>  x, y = self.coords
>  xRel, yRel = self.relPoint # The rotation should be relative to this
>  sin, cos = math.sin(w), math.cos(w)
>  x = x * cos - y * sin - xRel * cos + yRel * sin + xRel
>  y = x * sin + y * cos - xRel * sin - yRel * cos + yRel
>  self.coords = (x,y)
>
> I know the style isn't professional, and if you should have some piece of
> advice, you're welcome... but that's not the question.
> When I render it graphically, using pygame 1.6, the point tends to fall
> towards the center of rotation round after round. I mean if I have a loop
> rotating the point by a fixed angle, the point is like "attracted" by the
> center every round it does, like in a vortex.
> I think it depends from float representation inside python, but I have no
> clear idea about how to resolve it. Maybe should I use Decimal module? Or
is
> there any trick on this subject (2D vector graphics?) that I can't even
> imagine?
> Thanks you all,
>  Max
>
>





More information about the Python-list mailing list