Andrew Que Sites list Photos
Projects Contact
    Tonight was suppose to be the Duke Nukem 3d LAN party, but no one really showed up.  We had 3 player, which while fun, still wasn't what it could have been.
    Vinny in a basket
    Vinny, just lounging on my lap.  Poor Vinny has cabin fever.  It's too cold for her to go outside (she won't leave) and she's bouncing off the walls in the house.  When not reeking havoc, she likes to sleep in my lap.  She's taken to lounging on her back, which is kind of amusing.
    This came in the other day: snow.  It's only our second snowfall this winter that yielded any accumulation.  After a couple weeks of unseasonably warm weather, Wisconsin must have realized it was in fact January.  Temperatures fell and we received about 5 inches of snow.
   Pictured is rehearsal for Samuel Beckett's PLAY.  I've joined the drama club at school so I try my hand at running lights.  U-Rock has a decent setup.  No one really knows much about though, because no one goes to school here more then a couple years.  So, I've been giving myself a crash course in theater lighting.  Northing's caught on fire, I haven't tripped any breakers and I can put light on the stage, so I can't be doing that bad :)
Here is an algorithm I worked with over 10 years ago that introduced me to sine/cosine:
Xt   = X cos θz - Y sinθz
Yt = X sin θz + Y cosθz
X = Xt
Y = Yt

Xt = X cos θy - Z sin θy
Zt = X sin θy + Z cos θy
X = Xt
Z = Zt

Yt = Y cos θx - Z sin θx
Zt = Y sin θx + Z cos θx
Y = Yt
Z = Zt
    It's purpose is to rotate a point in 3d space.  Adjust for depth and you have a way to spin 3d objects.  I've implemented this algorithm in an SVG graphic.  It's painfully slow in a web browser, but functional.
    I first successfully worked with this algorithm in July of 1996 from an example I had written in assembly.  I recall having problems getting it translated into Pascal, mainly because I forgot about the intermediates—you can't update X to Xt before adjusting Y.  Back when I was working with this example, optimization of the algorithm was key.  Two tricks were used for this: sine/cosine lookup tables and fixed-point arithmetic.  The combination of the two eliminated the need for any floating point arithmetic, except to calculate the lookup tables.  To speed up divisions, everything was turned into a power of two.  The circle was divided into 256 divisions, so angles were denoted 0 to 255.  Fixed-point was done with 32-bit unsigned integers.  The upper 16-bit represented the decimal number and the lower 16-bit the fractional value.  This resulted in the range ±1/2^15 to 2^16 or as small as 0.0000152587890625 to ±32767.  Power of two division was done using bit-shift-right, and with the Intel 386 instruction "sar"—signed shift right.
    After understanding the algorithm, I wrote a 3d rotation function in pure 386 in-line assembly in Pascal.  Turbo Pascal didn't support 386 instructions, but you could do a trick.  Adding "db 66h" before a standard instruction resulted in the op-code using 32-bit register rather then the 16-bit.  So the line "db 66h; shl dx, 16" actually translated to the instruction "shl edx, 16".  It was a neat trick I picked up from some source code to play module music files.
    Building the sine/cosine tables for powers-of-two is pretty easy.  Sn = sin( 2*π*n / N ) where N is the number of divisions in the circle, and n is the current division.  At the time, I didn't know why, but I did understand that 2*pi created a complete sine table.  Sometime latter, I put together 2*pi is the equivalent of 360°, but in the unit of radians.  After learning a little more on the unit circle, I reconized what the 3d rotation algorithm was doing.  The expression Xt   = X cos θ - Y sinθ followed by Yt = X sin θ + Y cosθ when plotted for θ over 0-360° will result in a circle.  Take any point x,y and apply it to the function f( x , y ) = Xt   = X cos θ - Y , Yt = X sin θ + Y cosθ; the point will be rotated by θ.  To do this in 3d, the rotation has to be applied three times: once for X, Y and Z.
    Note that when rotating along the Z-axis, the Z coordinate isn't adjusted.  The same is true of the X coordinate on the X-axis and the Y coordinate on the Y-axis.  This makes sense.  Think of a some object, say a coffee cup.  Move so you are at eye level with the cup, looking directly at the center.  The brim of the cup with be up, the base down.  Now, begin to rotate the cup on it's base.  This is a Y-axis rotation.  Note that through out the rotation, the height (top to bottom) of fetchers is not changing, but their left-right position and depth (front to back) is changing.  The algorithm supports this observation.
    Anyhow, I couldn't resist trying an SVG implementation of my first 3d experiment.  Despite great advances in speed, this example runs slow using only 27 (3*3*3) points.  My original program used 1,000 (10*10*10) points and ran at a higher update rate on a machine 1/10th the speed.

