So earlier I alluded to how you can go about drawing an ellipsoid in OpenGL. I’ve also noticed a lot of people have been coming to this site expecting to find a tutorial on drawing ellipses (2D). This is a quick how-to on building these. It’s short, and to the point, but this works.
We first parametrize the equation of an ellipse (in the X-Y plane) centered at (x,y,0):
In this case, we’re parametrizing over , and
and
are the major axes lengths. To implement this in programming, we can build the “vertices” of in a loop:
float[] a = new float[3*361]; // 3-coordinates and 361 angles
for (int i=0; i<=360; i+=3) {
a[i+0] = x+(float)cos(i*PI/180)*rx; // X
a[i+1] = y+(float)sin(i*PI/180)*ry; // Y
a[i+2] = z; // Z
}
Drawing it using GL_LINE_LOOP will then render a completed ellipse:
If you’re like me, say you’re in research or academia, you are constantly reading research papers. In the old days, you would print off these papers and then organize them in folders or in stacks on your desk. Well, my desk isn’t that big. And paper and ink is expensive so the nowadays most people keep their research papers on their computers in the form of PDFs. There are pros and cons of doing this, and I will talk about how to fix the biggest con which is organizing these beasts. If you have and use Firefox, then you’ve probably heard of Zotero, which is a Firefox plugin that manages all your research documents. There are two requirements to use this however: you must be a user of Firefox (I am not anymore), and you must be online (What if you took your laptop to a café with no WiFi?) There are also two very big Pros to this program: it’s free, and it can export to BibTeX.
I don’t use Firefox anymore, the newest version of Safari works perfectly for me without the fluff. So, Zotero is out. Plus I wanted a standalone program to use. In comes Papers. Papers was designed specifically for research and technical papers to organize. It allows you to specify all the properties to be able to export to BibTeX, and even organize in different categories and subjects. It even has a myriad of built-in search engines designed to find technical papers, such as Google Scholar, Citeseer, ACM, PubMed, etc. These search engines can also help you complete the meta information for these papers.
Papers organizes your PDFs much like iTunes organizes your music. It copies the PDF (and optionally deletes the original) to a directory where it organizes it based on a scheme of your choosing. This is handy because before, and with Zotero, it just points to where the paper is. So if you do any future organization, the links are broken and have to be reestablished. This is annoying.
The downside? It ain’t free. It costs $42. But in my experience, a lot of these types of programs really fall short on what they offer in simplicity, reliability and usability. I did the free 30 day trial and I was satisfied enough to pay the money for it.
What they need to create is a program that parses the PDFs to grab the information, but that has yet to be done properly.
Screenshots.
If you’re a programmer then you probably have heard of Vim. Vim is a great text editor but the beauty lies in the syntax highlighting. The idea is to be able to move swiftly through your code without lifting your fingers from the keyboard. A mouse-less text editor. It takes a little bit of practice, but won’t take long to learn. If you’re running linux, you can grab it through apt-get, if you’re on a Mac, the check out MacVim, and Windows users should go through the Vim website. To learn, after you’ve installed Vim type “vimtutor” in a terminal and start practicing, I won’t go into how to operate this here.
Vim currently supports a load of programming languages for syntax highlighting. Although, I’m upset that there isn’t built-in support for Scala yet, you’ll have to find that file elsewhere.
Now that you have your GVim editor (Graphical Vim), you can edit some of its properties. In comes the two files: .vimrc and .gvimrc. The first file should already exist within your home directory, and the latter you may need to create (within your home directoy as well).
There are a number of settings you can manually set. For my .gvimrc, for example, I have this:
</div> <div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">set lines=40</div> <div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">set columns=78</div> <div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">set guioptions-=m</div> <div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">set guioptions-=T</div> <div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">set guifont=Monaco:h13</div> <div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">
set lines=40 set columns=78 set guioptions-=m set guioptions-=T set guifont=Monaco:h13
This sets the lines, columns, font type and size, as well as disables that ugly toolbar. Basically what you’re left with is a clean window for editing:
The .vimrc file has many options for you to throw in, and instead of listing everything, here are useful links to get you on your way:
While an icosahedron hardly looks like a sphere (unless you are looking at it from far away), we can easily approximate a sphere. This is taken directly out of The Redbook, and adapted for Java: (For more information I recommend checking out this great book)
float[] v1, float[] v2, float[] v3, float depth)
{
float[] v12 = new float[3];
float[] v23 = new float[3];
float[] v31 = new float[3];
// If done, add the final vertices and return.
if (depth==0) {
// Do what you will with the vertices here
return;
}
// Find the midpoint.
for (int i=0; i<3; i++) {
v12[i] = (v1[i]+v2[i])/2.0f;
v23[i] = (v2[i]+v3[i])/2.0f;
v31[i] = (v3[i]+v1[i])/2.0f;
}
// Normalize the coordinates.
v12 = normalize(v12);
v23 = normalize(v23);
v31 = normalize(v31);
// Recursively subdivide
subdivide(v2,v23,v12,depth-1);
subdivide(v1,v12,v31,depth-1);
subdivide(v3,v31,v23,depth-1);
subdivide(v12,v23,v31,depth-1);
}
To break this down, we divide each segment in half. To do this we must calculate the midpoint as shown above. Next, we normalize each of those coordinates by using a function (which I called normalize) that can do whatever process you want to acquire the appropriate distance from the center. (Purposefully being vague, but it’s not hard to figure out.) We then take those new vertices and pop them into the recursion once again. This will repeat until we’ve reached our target approximation.
Proper recursive subdivision will turn out icosahedron into a believable sphere.
OpenGL is a very powerful interface to graphics hardware consisting of over 700 distinct commands that you use to specify the objects and operations needed to produce interactive 3-Dimensional environments. OpenGL’s most popular application is in 3D games such as World of Warcraft, Counter-Strike, Call of Duty, and the wikipedia list goes on and on. However, it is also a very good scientific visual aid. For example, in my field, terabytes or even petabytes of 3-dimensional seismic data are constantly being processed. Being able to visualize the subsurface in all three dimensions is essential to obtaining an accurate interpretation.
In this series I will explain how to approximate drawing an ellipsoid. I’m learning this as I go, and I post as I go. One big help to my research will be the OpenGL Programming Guide, or “The RedBook” by Shreiner et al. This book has so far proven extremely valuable. The issue is that the code examples are written in C, and for my purposes I will be writing in Java, and JOGL, which is just a set of Java bindings to the OpenGL API.
In order to approximate an ellipsoid we must first draw a sphere. The idea is that an ellipsoid has three primary axes shown in the equation:
Where x, y and z are the three axes, and a, b and c are their respective equatorial radii. In a sphere, a = b = c. So, to simplify drawing an ellipsoid we first draw a sphere.
There are lots of ways to draw a sphere in OpenGL. For this purpose, we want to draw a sphere with the radii as parameters set by the user. One example is by drawing an icosahedron, and the subdivide the segments to approximate a sphere.
An icosahedron is a Platonic object composed of 20 equilateral triangles spanning 12 vertices.
We therefore initialize array of vertices as well as an X and Z value.
private static float[] _vertices; private static float X = 0.525731112119133606f; private static float Z = 0.850650808352039932f
The weird numbers are so the distance from the origin to any of the vertices is 1.
Next, we assign the 12 vertices:
float[][] vertices =
{{-X,0.0f,Z}, {X,0.0f,Z}, {-X,0.0f,-Z}, {X,0.0f,-Z},
{0.0f,Z,X}, {0.0f,Z,-X}, {0.0f,-Z,X}, {0.0f,-Z,-X},
{Z,X,0.0f}, {-Z,X,0.0f}, {Z,-X,0.0f}, {-Z,-X,0.0f}};
Then we specify the order of these coordinates we need in order to get the icosahedron we want:
int[] indices =
{1,4,0, 4,9,0, 4,5,9, 8,5,4, 1,8,4,
1,10,8, 10,3,8, 8,3,5, 3,2,5, 3,7,2,
3,10,7, 10,6,7, 6,11,7, 6,0,11, 6,1,0,
10,1,6, 11,0,9, 2,11,9, 5,2,9, 11,2,7};
Now we cycle through each of the indices and place them into our private _vertices array. The reason we do this is because otherwise we would have 20 triangles sitting on top of each other.
_vertices = new float[indices.length*3];
for (int i=0; i<indices.length; ++i) {
_vertices[(3*i)+0] = vertices[indices[i]][0];
_vertices[(3*i)+1] = vertices[indices[i]][1];
_vertices[(3*i)+2] = vertices[indices[i]][2];
}
Correctly implementing the vertices in succession will give you a beautiful icosahedron, as seen in the figure below.
Next: Recursive subdivision of the icosahedron to approximate a sphere.
privatstatic float
X = 0.525731112119133606f;
[/sourcecode]
Yesterday I was asked to make a template or theme in Keynote, and it occurred to me that I’ve never seen or heard about how to accomplish this. After doing some snooping around the internet and playing with iWork myself I noticed a few things, first: it is possible in theory to create your own themes because File -> Save Theme exists. However, whenever I would make some basic templates I would save the theme and it would be gone. I knew I had to edit the master slides but there is no help pointing you in that direction.
The master slides are actually hidden. Doesn’t really make sense why, because you can’t overwrite the default master slides (to my knowledge), so permanent alteration is not readily possible. To find the master slides, open up Keynote and start with a basic template (probably white – allows for a fresh start).
Pretty basic, right? You could make temporary changes to these slides alone but the purpose of this slide is to make a theme.
If you look at the left panel labeled “Slides”, there’s a slider that’s cleverly camouflaged. The only noticeable difference is the double-horizontal line icon indicating that the panel is resizable.
Now you can double click on a master slide and alter it at will. Don’t forget to go down the line and change them all, wouldn’t really be a theme otherwise. Once you’re done, now feel free to go to File -> Save Theme
Now you have a crazy cool theme! If you want to use it next time, just look at the bottom of the theme chooser because it’s appended to the end of the list.
I recently purchased iWork ‘09 after trying it out for the first 30 days. There are a lot of things about it that I like (e.g. the backwards compatibility with Office 2007, the ability to export to pdf, etc.) However, one big thing that I noticed was missing was that the package has no built-in equation editor. This is a big red flag for me since as a student I’m throwing equations in papers and presentations all the time. Office 2007 offers a fairly straight-forward equation editor, and then of course there’s OpenOffice Formula for the linux users. There is a solution, but it requires a very small amount of knowledge in .
LaTeXiT offers a very simple solution, and actually ends up looking much better than MS Office and OpenOffice. Once you know how to use it, it can become a lot faster as well.
When I start a presentation in Keynote, I usually launch LaTeXiT as well.

