Mathematics and Digital Art: Update 1 (Fall 2017)

About a month has passed since beginning my third semester of Mathematics and Digital Art!  As with last semester, I plan on giving updates about once a month to discuss changes in the course and to showcase student work.

The main difference this semester (as I discussed a few weeks ago) was starting with Processing right from the beginning.  From my perspective, the course has run more smoothly than ever — and some of my students are already really getting into the coding aspect of creating digital art.

I do believe that beginning this way will pay off when we get to making movies.  Since we’ll already know the basics and understand the difference between user space and screen space, I can focus more on the interactive abilities of Processing — such as having features of the displayed image change by moving the mouse or pressing different keys on the keyboard.

The first two assignments were essentially the same as last semester.  We began with discussing color and the work of Josef Albers, emphasizing the fact that there is no such thing as “pure color” — colors are only perceived in relation to other colors.

Again, I was surprised by the diversity of the images students created.  Like last year, a few students experimented with a minimalist approach.  Here is what Alex generated using just a 2-by-2 grid of squares.

Day112Alex

I should point out that outlining the geometrical objects (using the strokeWeight function) is not “pure” Albers — you aren’t really seeing one color on top of another due to the black outlines.  But I did have students submit three pieces, insisting that one of the pieces was created only by changing the parameters in the original Albers routine, as shown in the following submission.

Day112Linh2

Here is Courtney’s submission on this theme, again created only by changing parameters to the drawing routine.

Day112Courtney

 

Most students — I think in part due to the fact that we started discussing code even earlier than previous semesters — really pushed the geometry far beyond the simple idea of rectangles within rectangles.

While toying with various geometrical motifs, Tera found something that reminded her of a rose.  This influenced her color palette:  reds and pinks for the flowers, with a green background, meant to suggest that the flowers were in a garden.

Day112Tera

Cissy explored the geometry as well.  Note how keeping the stroke weight at zero — so that the geometrical objects have no outline — creates a more subtle effect, especially since the randomness from the dominant color is not too pronounced.

Day112Cissy

The second art assignment, as in the previous semesters, was to explore creating textures using randomness in both color and shape.  As with the first assignment, I wanted students to submit one piece which involved only changing the parameters to a given function.  In this case, the function created a grid of gray circles, with both the intensity of the gray and the size of the circles having some degree of randomness.  I think it is important that students do some work within given constraints — it really challenges their creativity.  Here is Terry’s piece along these lines.

Day112Terry

 

The second piece was based on a function which created a grid of squares of the same size, but random colors.  Here, there were no constraints — students could modify the geometry in any way they wanted to.  Several were quite creative.  For example, Sepid approached this task by choosing both shape and color to create an image reminiscent of a stained glass window.

Day112Sepid

The third piece involved a color gradient (see my previous posts on Evaporation).  If you look back at these posts, you’ll recall that a color gradient can be created by increasing the randomness of the colors as you move from the top of the image to the bottom using a power function:  f(y)=y corresponds to a linear gradient, f(y)=y^2 corresponds to a quadratic gradient, etc.  Different effects can be created by varying the exponent.

As I was discussing this in class, one student asked what would happen if you used a negative exponent.  I had never thought about this before!  Jack used this idea in his piece, which he said reminds him of looking at a fire.

Day112Jack

It turns out that using a negative exponent creates a gradient beginning with black on the top.  Why is this?  As the image proceeds lower down the screen, the algorithm subtracts values from the RGB parameters proportional to y^n, where y=0 corresponds to the top of the image, and y=1 corresponds to the bottom of the image.

So if the exponent n is positive, there is very little randomness subtracted.  But if the exponent is negative, a lot of randomness is subtracted, since now the numbers near 0 are on the denominator.  Because the RGB values only go up to 255, subtracting a large degree of randomness leaves nothing left — in other words, black.  Now some of the numbers will end up being negative  near the top– but putting all negative numbers in a color specification in Processing does in fact give you black.

Another student also worked with yellows and reds to imitate fire in another way.  Instead of making small circles, he made larger circles with quite a bit of overlap, creating a rather different effect.

Day112Ali.png

And Rosalie found in interesting say to create stripes with the algorithm.  I had not seen this effect before.

Day112Rosalie

So that’s it for the first update of the Fall 2017 installment of Mathematics and Digital Art.  As you can see, my students are already being quite creative.  I look forward to seeing their work develop as the semester progresses!

 

Using Processing for the First Time