January 13, 2007

Piston Travel Animation

    Here is something I've been working on for the last couple of days.  In trigonometry, we're learning how to transform functions that include sine, cosine, tangent, ext.  At my previous job, I worked with an algorithm to translate crank shaft angle to piston height for an internal combustion engine.  The algorithm was rather confusing, and didn't work for 0 degrees which created a divide by zero condition.  At the time I was using this algorithm, I did want to break it down, understand what it was trying to do and come up with something that did the same thing without the divide by zero condition.  But I lacked the math skills to touch it.  Now, I've re-examined the algorithm.  On the net, I found a couple of alternative transform function and set about proving all the algorithms are identical.  (Yes, I spent my Friday evening writing mathematical proofs).  I wasn't able to do break the initial algorithm down algebraically, although that should be possible—I wasn't sure how to approach "tan( arcsin( n ) )".  I was able to demonstrate the sections of the algorithm visually, and why they all resulted in the same answer. 
    After completing the proof, I wanted to model the motion.  My experiences using Javascript to preform animation (the snowfall in the logo) showed me Javascript in XHTML for animation just wasn't going to cut it.  So I decided to learn something new: Scalar Vector Graphics (SVG).  Turns out that is exactly what I was looking for.  It actually allows the use of Javascript (or something similar, it calls it "ecmascript") to manipulate the elements.  In no time, I had a working demo of crank and piston motion. 
    The animation shows the areas of the algorithm as I have labeled them in the proof.  The circle represents the crank shaft.  The blue line from the center of the crank shaft to the edge represents the arm.  Its length is constant.  The blue line from the crank arm to the gray box represents the tie rod, which also has a constant length. 
    The other lines represent other important measurements.  h divides the triangle into two right triangles.  When that is done, you get two sides: y (brown) and y' (green).  y + y' = piston height. Note that y can be negative.
    When I started writing this article, I wanted to include the equations that make this work.  There is a system called MathML that is supported by web browsers.  Unfortunately, what OpenOffice Math outputs and what Mozilla works with are not the same.  Either you can look at the MathML file alone (which render correctly), or you can re-write the equations with some crazy system that isn't exactly the same and that I never made work.  I didn't feel like exporting a bunch of image files either.  So, that's that.  No equations. :(

1 comment has been made.

From Ericasaurus Rex


August 29, 2009 at 11:08 PM

Understanding this makes me feel smart.
Painting with Laser Light

Painting with Laser Light

    I spent most of the day working on trigonometry, starting with homework in the morning and then writing a proof for piston motion in the evening. 
    Pictured is an experiment I did painting with laser light.  Using manual exposure, I setup a 30 second shutter time in a dark room. Then, using a laser, swept over the area in frame.  The result: a room lite by lines of laser light.  Turned out kind of neat.

1 comment has been made.

From Nick


January 22, 2007 at 10:44 PM

Awesome picture. :) You are quite the photographer.
The Loft

The Loft

    There has been a lot of work to get the Garage put back in order after the building of the loft, but finally things are organized enough to warrant a picture.  So here is the loft.  As you can see, there are no vertical supports.  The loft mounts directly to the studs on the wall.  On the right side is a latter constructed out of part of the old bunk bed.  The top of the loft has a railing that is fairly sturdy-- a good thing if you have a bunch of rowdy gamers up there.
    I did some updates today on the Indigo Dragon.  We are now running Apache 2.2.3, PHP 5.2.0 and OpenSSL 0.9.8d as well as the latest Debian updates.  I saw that PHP had a few new fetchers, but didn't really look into them.
    I started listening to a 24 part lecture on the origins of life by Robert Hazen.  Absolutely fascinating, especially the field of emergence.  There is a developing system of mathematics being used to define now complex system function.  Emergence shows how unordered things (such as grains of sand) when put in the right conditions, come to form complex systems (such as sand waves).  Emergence demonstrates that not everything simply get more chaotic over time.  When there is energy, things can group and form structures from what was otherwise disorganized.  It's a natural way from which to build up, as compared to the universes standard model of entropy where everything falls into disorder.  Everything from little sand waves to spiral galaxies to the very building blocks of life itself.
Order from disorder is a scientific rarity.
Allow me to explain it with a little bit more clarity.
Did I say rarity? I meant impossibility,
at least in a closed system there will always be more entropy.
MC Hawking - Entropy
    Keep in mind a "closed system" is one where no outside energy is introduced.  In open systems, where there is external energy added to the equation, emergence demonstrates you can go against entropy, and it is possible to have order from disorder.  Neat stuff.