GraphicsContext - visible offset between lines and other shapes

Hi All,

I’m trying to accomplish the simple task of drawing two circles in random places on a GraphicsContext and connecting their centers with a line segment. However, the circles always appear below and to the right of the endpoints of the line. I have observed this using both StrokeLine and DrawLines, on windows 7/python2.7/wx 2.8.12.1 and centos 6/python2.6/wx 2.8.12.0 . Can someone please help me figure out how to accomplish this? Sorry if it’s a dumb question but I couldn’t find any info on the subject anywhere.

Thanks in advance,

David

stroke_line.py (1.1 KB)

I wanted to test your module but running it gave me a TabError because you are mixing tabs and spaces. Never do that. Haven’t you read PEP 8? I’m sure no one would go through the hassle of fixing all tabs to spaces just to fix your module and then to be able to run it and see what’s the issue in it. First off, fix your module so that it has no tab whitespace in it, then resend it. Thanks.

I’m trying to accomplish the simple task of drawing two circles in random places on a GraphicsContext and connecting their centers with a line segment. However, the circles always appear below and to the right of the endpoints of the line. I have observed this using both StrokeLine and DrawLines, on windows 7/python2.7/wx 2.8.12.1 and centos 6/python2.6/wx 2.8.12.0 . Can someone please help me figure out how to accomplish this?

Maybe the docs
http://docs.wxwidgets.org/stable/wx_wxgraphicscontext.html#wxgraphicscontextdrawellipse
are not completely clear in the meaning, that the dimension of the ellipse is given by x, y and h (eight), w (idth). Simply offset the x, y coordinates by the radius.

    diameter = 20
    radius  = diameter * 0.5
    gc.DrawEllipse( x1*maxx - radius, y1*maxy - radius, diameter, diameter )
    gc.DrawEllipse( x2*maxx - radius, y2*maxy - radius, diameter, diameter )

David Howard wrote:

Hi All,

I'm trying to accomplish the simple task of drawing two circles in
random places on a GraphicsContext and connecting their centers with a
line segment. However, the circles always appear below and to the right
of the endpoints of the line. I have observed this using both StrokeLine
and DrawLines, on windows 7/python2.7/wx 2.8.12.1 and centos
6/python2.6/wx 2.8.12.0 . Can someone please help me figure out how to
accomplish this? Sorry if it's a dumb question but I couldn't find any
info on the subject anywhere.

When you call DrawEllipse you pass the upper-left corner of the rectangle that contains the ellipse, as well as the width and height. So when you draw a line to/from those same coordinates then you are connecting the rectangle corners, not the centers of the ellipses.

···

--
Robin Dunn
Software Craftsman

Ah, that makes perfect sense. Thank you very much for your help.

···

On Saturday, August 10, 2013 1:29:39 PM UTC-7, Robin Dunn wrote:

David Howard wrote:

Hi All,

I’m trying to accomplish the simple task of drawing two circles in

random places on a GraphicsContext and connecting their centers with a

line segment. However, the circles always appear below and to the right

of the endpoints of the line. I have observed this using both StrokeLine

and DrawLines, on windows 7/python2.7/wx 2.8.12.1 and centos

6/python2.6/wx 2.8.12.0 . Can someone please help me figure out how to

accomplish this? Sorry if it’s a dumb question but I couldn’t find any

info on the subject anywhere.

When you call DrawEllipse you pass the upper-left corner of the
rectangle that contains the ellipse, as well as the width and height.
So when you draw a line to/from those same coordinates then you are
connecting the rectangle corners, not the centers of the ellipses.


Robin Dunn

Software Craftsman

http://wxPython.org