While I have discussed how to code in Processing in several previous posts, I realized I have not written about getting Processing working on your own computer.  Naturally I tell students how to do this in my Mathematics and Digital Art course.  But now that I have started a Digital Art Club at the University of San Francisco, it’s worth having the instructions readily accessible.

The file I will discuss may be used to create an image based on the work of Josef Albers, as shown below.

0001

See Day002 of my blog,  Josef Albers and Interaction of Color, for more about how color is used in creating this piece.

As you would expect, the first step is to download Processing.  You can do that here.  It may take a few moments, so be patient.

The default language used in Processing is Java.  I won’t go into details of why I’m not a fan of Java — so I use Python mode.  When you open Processing, you’ll see a blank document like this:

Day110Screen1

Note the “Java” in the upper right corner.  Click on that button, and you should see a menu with the option “Add Mode…”  Select this option, and then you should see a variety of choices — select the one for Python and click “Install.”  This will definitely take a few minutes to download, so again, be patient.

Now you’re ready to go!  Next, find some Processing code written in Python (from my website, or any other example you want to play around with).  For convenience, here is the one I’ll be talking about today:  Day03JosefAlbers.pyde.  Note that it is an Open Office document; WordPress doesn’t let you upload a .pyde file.  So just open this document, copy, and paste into the blank sketch.  Be aware that indentation is important in Python, since it separates blocks of code.  When I copied and pasted the code from the Open Office document, it worked just fine.  But in case something goes awry, I always use four spaces for successive indents.

Now run the sketch (the button with the triangle pointing to the right).  You will be asked to create a new folder; just say yes.  When Processing runs, it often creates additional files (as we’ll see in a moment), and so keeping them all in one folder is helpful.  You should also see the image I showed above; that is the default image created by this Processing program.

Incidentally, the button with the square in the middle stops running your sketch.  Sometimes Processing runs into a glitch or crashes, so stopping and restarting your sketch is sometimes necessary.  (I still haven’t figured out why it crashes at random times.)

Next, go to the folder that you just created.  You should see a directory called “frames.”  Inside, you should see some copies of the image.

Day110Screen2

Inside the “draw” function, there is a function call to “saveFrame,” which saves copies of the frames you make.  You can call the folder whatever you want; this is convenient, since you might want to make two different images with the same program.  Just change the folder name you save the images to.

A word about the syntax.  The “####” means the frames will be numbered with four digits, as in 0001.png, 0002.png, etc.  If you need more than 10,000 frames (likely you won’t when first starting), just add more hashtags.  The “.png” is the type of file.  You can use “.tif” as well.  I use “.tif” for making movies, and “.png” for making animated gifs.  There are other file types as well; see the documentation on saveFrame for more details.

Now let’s take a look at making your own image using this program.

Day110Screen3

If you notice, there are lines labelled “CHANGE 1” to “CHANGE 6” in the setup and draw functions.  These are the only lines you need to change in order to design you own piece. You may tweak the other code later if you like.  But especially for beginning programmers, I like to make the first examples very user-friendly.

So let me talk you through changing these lines.  I won’t bother talking about the other code right now — that would take some time!  But you don’t need to know what’s under the engine in order to create some interesting artwork….

CHANGE 1:  The hashtags here, by the way, indicate a comment in your code:  when your program runs, anything after a hashtag is ignored.  This makes it easy to give hints and provide instructions in a program (like telling you what lines to change).  I created a window 800 x 600 pixels; you can make it any size you want by changing those numbers. The “P2D” just means you’re working with a two-dimensional geometry.  You can work in 3D in Processing, but we won’t discuss that today.

CHANGE 2:  The “sqSide” variable indicates how big the square are, in units of pixels.  The default unit in Processing is always pixels, so if you want to use another geometry (like a Cartesian coordinate system), you have to convert from one coordinate system to another.  I do all this for you in the code; all you need to do is say how large each square is.  And if you didn’t go back and read the Josef Albers piece, by “square,” I mean a unit like this:

Day002Square

CHANGE 3, CHANGE 4:  The variables “sqRows” and “sqCols” indicate, as you would expect, how many rows and columns are in the final image.  Since I have 15 rows and the squares are 30 pixels on a side, the height of the image is 450 pixels.  Since my window is 600 pixels in height, this means there are margins of 75 pixels on the top and bottom.  If your image is too tall (or too wide) for the screen, it will be cropped to fit the screen.  Processing will not automatically resize — once you set the size of the screen, it’s fixed.

