Dataset Viewer (First 5GB)
text
stringlengths 0
603k
|
---|
A note on digitized angles The preparation of this note was supported in part by National Science Foundation grant grant CCR–8610181. |
Donald E. Knuth, Stanford University Abstract. |
We study the configurations of pixels that occur when two digitized straight lines meet each other. |
About ten years ago I was supervising the Ph.D. thesis of Chris Van Wyk, which introduced the IDEAL language for describing pictures. |
Two of his example illustrations showed arrows constructed from straight lines something like this: When I looked at them, I was sure that there must be a bug either in IDEAL or in the TROFF processor that typeset the IDEAL output, because the long shafts of the arrows did not properly bisect the angle made by the two short lines of the arrowheads. |
The shafts seemed to be drawn one pixel too high or too low. |
Chris spent many hours together with Brian Kernighan trying to find out what was wrong, but no errors could be pinned down. |
Eventually his thesis was printed on a high-resolution phototypesetter, and the problem became much less noticeable than it had been on the laser-printed proofs. |
There still was a glitch, but I decided not to hold up Chris’s graduation for the sake of a misplaced pixel. |
I remembered this incident at the end of 1983, when I was getting ready to write a new version of the METAFONT system for digital art. |
I didn’t want my system to have such a flaw. |
But to my surprise, I learned that the problem is actually unavoidable in raster output: It is almost impossible to bisect a digitized angle exactly, except in very special circumstances. |
The two “halves” of the angle will necessarily appear somewhat different from each other, unless the resolution is quite high. |
Therefore Van Wyk (and Kernighan) were vindicated. |
Similar problems are bound to occur in MacDraw and in any other drawing package. |
For example, one of the things I noticed was the following curious fact. |
Consider the EQU angle that is made when a straight line segment of slope 2 comes up to a point EQU and then goes down along another line of slope EQU : If we digitize this angular path, the result will take one of five different shapes, depending on the value of the intersection point EQU, whose coordinates are not necessarily integers. |
The possibilities are If this EQU angle provides the left half of an arrowhead, the right half of the arrowhead will be a EQU angle made by a line of slope EQU meeting a line of slope EQU, For this angle there are, similarly, five possibilities after digitization, namely To complete the arrowhead, we should match the left angle EQU with an appropriate EQU. |
But none of the EQU ’s has the same shape as any of the EQU ’s. |
And this is the point: Human eyes tend to judge the magnitude of an angle by its appearance at the tip. |
By this criterion, some of these angles appear to be quite a bit larger than others (except at high resolutions). |
Hence it is not surprising that a correctly drawn angle of type EQU would appear to be unequal to a correctly drawn angle of type EQU, even though both angles would really be EQU when drawn with infinite resolution. |
(The patterns of white pixels, not black pixels, are the source of the inconsistency.) |
Here, for example, are four quite properly digitized arrows with shafts of increasing thickness: We might also want to know the probability that the digitized shape will be of a particular type EQU, when the corner point EQU is chosen at random in the plane. |
Is one of the patterns more likely to occur than the others? |
The answer is no, when we use the most natural method of digitization; each EQU will be obtained with probability 1/5. |
Similarly, each of the five shapes EQU turns out to be equally likely, as EQU varies. |
The main purpose of this note is to prove that the facts just stated are special cases of a general phenomenon: We assume that EQU and EQU are rational numbers in lowest terms. |
Two digitized shapes are considered to be equal if they are identical after translation; rotation and reflection are not allowed. |
Before we can prove the theorem, we need to define exactly what it means to digitize a curve. |
For this, we follow the general idea explained, for example, in. |
We consider the plane to be tiled with pixels, which are the unit squares whose corners have integer coordinates. |
Our goal is to modify a given curve so that it travels entirely on the boundaries between pixels. |
If the curve is given in parametric form by the function EQU as EQU varies, its digitization is essentially defined by the formula as EQU varies, where round EQU is the integer nearest EQU. |
We need to be careful, of course, when rounding values that are halfway between integers, because round EQU is undefined in such cases. |
Let us assume for convenience that the path EQU does not go through any pixel centers; i.e., that EQU is never equal to EQU for integer EQU and EQU. |
(Exact hits on pixel centers occur with probability zero, so they can be ignored in the theorem we wish to prove. |
An infinitesimal shift of the path can be used to avoid pixel centers in general, therefore avoiding the ambiguities pointed out in Bresenham’s interesting discussion ; but we need not deal with such complications.) |
Under this assumption, whenever we have EQU so that ‘round EQU ’ is ambiguous, the value of round EQU will be unambiguous, and we can include the entire line segment from EQU to EQU in the digitized path. |
Similarly, when EQU reaches a value such that round EQU but round EQU or EQU, we include the entire segment from EQU to EQU. |
This convention defines the desired digitized path, round EQU. |
When the path EQU returns to its starting point or begins and ends at infinity, without intersecting itself, it defines a region in the plane. |
The corresponding digitized path, round EQU, also defines a region; and this digitized region turns out to have a simple characterization, when we apply standard mathematical conventions about “winding numbers”: The pixel with corners at EQU, EQU, EQU, EQU belongs to the digitized region defined by round EQU if and only if its center point EQU belongs to the undigitized region defined by EQU. |
(This beautiful property of digital curves is fairly easy to verify in simple cases, but a rigorous proof is difficult because it relies ultimately on things like the Jordan Curve Theorem. |
The necessary details appear in an appendix to John Hobby’s thesis, Theorem A.4.1.) |
Now we are ready to begin proving the desired result. |
The region defined by an angle at EQU with lines of slopes EQU and EQU can be characterized by the inequalities EQU We may need to reverse the signs, depending on which of the four regions defined by two lines through EQU are assumed to be defined by the given angular path; this can be done by changing EQU to EQU and/or EQU to EQU. |
EQU This region contains the pixel with lower left corner EQU if and only if We can simplify the notation by combining several constants, letting EQU and EQU : Let EQU be the digitized region consisting of all integer pairs EQU satisfying this condition; these are the pixels in the digitized angle corresponding to EQU. |
As noted above, it is safe to assume that the pixel centers do not exactly touch the lines forming the angle; thus we are free to stipulate that EQU and EQU for all pairs of integers EQU. |
However, if equality does occur, we might as well define the digitized region EQU by the general inequalities EQU and EQU, as stated, instead of treating this circumstance as a special case. |
Notice that EQU is equal to EQU ; therefore we can assume that EQU and EQU are integers in the following discussion. |
Another corner point EQU will lead to parameters EQU defining another region EQU in the same way. |
The two regions EQU and EQU have the same shape if and only if one is a translation of the other; i.e., EQU if and only if there exist integers EQU such that Our main goal is to prove that the number of distinct region shapes, according to this notion of equivalence, is exactly EQU. |
Assume that EQU with respect to EQU and EQU, and let EQU be the corresponding translation amounts. |
Thus we have for all integer pairs EQU. |
Let EQU and EQU, so that for all integers EQU. |
This implies that EQU and EQU. |
For if, say, we had EQU, we could find integers EQU and EQU such that EQU and EQU, because EQU and EQU are relatively prime; this would satisfy the inequalities on the left but not on the right. |
(More precisely, we could use Euclid’s algorithm to find integers EQU and EQU such that EQU. |
Then the values EQU would satisfy the left inequalities but not the right, for infinitely many integers EQU, because EQU.) |
Thus EQU implies that EQU and EQU. |
The converse is trivial. |
Let EQU and EQU be integers such that EQU. |
The lemma tells us that EQU ; hence every digitized region EQU has the same shape as some digitized region EQU in which EQU. |
It remains to count the inequivalent regions EQU when EQU is an integer. |
According to the lemma we have EQU if and only if there exist integers EQU with EQU and EQU. |
But EQU if and only if EQU and EQU for some integer EQU ; hence the condition reduces to EQU. |
In other words, EQU if and only if EQU is a multiple of EQU. |
The number of inequivalent regions is therefore EQU, as claimed. |
To complete the proof of the theorem, we must also verify that each of the equivalence classes is equally likely to be the class of the digitized angular region, when the intersection point EQU is chosen at random in the plane. |
The notational change from EQU to EQU maps equal areas into equal areas; so we want to prove that the equivalence class of EQU is uniformly distributed among the EQU possibilities, when the real numbers EQU are chosen at random. |
Choosing real numbers EQU at random leads to uniformly distributed pairs of integers EQU. |
And if EQU has any fixed value and EQU runs through all integers, the equivalence class of EQU runs cyclically through all EQU possibilities. |
A close inspection of this proof shows that we can give explicit formulas for the sets of intersection points EQU that produce equivalent shapes. |
Let EQU and let EQU denote the shape corresponding to region EQU in the proof, where EQU. |
Then the digitized angle will have shape EQU if and only if EQU lies in the parallelogram whose corners are EQU plus or in a parallelogram obtained by shifting this one by an integer amount EQU. |
In the special case EQU and EQU, the shapes EQU are what we called EQU above; in the special case EQU and EQU, the EQU are what we called EQU. |
The shapes that appear in the digitized angles depend on the values of EQU in the unit square, according to the following diagrams: Notice that the parallelograms “wrap around” modulo 1, each taking up an area of 1/5. |
When the slope of either line forming an angle is irrational, the number of possible shapes is infinite (indeed, uncountable). |
But we can still study such digitizations by investigating the shape only in the immediate neighborhood of the intersection point; after all, those pixels are the most critical for human perception. |
For example, exercises 24.7–9 of The METAFONTbook discuss the proper way to adjust the vertices of an equilateral triangle so that it will digitize well. |
The moral of this story, assuming that stories ought to have a moral, is probably this: If you want to bisect an angle in such a way that both halves of the bisected angle are visually equivalent, then the line of bisection should be such that reflections about this line always map pixels into pixels. |
Thus, the bisecting line should be horizontal or vertical or at a EQU diagonal, and it should pass through pixel corners and/or pixel centers. |
Furthermore, your line-rendering algorithm should produce symmetrical results about the line of reflection (see ). |
This subject is clearly ripe for a good deal of further investigation. |
I wish to thank the referees and the editor for their comments. |
In particular, one of the referees suggested the present proof of the theorem; my original version was much more complicated. |
Bibliography Jack E. Bresenham, “Ambiguities in incremental line rastering,” IEEE Computer Graphics and Applications 7, 5 (May 1987), 31–43. |
John Douglas Hobby, Digitized brush trajectories. |
Ph.D. thesis, Stanford University, April 1985. |
Also published as report STAN-CS-85-1070. |
Donald E. Knuth, The METAFONTbook, Volume C of Computers & Typesetting, (Reading, Mass. |
: Addison–Wesley, 1986). |
Christopher John Van Wyk, A language for typesetting graphics. |
Ph.D. thesis, Stanford University, June 1980. |
Also published as report STAN- CS-80-803. |
The “arrow” illustrations that prompted this research appear on page 20. |
Christopher J. |
Van Wyk, “A graphics typesetting language,” SIGPLAN Notices 16, 6 (June 1981), 99–107. |
REMARKS ON ITERATED CUBIC MAPS John Milnor This note will discuss the dynamics of iterated cubic maps from the real or complex line to itself, and will describe the geography of the parameter space for such maps. |
End of preview. Expand
in Data Studio
No dataset card yet
- Downloads last month
- 72