Keynote and LaTeXiT

Type your equation into LaTeXiT and render it

Simply click and drag the equation into Keynote, and voila! A completely vectorized equation you can resize at will
is an excellent document markup language which is used, predominantly in the academic industry, to produce crisp reports and simple professional presentations or slides. Why not just use Microsoft Office? Well, there are a lot of reasons why you’d want to choose between these two environments. For example, one might want to use Office because it is WYSIWYG (or, What You See Is What You Get), which is a programming term used for a system where the content displayed during editing appears similar, if not identical, to the final product. This is very handy for the people who enjoy watching their report grow. They can recognize if something doesn’t look correct immediately. However, this can be a hindrance when you know what you want but can’t seem to find that damn button that does it.
The environment is rather text-based, and you don’t see the actual product until you compile it. One benefit of
is that it handles a lot of things for you, and makes it look good, and keeps organization easy when it comes to references, citations and equations. The problem here comes in when you don’t know the correct syntax, which is comparable to the previous problem. So,
isn’t for everyone, but then again neither is Office.
For those of you who use , you can make your lives a lot simpler if you create a basic macro file that handles all those cumbersome commands. So, to show an image you go from typing:
\begin{figure}
\includegraphics[width=200px]{earth.png}
\caption{This is planet Earth.}
\label{fig:earth}
\end{figure}
to
\fig{200px}{earth.png}{This is planet Earth.}{fig:earth}
which effectively reduced the number of lines from 5 to 1.
To create your own macro, create a tex file that will be easy for you to remember, such as macro.tex.
Within your blank .tex file, create your first definition by using the \def command. For this one, we will use the figure example above. Type:
\def\fig#1#2#3#4 {
\begin{figure}
\includegraphics[width=#1]{#2}
\caption{#3}
\label{#4}
\end{figure}
}
Following the \def declaration you must put the name of your function, followed with however many parameters you want to have the freedom to choose (4, in this case). Notice how they are entered as #1#2#3#4. Within the curly braces of the function, place the command you want, with each variable replaced with a variable number.
To use the macro you’ve just made, in the preamble of your report put:
\input{macro.tex}
Assuming your macro is in the same directory as your file. Then in the main file all you need to do is call your \fig command with all the parameters to produce the desired output
Now you can dump all the redundant cumbersome functions you want in your macro.tex file and let that be the last time you’ll ever have to type all those out!
Requirements:
- The most recent version of Java (http://java.sun.com/javase/downloads/index.jsp)
- A text editor of your choice (I use Vim)
- A terminal window & knowledge of BASH commands
You know, the resources available to distribute programs through Java Web Start (JWS) are few and far between, so here is a summary from start to finish on how you can get a .java file and make it into a sexy JWS application. This has mainly been spliced together from what information I could find, and also me some intermediate steps I had to play with. This tutorial is full of pictures, so look out!
1. Make your application
All you need to start with is your .java file.
2. Make your JNLP file
The JNLP file for my program is as follows: (I will break this down later)
JWS uses what’s called a Java Network Launching Protocol (JNLP) file to launch the program onto the computer of interest. These are only XML files with a different extension. They do need to follow a very specific format, however. Here’s how my JNLP file breaks down:
<?xml version="1.0" encoding="UTF-8"?>
This just describes the xml version and encoding.
<jnlp spec="1.0+" codebase="file:///Users/chris/Sites/SeniorDesign/apps/" > ... </jnlp>
This begins your JNLP envelope by describing the specification version and the directory of your JAR applications. Since I will be launching this locally, I need to include the entire path “file:///…”
<information> <title>Gravity Forward Modeling Program</title> <vendor>Colorado School of Mines</vendor> <homepage href="/SeniorDesign" /> <description>Interactive forward modeling program</description> </information>
The information section gives basic information about the application.
- <title> gives the title.
- <vendor> who distributes this program?
- <homepage> what is the homepage of the vendor?
- <description> a brief description about the program.
<offline-allowed />
This allows the application to be run if not connected to the network.
<security> <all-permissions /> </security>
This is the security section, which denotes who can use the program. are two possibilities that can go in here: all-permissions, and j2ee-application-client-permissions. The J2EE permission supports a limited number of usability, and so I set this to all-permissions to avoid problems. The reason we sign our jar files is because of this section right here.
<resources> <j2se version="1.2+" /> <jar href="lib/gravityFM.jar" /> <jar href="lib/edu_mines_jtk.jar" /> </resources>
The resources section requests both the runtime version required, and the location of the jar files containing the application classes. For my program, I required two jar files, which both have to be signed by the same vendor.
<application-desc main-class="gravityGUI.gravityFM" />
This section describes two things: (1) That it’s in fact an application (instead of an applet), and (2) the main class name. Both are required. That’s all you need for the JNLP file, of course there are additional parameters you can enter, but you can of course look those up.
3. Compile your application
You should now have .class files to accompany your .java file.
4. Create your Manifest file
If you edit your program in a text editor such as Vim, Emacs, Notepad or otherwise, then you’ll need to create a Manifest file. (If you use an IDE such as Eclipse or Netbeans then you can produce a Manifest file that way, I believe). To do this, create a file and name it Manifest.txt. Add these two lines: Main-Class: yourMainClass Class-Path: anyExtrajars.jar Make sure there’s a return character after the last line, because apparently it won’t parse correctly otherwise. Explanation: The Main-Class argument is the class which runs the program. This is (most often) the class that contains: public static void main(String[] args) The Class-Path argument is for any outside JAR files that need to be compiled with your program. In my case, my Manifest.txt file looks like this:
5. Create and sign your JAR file
Since JWS requires that you use archived Java files, you will need to create .jar files for your classes. Command inputs are listed as bold face, and subsequent explanations are below.
$ jar cvmf Manifest.txt myJar.jar directory/*.class
This command will create your jar file with the manifest file that you just created. Breaking down these parameters:
- -c = create new java archive
- -v = be verbose about it (show me what I’ve added)
- -m = add the manifest file
- -f = specify the name of the jar file
The output should look something like this:

Output of creating the JAR file. Note that it added the manifest first, then the subsequent java classes
$ keytool -genkey -keystore myKeys -alias myAlias
In order to distribute a published JAR file, you will need to sign it. The means that when a user comes by and clicks on the link to the program, a little online certificate will pop up requesting permission to invade their computer with your program. Rename myKeys and myAlias to relevant names, of course. You will be prompted for a series of information concerning the keystore. CAUTION: remember your password!

An example of creating your own keystore. Make sure to put any relevant information as the user might wonder who is responsible for the program
$ jarsigner -keystore myKeys myJar.jar yourAlias
This will sign the jar file you created. You will need to know your password. Now you have a JAR file, and a JNLP file, so now you can put it all onto your website.
6. Set up your website directory
Move your JAR file to your website directory, (more specifically, into the directory you defined as your codebase parameter in your JNLP file).
7. Link to the JNLP file
To call the file, simply create a link to the JNLP file. Make sure your server can handle these kinds of files (see below).
<a href="yourJnlpFile.jnlp">Click here for awesomeness</a>

Success! A standalone application that runs on the user's computer instead of directly off the network
8. A note: Server configuration
While JWS does not rely on HTTP and the latest server technology, there is one configuration that must be done in order for it to work properly. The web server must be configured to return the proper MIME type for the JNLP content. If your’e using the latest version of Tomcat 4.0.x, this is already configured for you. I am running Apache 2 locally on my mac and it was already set up. However, older versions do require a manual config edit. If you look into the web.xml file in the conf directory in the installation location, you’ll find this information:
<mime-mapping> <extenstion>jnlp</extension> <mime-type>application/x-java-jnlp-file</mime-type> </mime-mapping>
Older configurations will requre you to enter this information manually. That’s it! Now you can distribute all your Java files over the internet like popcorn.
9. Resources
Clearly I didn’t come up with this on my own. Check out these websites for more information
- Java website information on Java Web Start http://java.sun.com/developer/technicalArticles/Programming/jnlp/
- Information on manifest files http://en.wikipedia.org/wiki/Manifest_file
- Jar creation & editing http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/jar.html
- JNLP Tag Reference http://lopica.sourceforge.net/ref.html



