CHANGE 5:  The “background” function call sets the color of the background, using the usual RGB values from 0-255.

CHANGE 6:  The first three numbers are the RGB values of the central rectangles in a square unit.  The next three numbers indicate how the background colors of the surrounding rectangles change.  (I won’t go into that here, since I explain it in detail in the post on Josef Albers mentioned above.  The only difference is that in that post, I use RGB values from 0-1, but in the Processing code here, I use values from 0-255.  The underlying concept is the same.)

The last (and seventh) number is the random number seed.  Why is this important?  If you don’t say what the random number seed is (the code does involve choosing random numbers), every time you run the code you will get a different image — the computer just keeps generating more (and different) random numbers in a sequence.  So if you find an image you really like and don’t know what the seed is, you’ll likely never be able to reproduce it again!  And if you don’t quite like the texture created by using one random seed, you can try another.  It doesn’t matter so much if you have many rows and columns, but if you try a more minimalist approach with fewer and larger squares, the random number seed makes a big difference.

OK, now you’re on your own….  This should be enough to get you started, and will hopefully inspire you to learn a lot more about Python and Processing!

 

 

To Processing I

I made a decision last week to abandon using Sage (now called CoCalc) as a platform in my Mathematics and Digital Art class.  It was not an easy decision to make, as there are some nice features (which I’ll get to in a moment).  But now any effective use of Sage comes with a cost — the free version uses servers, and you are given this pleasant message:  “This project runs on a free server (which may be unavailable during peak hours)….”

This means that to guarantee access to CoCalc, you need a subscription.  It would not be prohibitively expensive for my class — but as I am committed to being open source, I am reluctant to continue putting sample code on my web page which requires a cost in order to use.  Yes, there is the free version — as long as the server is available….

When I asked my students last semester about moving exclusively to Processing, they responded with comments to the effect that using Sage was a gentle introduction to coding, and that I should stick with it.  I fully intended to do this, and got started preparing for the first few days of classes.  I opened my Sage worksheet, and waited for it to load.  And waited….

That’s when I began thinking — I did have experiences last year where the class virtually came to a halt because Sage was too slow.  It’s a problem I no longer wanted to have.

So now I’m going to Processing right from the beginning.  But why was I reluctant in the past?

The issue is that of user space versus screen space.  (See Making Movies with Processing I for a discussion of these concepts.)  With Sage, students could work in user space — the usual Cartesian coordinate system.  And the programming was particularly easy, since to create geometrical objects, all you needed to do was specify the vertices of a polygon.

I felt this issue was important.  Recall the success I felt students achieved by being able to alter the geometry of the rectangles in the assignment about Josef Albers and color.  (See the post on Josef Albers and Interaction of Color for a refresher on the Albers assignment.)

peyton
Peyton’s piece on Josef Albers.

Most students experimented significantly with the geometry, so I wanted to make that feature readily accessible.  It was easy in Sage, the essential code looking something like this:

Screen Shot 2017-08-26 at 11.08.35 AM

What is happening here is that the base piece is essentially an array of rectangles within unit squares, with lower-left corners of the squares at coordinates (i, j).  So it was easy for students to alter the polygons rendered by using graph paper to sketch some other polygon, approximate its coordinates, and then enter these coordinates into the nested loops.

Then Sage rendered whatever image you created on the screen, automatically sizing the image for you.

But here is the problem:  Processing doesn’t render images this way.  When you specify a polygon, the coordinates must be in screen space, whose units are pixels.  The pedagogical issue is this:  jumping into screen space right at the beginning of the semester, when we’re just learning about colors and hex codes, is just too big a leap.  I want the first assignment to focus on getting used to coding and thinking about color, not changing coordinate systems.

Moreover, creating polygons in Processing involves methods — object-oriented programming.  Another leap for students brand new to coding.

The solution?  I had to create a function in Processing which essentially mimicked the “polygon” function used in Sage.  In addition, I wanted to make the editing process easy for my students, since they needed to input more information this time.

Day108pyde1

In Processing — in addition to the number or rows and columns — students must specify the screen size and the length of the sides of the squares, both in pixels.  The margins — xoffset and yoffset — are automatically calculated.

Here is the structure of the revised nested for loops:

Day108pyde2

