# The Malevolent Mathemagician | Natural Language Programming

• Difficulty Level : Medium
• Last Updated : 29 Sep, 2022

` `

Now let’s draw some triangles. Here’s a simple 3-4-5 triangle with the center of the screen marked by a red dot… …and this is the routine that drew it:

` `

The critical juncture in this routine occurs after we’ve drawn the 3-inch horizontal line and the 4-inch vertical line. At that point we’re sitting on the uppermost vertex of the triangle, facing north. To get back to the center of the screen we need two things. Mathemagicians would say, “Of course you do. You need to know how far to turn around (an angle) and how long your next stroke should be. But we don’t want to say that, for two reasons: first, because it hurts our heads to figure out exactly what angle we need, and secondly because it can be difficult (or even impossible) to figure out the exact stroke length using mathemagical techniques. “If it’s hard, it’s wrong, ” is a standing motto among us Osmosians. So back to the third stroke of our triangle. Exactly where are we? We’re 4 inches north of center (that’s the rise) and three inches west of center (that’s the run). That’s our exact position. In what direction do we want to go? Obviously, we want to go 4 inches south and 3 inches east, by the shortest possible route. And exactly how far do we want to go? Same answer: 4 inches south and 3 inches east. Isn’t it curious that both the angle of our line and the length of our line can be described in the same, whole-number-only terms? And note that this works, not only for “mathemagician-friendly” 3-4-5 triangles, but for all triangles. So all we need to do is compute the rise and the run, which is simply the difference between two spots on the screen…

` `

…and then we stroke the third line based on that rise/run:

` `

At the very bottom we’ve got Bresenham’s integer-only line drawing algorithm, so we’re not cheating when we plot the lines. So far, so good. Now let’s see if it actually works with that troublesome “unit triangle” — a right triangle with short sides just one unit in length. The routine to draw it is the same as above, except that the first two strokes are only one inch long:

` `

Here’s the output: Whoohoo! It works! And what is the exact length of those sides? Let me see… the first side has a rise of exactly 0 and a run of exactly -1; the second side has a rise of exactly 1 and a run of exactly 0. And the third side  has rise of exactly -1 and a run of exactly 1. All integers, all exact, all easily calculated. But will it work if the triangle is not a right triangle, or is rotated in some arbitrary direction? Let’s see. Here’s a routine that draws eight, scalene triangles at eight different rotations:

` `

And here’s the output: Baby steps toward a more natural, more rational mathematics. BIG baby steps. In Plain English.

My Personal Notes arrow_drop_up