from numpy import *
def normalize( v ):
len = linalg.linalg.norm( v )
v[0,0] = v[0,0] / len
v[0,1] = v[0,1] / len
v[0,2] = v[0,2] / len
return v
def create_numpy_rotation_matrix( axis, phi ):
axis_n = normalize( axis )
u_1 = axis_n[0,0]
u_2 = axis_n[0,1]
u_3 = axis_n[0,2]
cos_phi = cos( phi )
sin_phi = sin( phi )
return matrix([[ cos_phi + ((1 - cos_phi) * u_1 * u_1), (1 - cos_phi) * u_1 * u_2 - u_3 * sin_phi, (1 - cos_phi) * u_1 * u_3 + u_2 * sin_phi ],
[ (1 - cos_phi) * u_1 * u_2 + u_3 * sin_phi, cos_phi + (1 - cos_phi) * u_2 * u_2, (1 - cos_phi) * u_2 * u_3 - u_1 * sin_phi ],
[ (1 - cos_phi) * u_1 * u_3 - u_2 * sin_phi, (1 - cos_phi) * u_2 * u_3 + u_1 * sin_phi, cos_phi + (1 - cos_phi) * u_3 * u_3 ]])
Thursday, April 10, 2008
numpy rotation matrix
Here's a small, ugly chunk of code that takes an angle and rotation axis and generates a numpy rotation matrix.
Tuesday, January 29, 2008
LaTeX Makefile
Direct Download
hg repo
The short version:
A simple makefile for compiling LaTeX documents. Hopefully easy to configure for your needs.
Overview:
Most of the times when I use LaTeX, pdflatex is the easiest way to compile my TeX source and be on my way. However, pdflatex has some limitations - most notably on my system it doesn't handle embedded graphics very well. It barfs when it runs into \includegraphics directives that refer to EPS and PS files, which are the two most common formats I use.
You can get around this problem by going the latex->dvi->pdf route, but I found it cumbersome to repeat these commands by hand. I wrote a simple makefile to handle the compilation and document assembly.
This makefile will compile a LaTeX file and then convert it to PS and PDF formats. It keeps the intermediate files in a separate directory to avoid clutter.
It also checks for updates to a BiBTeX file and, if necessary, runs BiBTeX to update the bibliography database.
I'm posting it up in the hopes that someone else might find it useful. I tried to document it fairly well - just edit the variables near the top to point to whatever file you're working on.
Usage:
The make targets are:
pdf-full (default) - runs latex, (optionally) bibtex, dvips and dvipdf on the input file specified at the top of the makefile. Intermediate output files go in a work directory (default: work/)
pdf-only - runs latex, (optionally) bibtex, and dvipdf
pdf - runs pdflatex, (optionally) bibtex
Tested with:
hg repo
The short version:
A simple makefile for compiling LaTeX documents. Hopefully easy to configure for your needs.
Overview:
Most of the times when I use LaTeX, pdflatex is the easiest way to compile my TeX source and be on my way. However, pdflatex has some limitations - most notably on my system it doesn't handle embedded graphics very well. It barfs when it runs into \includegraphics directives that refer to EPS and PS files, which are the two most common formats I use.
You can get around this problem by going the latex->dvi->pdf route, but I found it cumbersome to repeat these commands by hand. I wrote a simple makefile to handle the compilation and document assembly.
This makefile will compile a LaTeX file and then convert it to PS and PDF formats. It keeps the intermediate files in a separate directory to avoid clutter.
It also checks for updates to a BiBTeX file and, if necessary, runs BiBTeX to update the bibliography database.
I'm posting it up in the hopes that someone else might find it useful. I tried to document it fairly well - just edit the variables near the top to point to whatever file you're working on.
Usage:
The make targets are:
pdf-full (default) - runs latex, (optionally) bibtex, dvips and dvipdf on the input file specified at the top of the makefile. Intermediate output files go in a work directory (default: work/)
pdf-only - runs latex, (optionally) bibtex, and dvipdf
pdf - runs pdflatex, (optionally) bibtex
Tested with:
- GNU Make 3.81
- LaTeX version pdfeTeX 3.141592-1.21a-2.2 (Web2C 7.5.4)
- dvips(k) 5.95a Copyright 2005 Radical Eye Software (www.radicaleye.com)
I don't have a lot of experience writing makefiles, so any comments on better construction are appreciated. Specifically I've marked two "hacky" bits I would have liked to make better with TODO's.
Wednesday, March 7, 2007
Topology Intro, continued
Continuity is of great importance in topology. We define continuity very generally, based only on the definitions from the previous post. Despite this, it's one of the most fundamental concepts in topology.
Along with continuity, another important concept is that of homeomorphism.
These two concepts are a bit dry, but they are important building blocks in topology. Next time I'll show some pictures that give a more clear and intuitive understanding for what it means for a function to be continuous and for two spaces to be homeomorphic.
Let f: X -> Y be a function from a topological space X to a topological space Y.It's important to think of this in the purest abstract sense. Both X and Y are topologies and they can be on entirely different sets with completely different notions of what it means to be open - we can still define a continuous function between them.
We say that f is continuous if and only if for every open set V in Y, the inverse image of V under f, f-1(V), is open in X.
Along with continuity, another important concept is that of homeomorphism.
Let f be a function from a topological space X to a topological space Y. We say f is a homeomorphism if f satisfies the following conditions.If a homeomorphism exists between two spaces X and Y we say that X and Y are homeomorphic.
- f is continuous
- f is a bijection (f is 1-1 and onto)
- f-1 is also continuous
These two concepts are a bit dry, but they are important building blocks in topology. Next time I'll show some pictures that give a more clear and intuitive understanding for what it means for a function to be continuous and for two spaces to be homeomorphic.
Tuesday, March 6, 2007
Topology Intro
I've been studying topology for about a year and I'm an addict.
Not in a long time has anything drawn me in, held my interest, and continued to fascinate me as I progress.
Topology is a branch of mathematics that can perhaps be described as abstract geometry. In topology we take various mathematical structures and think about them as shapes. Properties of these shapes (e.g. whether they have holes, if they curve in on themselves, if you can draw a path on them) reflect underlying properties in the mathematical structures.
If we create topologies (e.g. shapes) on two different mathematical structures, and the shapes are similar, we can conclude that certain aspects of the underlying mathematical structures are similar.
It's awesome.
Rigor follows.
A topology is a set X on which we define what it means for a subset U of X to be open and which satisfies the following conditions.
Not in a long time has anything drawn me in, held my interest, and continued to fascinate me as I progress.
Topology is a branch of mathematics that can perhaps be described as abstract geometry. In topology we take various mathematical structures and think about them as shapes. Properties of these shapes (e.g. whether they have holes, if they curve in on themselves, if you can draw a path on them) reflect underlying properties in the mathematical structures.
If we create topologies (e.g. shapes) on two different mathematical structures, and the shapes are similar, we can conclude that certain aspects of the underlying mathematical structures are similar.
It's awesome.
Rigor follows.
A topology is a set X on which we define what it means for a subset U of X to be open and which satisfies the following conditions.
- Under the specification of an open set in X, the arbitrary union of open sets is also open
- The finite intersection of open sets is open
- X, the entire set, is open
- The empty set is open
- X = R
- An open set is an open interval (e.g. not including end points) on the real line, (a, b) where a < b
- Additionally, we define R and the empty sets as two additional open sets
Subscribe to:
Posts (Atom)