Of course there are many more function calls in the loops — stroke weights, additional fill colors and polygons, etc.  But it looks very similar to the loop formerly written in Sage — even a bit simpler, since I moved the translations to arguments (instead of needing to include them in each vertex coordinate) and moved all the output routines to the “myshape” function.

Again, the reason for this is that creating arbitrary shapes involves object-oriented concepts.  See this Processing documentation page for more details.

Here is what the myshape function looks like:

Day108pyde3

The structure is not complicated.  Start by invoking “createShape,” and then use the “beginShape” method.  Adding vertices to a shape involves using the “vertex” method, once for each vertex.  This seems a bit cumbersome to me; I am new to using shapes in Processing, so I’m hoping to learn more.  I had been able to get by with just creating points, lines, rectangles, and circles so far — but that doesn’t give students as much room to be creative as including arbitrary shapes does.

I should point out that shapes can have subshapes (children) and other various attributes.  There is also a “fill” method for shapes, but I have students use the fill function call in the for loop to avoid having too many arguments to myshape.  I also think it helps in understanding the logical structure of Processing — the order in which functions calls are invoked matters.  So you first set your fill color, then when you specify the vertices of your polygon, the most recently defined fill color is used.  That subtlety would get lost if I absorbed the fill into the myshape function.

As in previous semesters, I’ll let you know how it goes!  Like last semester, I’ll give updates approximately monthly, since the content was specified in detail in the first semester of the course (see Section L. of 100 Posts! for a complete listing of posts about the Mathematics and Digital Art course).

Throughout the semester, I’ll be continuously moving code from Sage to Processing.  It might not always warrant a post, but if I come across something interesting, I’ll certainly let you know!

On Coding XI: Computer Graphics III, POV-Ray

It has been a while since the last installment of On Coding.  I realized there is still more to say about computer graphics; I mentioned the graphics package POV-Ray briefly in On Coding IX, but feel it deserves much more than just a mere mention.

I’d say I began using POV-Ray in the late 1990’s, though I can’t be more precise.  This is one of the first images I recall creating, and the comments in the file reveal its creation date to be 19 September 1997.

petrie

Not very sophisticated, but I was just trying to get POV-Ray to work, as I (very vaguely) remember.  Since then, I’ve created some more polished images, like the polyhedron shown below.  I’ll talk more about polyhedra in a moment….

XT-18-19-28

First, a very brief introduction.  POV-Ray stands for Persistence of Vision Raytracer.  Ray tracing is a technique used in computer graphics to create amazingly realistic images.  Essentially, the color of each pixel in the image is determined by sending an imaginary light ray from a viewing source (the camera in the image below) and seeing where it ends up in the scene.

800px-Ray_trace_diagram.svg
Image by Henrik, Wikipedia Commons.

It is possible to create various effects by using different light sources, having objects reflect light, etc.  You are welcome to read the Wikipedia page on ray tracing for more details on how ray tracing actually works; my emphasis here will be on the code (of course!) I wrote to create various three-dimensional images.  And while the images you can produce using a ray tracing program are quite stunning at times, there is a trade-off: it takes longer to generate images because the color of each pixel in the image must be individually calculated.  But I do think the results are worth the wait!

My interest in POV-Ray stemmed from wanting to render polyhedra.  The images I found online indicated that you could create images substantially more sophisticated than those created with Mathematica.  And better yet, POV-Ray was (and still is!) open source.  That means all I needed to do was download the program, and start coding….

R_3-5_Dual

POV-Ray is a procedural programming language all in itself.  So to give you an idea of what a typical program looks like, I’ll show you the code which makes the following polyhedron:

tRp_52-3-5

Here’s how it begins.

POV4

The #include directive indicates that the given file is to be imported.  POV-Ray has many predefined colors and literally hundreds of different textures:  glass, wood, stone, gold and other metals, etc.  You just include those files you actually need.  To give you an idea, here is the logo I created for Dodecahedron Day using  silver and stone textures.

logo3

Next are the global settings.  There are actually many global settings which do a lot more than I actually understand…but I just used the two which were included in the file I modeled my code after.  Of course you can play with all the different settings (there is extensive online documentation) and see what effects they have on your final image, but I didn’t feel the need to.  I was getting results I liked, so I didn’t go any further down this path.

Then you set the camera.  This is fairly self-explanatory — position the camera in space, point it, and set the viewing angle.  A fair bit of tweaking is necessary here.  Because of way the image is rendered, you can’t zoom in, rotate, or otherwise interact with the created image.  So there is a bit of trial-and-error in these settings.

