![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFRMPjK_DB-W-OP8GeBfYs_TEnW0N48l9W5c9qi4Md5V9tYEF23HOfVTucdInMw4HuT4TQ5tt3p4o3IZdZMIW3PKa2QOSeMxl1ROs6G0ibCCnk28VytXtiSu2b1yzmL1H8Q84Uc9XZX-s/s200/CompassSmall.jpg)
Pixels and points are two ways of looking at the plane. But both of them involve a two-dimensional address system, and the two dimensions are usually called X and Y, but sometimes also columns and rows.
We see here a right-handed coordinate system. On the compass, the X-axis points east and the Y-axis points north. In the center is the origin, the point where X and Y are both zero. We like to write a coordinate as an ordered pair, in this case (0, 0). The axes also split the plane into four quadrants (shown in color and with their conventional Roman numerals).
If you are working in columns and rows instead of X and Y, then you are actually using a left-handed coordinate system, because larger rows are below the smaller ones, and so the direction of increasing rows points south. Pixels in an image are usually laid out in rows and columns.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1ahLwBc8r_Vjg1GXDEukNZBWTu5z5M5HHGL0-2N6A1ys_OxWnthk4P_9uACJ-CLH8OMY2mGNbZwVqafTMq-XHaGbA8U2kPQ-SpyEufGLRc4cNnMOUeEfe8cihm6_FX3W5NkThnfkWgXg/s200/Pixels.jpg)
Vegments and Sectors
Wait, I meant segments and vectors (I'm just trying to confuse you with doubletalk, hee hee)! Join two points with a small straight line and you get a segment. If you join two points in the same way, but the join actually has a direction, then you have a vector. Segments and vectors may be measured and quantified in different ways. And each has their own use.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhi8uFmfCZy1zVfle0m7zckfLU8K_T0-1XDO5GGhTvTWtS-ALI5ZJ9hCfTZBhdZQA_dWSzVxVlklC7Pxr0GbEfB8e2SyrU5ODELYXSBKgNyrHQU2yIzHM8ZqKMle9V1ZheS4kYshO1MTr0/s1600/OneSegmentSmall.jpg)
Segments may be chained end-to-end to create polygons. Most commonly, a polygon is closed, in which case it has an inside and an outside. You can compute a closed polygon's area also. More (much more!) on this later.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGC3w_LYM2cMHFFpy3LXffrH-obkvlsfLh2GAISV0D48_kOIsXDGGzTnotsJ1X_YsW1JfiHIDCTxyxu3MQNAKQ2E0gI5r95zBYls-d1ucEoL4h_libyRkOwrQLpHzMNzYLePybwxdsarA/s1600/OneVectorSmall.jpg)
A vector's measure starts by computing the X and Y deltas that make it up. Once you perform the subtraction, any notion of being rooted in the plane goes away. Why? This is intuitively true because you subtract away the start point of the vector, removing its home base.
Length and Stuff (No, It Isn't Spelled Lenght! Grrr!)
Simple subtraction creates the vector, as you can see. This is why a vector is oriented. A vector from P3 to P4 is quite different from the vector from P4 to P3. In fact, it is the negative of it. Or inverse.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhX_JpyS_-wCthkEpY7ExLl-qQRUePuAH-EtTGHz57wka57qkgu3y481W5CIr_DoIkvJxnbQLeJ3UAf2Xpm2nqbjDv9Lb5gEmR7C3qqNuuJ9tg0AwDcTulpa0gAozt196V5uHronDfuS8w/s200/OneVectorSmall.jpg)
So here is the easy way to compute the length of a segment. You move the "right angle" of the imaginary right triangle (kind of shown shaded in a very light peach color) directly to the origin. This translation is effectively performing a subtraction, in this case, of the lesser of the two X's, which happens to be X4, from the two points, and also a subtraction of the lesser of the two Y's, Y3, from the two points. Anyway, the base and height of the right triangle are now known, so we may compute its hypotenuse length using Pythagoras' rule.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuQovb6QcVy5OTzyqcr6JXkSeTquGSs_cTsHJKPfgp8HCn25dcqzpOTiv4Ed6TJmQwku7Cn3TYKjdBWWgeyl_RmwGFH45W0eu_MidVMfp9Si_YPgkrSTSAwI46BOpUkg3errGcPtxdxzM/s200/VectorLength.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtxrI6rBU0beQDHbwZo70H4gZLPzki7xuD8UjAOkJKV_ai36qqvVvgl3h_mvzjv9oGNxI4Ha5Ce6ClsMvmLSS8CEd-3hDlWso0fugmxq0LQOE7dtyo5OgfuqKlPQOxzOQuEsyY3iQ_hIU/s1600/Length.jpg)
OMG Do I Have To Know This Stuff?!?
If you already know about all the kinds of numbers, then you can skip this section. However, just bear in mind that I had to know about all these things before I could develop Painter! And now it's your turn! Waahahahahaa!
There are various kinds of numbers that it is useful to know. The integers are the whole numbers, zero, and their negatives. On a computer, there may be a smallest integer and a largest integer. That is what we like to call an implementation detail in the business. If you need more accuracy, you might want to use a real number. Real numbers can represent the integers, and all the numbers in between as well, like 9.57212947621.... On computers, these are represented by things called floats and doubles. These have various numbers of bits of accuracy.
When you divide one integer by another integer, you get a rational number (but please don't divide by zero!). There is really quite a spectrum of numbers that can be represented by rational numbers, called a Markov spectrum (but I digress). On a computer, real numbers can't really represent all rational numbers with 100% accuracy. For instance, you can represent 123/128 exactly, but 1/3 is hopeless to represent accurately. This turns out to be true because computers use power-of-two (binary) representations, and 128 just happens to be two to the seventh power.
Some numbers can't be represented exactly as a rational number or by floats and doubles on the computer. One example of these is an algebraic number: a number that is the root of some polynomial with integer coefficients, like the square root of two. If a segment has its endpoints at points whose X and Y are integers, then the segment's length is an algebraic number.
Another example is a transcendental number. Such a number can't be represented as an algebraic number or a rational number. Well, pi and e, the base of natural logarithms, are two examples of transcendental numbers.
OK, computers really only approximate these, but it's good enough for government work.
Back to the Vector
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisJDQiDtxSMxwDB-NJ8ZtlK2AUAidHEJZ7KUF57fU0Pd0KarbbnNBwZVvN8VUJvHzZXeBHhfOEA-D6otWL72pAhXd7zPTug3w2GIHkXe8qB7DVrHoQQ_nU6cJX_C0USVaW1WoATQwhvyc/s1600/VectorAngleSmall.jpg)
Pi, by the way, is the magic ratio of the circumference of a circle to its diameter. It has a value of about 3.14159.... Yes, I memorized pi to 100 places and I used to recite it. Jeez, was I a geek!
But radians are a pure mathematical way of looking at things. Using radians instead of degrees saves you a multiply each time you do a trig function. Uh-oh. Trig functions!
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTtzM28rmkZSTdV-RUKnv03ATUOMSOr3FkoDHhJVoBS-aShT3DMKMQx0H5aOg9PIXSM5Csuq4uHOpZVvMb3yYhp2Pz4k3iwu-uf8Qaed0ebtV74APR-cRMxxs6tIIMBbN7ZYXPMn5BWCw/s1600/VectorTrigSmall.jpg)
I remember when I was introduced to this fact. It was, to me, an "aha" moment. Now I understood why trigonometry was important! Actually, a few things fell into place that day in 1974. I ended up using it later on a test given to me by Joe Sukonick, a clever programmer at Calma Company. That bearded MIT graduate fellow ended up with a patent on the XOR for cursors in raster systems, by the way. But it was another guy at Calma, Tom Schaefer, that taught me some really useful things about analytic geometry. Without this information, it would have been seriously difficult to create Painter, or build the mosaic brush. Or really anything I do today.
What's Dot?
At Calma, segments definitely got connected end-to-end to create polygons. Calma built very good CAD (computer-aided design) systems for the very first VLSI (very large scale integration) components. In other words, microchips like the Motorola 68000 were designed on our systems. Yep, the original Macintosh's CPU.
I remember thinking about the notion of concave and convex and clockwise and counterclockwise. How could I determine these attributes for a polygon? It seemed like concavity was a local thing, and could be determined by looking at three consecutive points. But clockwise and counterclockwise were much more complicated, and were clearly a global thing. Or were they?
So there I was at the tender age of 19 at Calma, thinking abstractly about analytic geometry. It turns out I was smart enough and up to the challenge!
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1nQIqo4xIj4dxuVpr7p1WaWHyPN8BykkEs8jLnrYOD0cyY65tIPJH4m97CjeD8b3u5ErO6NUw6cUUVDOLBIlAevIRsVRFn9LvJ7KWzyvrwa8D2XvZHxJ7-OUEOMMHlWsvBiffyF7h4FQ/s1600/PointsVectors.jpg)
First there were three points, P1, P2, and P3. You could subtract the points' X's and Y's to make two vectors, V1 and V2.
But note that, the two vectors, if rooted at the same origin, created an angle between them, called theta. The angle is measured in counterclockwise degrees (or radians!).
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilrFRBcUmV2BA74SrDFW9k3lxZFF2c8Ra48xvb9e8jURRCjCgFp4K2KjMuO25dslFTE2v2DuLB3PQkKOpTl3-g7rVuUf0-Z01PFcLVEVnsfpclNDl7qTIe3r-oxaU42oj11E-SlgNqny4/s1600/TwoOperators.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgECnInLT_6xF2_5lnizNvNIuUHIVoLPWQNWP9azffWKmux86Hxk9ZkcF59rqVG_KgIb70f6hGLD5Q-GgdLopacpXjzoocH1YEtPB0yI1TXe7fi849E3Y_6hlscYtJMmMf3Uf7E1yVoogs/s1600/TrigOperators.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSswP1mmOSIGHE7i8HuxtcvSIPcO6ZXVpeACrX9tDxCGS02QGhQtfet6ncQAfLhDbr2XHGjiwMdTXmnbctLgaNa4X1yv33YaIu0tK26smguYCTqJE-_zAxWsXEXiWyBHt3L08WFhFf9Sc/s1600/LeftRight.jpg)
OMG I thought this was incredibly clever. With this one operation, I could decide if a polygon is concave or convex, and even whether to not a polygon was clockwise or counterclockwise (as long is it's not self-intersecting).
But, of course, my brain was thinking several steps ahead.
It also occurred to me that, if V1 and V2 were unit vectors, that the dot and codot operators would simply produce the cosine and the sine of theta directly. In fact, I could see now that the rule about a vector's angle was simply a special case of this.
The dot product, it turned out, was useful in determining whether the two vectors were pointing in the same basic direction (if the dot is positive) or the opposite direction (if the dot is negative). And, by the way, if the dot product is zero, then the two vectors are at right angles to each other (perpendicular).
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTa5qS4kMJPnxzc_5bCfh8_zemr8sr9yWMI720E4WhSmUMAIywdHdfSaWBon2V8ccR__0V1V5UmTx0aoGFo9QeEOzm182wTkciyLBYl1RbGYZxgXsmKf7RorpWn1GwoErJ08NARyETWdk/s280/Area.jpg)
Polygons are a connected and closed chain of points in the plane. Between any two neighboring points is a segment. So, how do we compute the area of a polygon? Well, we make use of a clever technique called the trapezoidal rule. If a polygon is clockwise, then we just have to make trapezoids from each segment by dropping lines to the Y axis as we see in this diagram. Note that, on the bottom of the polygon, when the segments are going in the other direction, then the trapezoid areas become negative, because the X terms are going from right-to-left instead of from left-to-right as they are here. And that makes polygon area work by first computing the integral under the top of the polygon and subtracting the integral below the bottom of the polygon.
This has an interesting side effect. The clockwise polygons have a positive area and the counterclockwise polygons have a negative area.
So, really, to get the area, we have to take the absolute value of the computed area. And the sign is the orientation of the polygon. This turns out to be a very convenient way to compute polygon area! Once you see it, you will wonder how it can be so simple.
This turned out to be a question on Joe Sukonick's aptitude test at Calma. I took that test, and I got it right. But another guy, Bruce Holloway, got the job. Because, I was going to college at Caltech. The very next spring, when in Chemistry lab at Caltech, I got a call from Art Collmeyer. He saw the test and decided I might be interested in a summer job at Calma. It's good he called. I met Tom Hedges at Calma.
Oh, and by the way, the lobster bisque at Hula's Grille in Santa Cruz is excellent!
No comments:
Post a Comment