Hypnotic Figure Eight Klein Bottle Emblem
Introduction
I made this cool little emblem in C++/GLSL [1]. It is shaded in realtime to look smooth and smarmy at arbitrary zoom. You can find the math at MathWorld’s Klein Bottle entry (scroll down a little).
Challenges
Normals in closed form
I had to punch the parametric equations into Mathematica to get a closed-form solution for the normals (a huge pile of sine and cosine terms [2]), so that it maintains its infinitely awesome smoothness when Blinn-Phong shaded on a per pixel basis in hardware.
Normal mapping a non-orientable surface
The main challenge was figuring out how to normal map and cull a non-orientable surface! Of course the trick was to do it piecewise, as we do in any good-old-nasty-sticky-applied-math-type situation.
Code
[1] Here is a zip of the Xcode project. It compiles on my MacBook Pro (Intel) under Leopard.
[2] As here:
p(u,v) = (x(u,v), y(u,v), z(u,v))
x(u,v) = cos(u) [ a + cos(u/2) sin(v) - sin(u/2) sin(2 v) ]
y(u,v) = sin(u) [ a + cos(u/2) sin(v) - sin(u/2) sin(2 v) ]
z(u,v) = sin(u/2) sin(v) + cos(u/2) sin(2 v)
dp/du =
dx/du = cos(u) (-1/2 sin(u/2) sin(v) - 1/2 cos(u/2) sin(2 v))
- sin(u) (a + cos(u/2) sin (v) - sin(u/2) sin(2 v))
dy/du = sin(u) (-1/2 sin(u/2) sin(v) - 1/2 cos(u/2) sin(2 v))
+ cos(u) (a + cos(u/2) sin(v) - sin(u/2) sin(2 v))
dz/du = 1/2 cos(u/2) sin(v) - 1/2 sin (u/2) sin(2 v)
dp/dv =
dx/dv = cos(u) (cos(u/2) cos(v) - 2 cos(2 v) sin(u/2))
dy/dv = sin(u) (cos(u/2) cos(v) - 2 cos(2 v) sin(u/2))
dz/dv = 2 cos(u/2) cos(2 v) + cos(v) sin(u/2)
normal = cross(normalize(dp/du), normalize(dp/dv))
Note
The code is available for playing with, learning from, and improving (hence GPLv2). The use of a/the Figure Eight Klein Bottle with the nice shading and colors and orientation is my personal trademark. This is not to say that (1) I am “copyright”ing a mathematical shape (learn the difference between a trademark and copyright) or (2) that you can’t play with this and make your own pages or artwork (posters, for example) or anything you want, even if you sell it. What I am saying is that I came up with the idea of using the shape/colors as a personal/professional logo. Make up your own logo.
As an example, GE uses the letters G and E and a circle swirly deal for their logo. You can use the letters G and E and circles and swirls in your own logo as long as no one confuses it with GE’s logo. Same here. You can use figure eight Klein bottle shapes how you like, just don’t steal my logo—or make a rip off that is too similar—for use as a logo. Especially if you are commercializing off my idea.
The FSF uses the gnu as a logo and I’m sure their lawyers would be ticked if people misrepresented the FSF with a gnu logo (or derivative) or tried to commercialize off it in a closed source way—i.e. they want you to use the logo if you are helping the FSF with its goals but if you are antagonistic to their goals and you use their logo for something illegal (like close-sourcing and distributing GNU-derived software) then they’ll come after you. That’s my interpretation, anyway.