Lighting comes next.  You can use point light sources in any color, or have grids of light sources.  The online documentation suggested the area lighting here (a 5-by-5 grid of lights spanning 5 units on the x-axis and 5 units on the z-axis), and it worked well for me.  Since I wanted the contrast of the colors of the faces of the polyhedra on a black background, I needed a little more light than just a single point source.  You can read all about the “adaptive” and “jitter” parameters here, but I just used the defaults suggested in the documentation and my images came out fine.

There are spotlights and cylindrical lighting sources as well, and all may be given various parameters.  Lighting in Mathematica is quite a bit simpler with fewer options, so lighting was one of the most challenging features of POV-Ray to learn how to use effectively.

So that’s the basic setup.  Now for the geometry!  I can’t go into all the details here, but I can give you the gist of how I proceeded.

POV2

The nested while loops produce the 60 yellow faces of the polyhedron.  Because of the high icosahedral symmetry of the polyhedron, once you specify one yellow face, you can use matrices to move that face around and get the 59 others.

To get the 60 matrices, you can take each of 12 matrices representing the symmetries of a tetrahedron (tetra[Count]), and multiply each by the five matrices representing the rotations around the vertices of an icosahedron (fiverot[Count2]).  There is a lot of linear algebra going on here; the matrices are defined in the file “Mico.inc”, which is included.

The vertices of the yellow faces are given in “VF[16]”, where the “VF” stands for “vertex figure.”  These vertex figures are imported from the file “VFico.inc”.  Lots of geometry going on here, but what’s important is this:  the polygon with vertices listed in VF[16] is successively transformed by two symmetry matrices, and then the result is defined to be an “object” in our scene.  So the nested loops place 60 objects (yellow triangles) in the scene.  The red pentagrams are created similarly.

POV3

Finally, the glass tabletop!  I wanted the effect to be subtle, and found that the built-in texture “T_Glass2” did the trick — I created a square (note the first and last vertices are the same; a quirk of POV-Ray) of glass for the polyhedron to sit on.

POV-Ray does the rest!  The overall idea is this:  put whatever objects you want in a scene.  Then set up your camera, adjust the lighting, and let POV-Ray render the resulting image.

petrie10

Of course this introduction is necessarily brief — I just wanted to give you the flavor of coding with POV-Ray.  There are lots of examples online and within the documentation, so it should not be too difficult to get started if you want to experiment yourself!

Still more on: What is…Inversive Geometry?

Now for the final post on inversive geometry!  I’ve been generating some fascinating images, and I’d like to share a bit about how I make them.

2017-07-19Inversion3v2.png

In order to create such images in Mathematica, you need to go beyond the geometrical definition of inversion and use coordinate geometry.  Let’s take a moment to see how to do this.

Recall that P′, the inverse point of P, is that point on a ray drawn from the origin through P such that

