package require Tk
canvas .c -width 100 -height 100
pack .c
set x 50
set y 50
set r 4.5
for {set i 0} {$i < 36} {incr i} {
set t [expr $i*0.174532925]
.c create line $x $y [expr $x+$r*sin($t)] [expr $y+$r*cos($t)]
}
You can get different effects by changing x, y and r. With the values
used above, the supposedly symmetrical pattern has a distinctly flat
lower-right quadrant. (You may need to use a magnifying glass.) Using
deliberately oddball values, such as x=y=50.1, or r=4.7, have an influence
on the pixel pattern, as you'd expect, but the unwanted asymmetry is
frequently seen.
What is the cause, and can I somehow stop it happening? n.b. (i) my
application doesn't know about the mapping from world coordinates to pixel
coordinates, and doesn't want to know, and (ii) I have tried changing the
capstyle to "projecting" etc., but on 1-pixel-wide lines I don't think
this has any effect.
It is as if the line drawing is truncating coordinates rather than
rounding.
Patrick Wallace
____________________________________________________________________________
Space Science & Technology Dept
Rutherford Appleton Laboratory
Chilton, Didcot,
Oxon OX11 0QX, UK
____________________________________________________________________________
End points of the two lines seem to be truncated by one pixel.
Excellent: much better than my long-winded example.
By the way, I found one workaround for my particular application - plot
the line twice, in the two directions.
Patrick Wallace
________________________________________________________________________
pack [canvas .c]
.c create line 10 10 20 30 -capstyle round
.c create line 10 30 20 10 -capstyle round
Geoff.
Hm. Interesting: I had already tried capstyle projecting and that
appeared to do nothing. But capstyle round does make a difference.
There's still an asymmetry, though. Try this:
package require Tk
canvas .c -width 100 -height 100 -bd 0 -highlightt 0
pack .c
set x 50
set y 50
set r 4.9
for {set i 0} {$i < 36} {incr i} {
set t [expr $i*0.174532925]
.c create line $x $y [expr $x+$r*sin($t)] [expr $y+$r*cos($t)] \
-capstyle round
}
Patrick Wallace
_______________________________________________________________________
Copying and pasting your code straight into tclsh gives me symmetric
output. I've grabbed a snapshot and zoomed in to double check.
Geoff.
The results must be dependent on screen resolution and perhaps software
version. I've tried an ancient wish on an Alpha Tru64 system and a
fairly recent tclsh under MS Windows; both give a result that contains a
departure from symmetry of just one pixel, but it's there. And adding the
-capstyle round doesn't fix the character-drawing problem that I started
with.
Patrick Wallace
__________________________________________________________________________
You know that rendering fonts at small sizes is a very advanced art?
Todays outline fonts (like Type1, Truetype, Opentype) build on a complex
magic called "Hinting", which may even be a font program, to do
acceptable scan-conversion on small sizes. Rendering each character
individual by drawing lines will definitely have severe limits.
Read e.g. this:
http://fontforge.sourceforge.net/overview.html#Hints
and for TrueType
http://www.microsoft.com/typography/TrueTypeHintingIntro.mspx
Christian