[OP]\cdot[OP']=1,

where [AB] denotes the distance from A to B.  Feel free to reread the previous two posts on inversive geometry for a refresher (here are links to the first post and the second post).

Now suppose that the point P has Cartesian coordinates (x,y).  Points on a ray drawn from the origin through P will then have coordinates (kx, ky), where k>0.  Thus, we just need to find the right k so that the point P'=(kx,ky) satisfies the definition of an inverse point.

This is just a matter of a little algebra; the result is

P'=\left(\dfrac{x}{x^2+y^2},\dfrac{y}{x^2+y^2}\right).

What this means is that if you have an equation of a curve in terms of x and y, if you substitute x/(x^2+y^2) everywhere you see x, and substitute y/(x^2+y^2) everywhere you see y, you’ll get an equation for the inverse curve.

Let’s illustrate with a simple example — in general, the computer will be doing all the work, so we won’t need to actually do the algebra in practice.  We’ll look at the line x=1.  From our previous work, we know that the inverse curve must be a circle going through the origin.

Making the substitution just discussed, we get the equation

\dfrac x{x^2+y^2}=1,

which may be written (after completing the square) in the form

\left(x-\dfrac12\right)^2+y^2=\dfrac14.

It is not hard to see that this is in fact a circle which passes through the point (0,0).

Now we need to add one more step.  In the definition of an inverse point, we had the point O being the origin with coordinates (0,0).  What if O were some other point, say with coordinates (a,b)?

Let’s proceed incrementally.  Beginning with a point (x,y), translate to the point (x-a,y-b) so that the point (a,b) now acts like the origin.  Now use the previous formula to invert:

\left(\dfrac{x-a}{(x-a)^2+(y-b)^2},\dfrac{y-b}{(x-a)^2+(y-b)^2}\right).

Finally, translate back:

\left(a+\dfrac{x-a}{(x-a)^2+(y-b)^2},b+\dfrac{y-b}{(x-a)^2+(y-b)^2}\right).

This is now the inverse of the point (x,y) about the point (a,b).

So what you see in the above image is several copies of the parabola y=x^2 inverted about a series of equally spaced points along the line segment with endpoints (1/2,-1/2) and (3/2,1/2).  This might seem a little arbitrary, but it takes quite a bit of experimentation to find a set of points to invert about in order to create an aesthetically pleasing image.

Of course there is another perspective on accomplishing the same task — just shift the parabolas first, invert about the origin, and then shift back.  This is geometrically equivalent (and the algebra is the same); it just depends on how you want to look at it.

Here is another image creating by inverting the parabola y=x^2 about points which lie on a circle.

2017-07-18Inversion1v2

And while we’re on the subject of inverting parabolas, let’s take a moment to discuss the cardioid example we looked at in our last conversation about inversion:

Cardioid2

To prove that this construction of circles actually yields a cardioid, the trick is to take the inverse of a parabola about its focus.  If you do this, the tangent lines of the parabola will then invert to circles tangent to a cardioid.  I won’t go into all the details here, but I’ll outline how the proof goes using the following diagram.

Day104ParabolaProperty

Draw a line (shown in black) tangent to the blue parabola at its vertex; the inverse curves are shown in the same color, but dashed.  Note that the black circle must be tangent to the blue cardioid since the inverse black line is tangent to the inverse parabola.

The small red disk is the focus of the parabola.  Key to the proof is the property of the parabola that if you draw a line from the focus to a point on the black line and then bounce off at a right angle (the red lines), the resulting line is tangent to the parabola.  So the inverse of this line — the red dashed circle — must be tangent to the cardioid.

Since perpendicularity is preserved and the line from the focus inverts to itself (since we’re inverting about the focus), the red circle must be perpendicular to this line — meaning that the line from the focus in fact contains a diameter, and hence the center, of the red circle.  Then using properties of circles, you can show that all centers of circles formed in this way lie on a circle (shown dotted in purple) which is half the size of the black circle.  I’ll leave the details to you….

Finally, I’d like to show a few examples of using the other conic sections.  Here is an image with 80 inversions of an ellipse around centers which lie on a line segment.

2017-07-22Inversion1v2

And here is an example of 100 hyperbolas inverted around centers which lie on a line segment.  Since the tails of the branches of a hyperbola all go to infinity, they all meet at the same point when inverted.

2017-07-22Inversion2v2

So now you know how to work with geometrical inversion from an algebraic standpoint.  I hope seeing some of the fascinating images you can create will inspire you to try creating some yourself!

More on: What is…Projective Geometry?

This week, I thought I’d go a little deeper into the subject of projective geometry (feel free to reread last week’s post for a refresher).  Why? I think this is a good opportunity to discuss the idea of an algebraic model of a geometry.  Certainly using Cartesian coordinates in the Euclidean plane makes many geometrical problems easier to approach.

So what would a coordinate system in projective geometry look like?  The most commonly used system is homogeneous coordinates.  Let’s see how they work.

The difficulty with adding the line at infinity is that we need infinitely many points in addition to those already in the plane.  Perhaps you might imagine that adding an “infinite” coordinate might do the trick, but there is an alternative — and algebraically simpler — approach.

First, think of the Euclidean plane as being the plane z = 1 in three-dimensional Cartesian coordinates, so that every Euclidean point (xy) is given homogeneous coordinates (xy, 1).  But we don’t want to make the z-coordinate special — we want all the homogeneous coordinates to have similar interpretations.  We accomplish this by giving each point infinitely many names — specifically, for any k ≠ 0, the coordinates (kxkyk) describe the same point as (xy, 1).  Geometrically, you might think of this as saying that the line through  (xy, 1) (except the origin) is, in some sense, the point (xy, 1).

So if z ≠ 0, the point (xyz) in homogeneous coordinates is another name for the Euclidean point (x/zy/z).  But why would you want to do this?

The punch line is that we can now use z = 0 to indicate that a point is on the line at infinity!  We still keep the convention that if k ≠ 0, the homogeneous coordinates (kxky, 0) describe the same point as (xy, 0), as long as x and y are not both 0.

So our system of homogenous coordinates contains all points (xyz) such that not all three coordinates are 0.  Any point with z ≠ 0 corresponds to a Euclidean point, and any point with z = 0 corresponds to a point on the line at infinity.

Is it really worth all this trouble?  There are many interesting features of such a coordinate system — and I’d like to mention a few of them here, omitting the proofs.  There are many resources online that include all the details — one example is the classic Projective Geometry by Veblen and Young available free as an ebook.

Let’s start be looking at equations of lines in projective geometry.  In the Cartesian plane, we may represent a line in the form Ax + By + C = 0, where A, B, and C are not all zero.  In the projective plane, a line has the form form Ax + By + Cz = 0, where A, B, and C are not all zero.  Nice, isn’t it?  This form is also consistent with our system of having many names for a point:  if Ax + By + Cz = 0 and k ≠ 0, then also A(kx) + B(ky) + C(kz) = 0 as well. So no problems there.

But the really neat aspect of this representation is how you can use linear algebra in three dimensions to solve many problems in projective geometry.  This isn’t a post about linear algebra — so I’ll limit myself to just one example.  But in case you do know something about linear algebra, I think you should see how it can be used in projective geometry when homogeneous coordinate are used.

We’ll consider the problem of finding the intersection of two lines, say Ax + By + Cz = 0 and Dx + Ey + Fz = 0.  The form of these expressions should remind you of taking the dot product, so that we can rewrite these expressions as

(A,B,C)\cdot(x,y,z)=(D,E,F)\cdot(x,y,z)=0.

Interpreting these coordinates and coefficients as vectors in three-dimensional space, we observe that the common point (xyz) is simultaneously perpendicular to both (A, B, C) and (D, E, F), since both dot products are zero.  So (xyz) can be found using the cross-product

(x,y,z)=(A,B,C)\times(D,E,F).

Very nice!  Again, there are many such examples, but this is not the place to discuss them….

This algebraic model also suggests another geometric model for the projective plane besides adding a line at infinity to the Euclidean plane.  Begin with the surface of a sphere centered at the origin in three-dimensional Cartesian space, and observe that opposite points on the sphere have homogeneous coordinates that are different names for the same point in the projective plane.

So, in some sense, we have exactly twice as many points as we need — so we identify opposite points on this sphere, so that they are in fact the same point.  (You might recall a similar discussion about points in the post on spherical geometry.)  Thinking about it in another way, we might just consider the top hemisphere of the sphere with only half of the equator, including just one of the endpoints of the semicircle.

And while this model is fairly simple geometrically, it is important to point out that this does not mean that the projective plane lies inside three-dimensional space.  Once we have our hemisphere and semicircle, we have to think about it without any of the surrounding space.  This is not easy to do, but this type of thinking is necessary all the time when studying differential geometry, a topic for another time….

One last benefit to using homogenous coordinates:  it can easily be abstracted to any number of dimensions.  Do you want a projective space?  Just add a plane at infinity to three-dimensional Euclidean space!  Coordinates are easy — all points (x, y, z, w), with not all coordinates equal to 0.  When w ≠ 0, the point (x, y, z, w) corresponds to the Euclidean point (x/w, y/w, z/w), and when w = 0, the point is on the plane at infinity.

And clearly, there would be no need to stop at three dimensions — it is just as easy to create a projective space of four or more dimensions.

Finding a workable system of coordinates for a particular geometry is not always a simple matter — but finding a system that allows problems to be solved easily is often a key step to studying any type of geometry.  I hope this gives you some insight to yet another aspect of the diverse universe of so many different Geometries….

What is…Projective Geometry?

The last type of geometry I discussed was inversive geometry, which is obtained by adding a point at infinity to the Euclidean plane.  Recall that as long as we had a consistent, useful model of this extended plane, it made perfect sense to define this new type of geometry.

Today, we’re going to add a line at infinity — creating what is called a projective geometry.  There are in fact many different types of projective geometries, but let’s just try to understand one at a time….

You might remember one important property of ω, the point at infinity in inversive geometry:  it was on every unbounded curve, and in particular, on every line. We need to be a bit more specific with our projective geometry, in the following sense.  Every line will intersect the line at infinity — denoted by λ — but not every line will intersect at the same point.

Consider all lines with some given slope m.  We then add one point to λ which lies on these lines, but no other lines.  In other words, each point on λ corresponds to an infinite family of parallel Euclidean lines — since now, with the addition of λ, there are no parallel lines in the projective plane.  The point at which two parallel (in the Euclidean sense) lines intersect is determined by their slope.

How does this differ from inversive geometry?  Well, in inversive geometry, if two lines had different slopes, they intersected in two points:  the usual finite point of intersection you learned about in algebra class, as well as ω.  But in projective geometry, two lines with different slopes intersect in only one point, since they intersect the line at infinity in two different points.

What this means is that any two distinct lines always intersect in exactly one point.  See the difference?  Parallel lines (in the Euclidean sense) intersect in a point on λ, and nonparallel (in the Euclidean sense) lines intersect in the same point they did in Euclidean geometry.

Now let’s look at the dual question (recall the discussion of duality, an important concept in spherical geometry):  what about a line between two points?  Two finite points generate a line, as usual.  If one point is finite and one lies on λ, the line generated is that line through the finite point with the slope corresponding to the point on λ.  And if both points are infinite, then the line through them is just λ.

Thus we have the following duality:  two distinct lines determine a unique point, and two distinct points determine a unique line.  Again, duality is an extremely powerful concept in geometry, so the fact that points and lines are dual concepts really is a legitimate justification for thinking about projective geometry.

Projective plane geometry is a broad subject — but some of my favorite objects to look at in projective geometry are the conic sections:  ellipses, parabolas, and hyperbolas.  This is because from the point of view of projective geometry, they are, in a sense which we’ll look at right now, all the same.

This sounds odd at first reading, but follow along.  The first question we need to consider is what points on λ lie on unbounded curves.  For lines, it’s easy — it’s just the point on λ corresponding to the slope of the line.

Now what about a parabola?parabola

You can see from the image that as points on the parabola move further away from its vertex, the tangents have slopes of ever-increasing magnitude.  Determining the precise slopes is an easy exercise in calculus — but what is important is that the tangent lines approach, in slope, the axis of the parabola.  In this case the axis is vertical, but of course the parabola may be rotated.

What this means is that the parabola intersects the line at infinity in the point corresponding to the slope of its axis.  Again, the tangent lines on either side approach this slope, but from two directions — from above and from below.

Now hold this thought while we look at a hyperbola.

hyperbola

Let’s see how we travel along the hyperbola.  As we move to the upper right toward the open red circle, we are moving closer to the red dashed asymptote — meaning we approach the point on λ corresponding to the slope of the red asymptote.  But here is where it becomes interesting:  as we cross the line at infinity, we come back along the asymptote toward the filled red circle on the other branch of the hyperbola!

Then we continue moving along the left branch, getting continually closer to the blue asymptote, approaching that point on λ corresponding to the slope of the blue asymptote as we pass through the blue filled circle.  Then we cross the line at infinity again, and jump to the right branch of the hyperbola toward the open blue circle.

Can you see what this means?  In projective geometry, a hyperbola does not have two separate branches.  Adding the line at infinity allows us a means to jump between the two branches.

Let’s look at these scenarios from a slightly different perspective.  Suppose that somehow, we can actually draw the line at infinity.  It’s the blue dashed line in the figure below.  Easy.

conics

Can you see where we’re going with this?  The left circle represents an ellipse, since it is a bounded curve and cannot intersect λ.  The middle circle represents a parabola — it’s a curve which intersects the line at infinity at exactly one point, and so is actually tangent to λ.  The right circle represents a hyperbola, since it intersects the line at infinity at two points.  It may look strange from this perspective, but this right circle really does represent the hyperbola illustrated above.

To summarize:  if a conic does not intersect the line at infinity, we call it a Euclidean ellipse, if it is tangent to λ, we call it a Euclidean parabola, and if it intersects λ in two points, we call it a Euclidean hyperbola.

Because you see, in projective geometry, there is no distinguished line.  Every line is just like any other.  So, in some sense, these is just one conic section in projective geometry!

What we have looked at today is what would be called an embedding of the Euclidean plane in the projective plane.  We saw how we could just add a line at infinity with certain properties, and our plane would behave “projectively.”  But from the perspective of projective geometry, you’ve just got conic sections and lines, with possibly 0, 1, or 2 intersection points as illustrated above.  A little mind-blowing, but absolutely true.

Of course we’ve only been able to scratch the surface of this really amazing geometrical world today.  Hopefully you will be inspired to learn a little bit more about it….