Moments of Inertia for Triangles and other Polygons

In my previous two articles I discussed collision detection and response between rigid bodies. In order to do proper collision response between rotating objects, we needed to calculate the moment of inertia about their center of mass. Here I’m going to describe how to get the moment of inertia for an arbitrary triangle, and then I’ll show a triangulation algorithm to apply this to any polygon. Right Triangles The first step is going to be calculating the moment of inertia for a right triangle, since we can get a simple closed formula. Let’s define the right triangle as having a width w and a height h, rotating about the origin with a uniformly distributed mass of density ρ. We know the area is equal to wh/2 so we can calculate the density if we only have the mass. ...

December 15, 2020 · 9 min

2D Rigid Body Collision Response

This is a followup to my previous article regarding collision detection between arbitrary polygons. Today I’ll be explaining how to update the linear and angular velocity of these polygons in response to that collision. I’m going to go about this with perfectly elastic collision in mind, so both momentum and kinetic energy will be conserved. At the end I’ll show how to tweak the formula slightly to change the elasticity with a coefficient of restitution. ...

December 12, 2020 · 7 min

2D Parametric Collision Detection

Today I’m going to describe a method for detecting collisions between arbitrary polygons in 2D. This is part one of a two-part series, in the next post I will show how to make use of this collision detection info to do collision response. Many collision detection methods simply test for intersection between the two polygons - but what if they are moving at high speed? What if you have a point mass that is supposed to collide with a line? In some cases testing for intersection alone will result in objects clipping through other objects - and simple intersection tests won’t tell you the time of collision, the point at which collision occurred, or the normal to the surface of collision, all of which are important for proper collision response. This method will allow us to calculate all three. ...

December 8, 2020 · 6 min

Nightcrawlers Game Art

Some original game art for my latest project, a survival platformer called Nightcrawlers. More to come!

November 20, 2016 · 1 min

Gravity Simulation of the Solar System

I was curious about how easy this would be to do, so the other day I took the leap and wrote a simple gravity simulator with the Earth and Sun. I googled for “planet table” and used the data from NASA’s public planetary fact sheet. I used the average distance from the Sun and average orbital velocity to set initial conditions for the Earth. After applying the law of gravity, I got a nice circular orbit. The masses, distances, and velocities I used are all accurate, but the diameters are much larger than in the actual solar system. With the diameters at the proper scale, the sun would be a tiny spec and the earth would be invisible. ...

August 28, 2016 · 2 min

Some Simple JavaScript Art

I’ve been seeing this sort of art everywhere, with moving points connected by lines that are more solid the closer the points are to each other. It’s fun to watch and seemed like a simple effect to replicate, so here is my take on it. Click on the animations below to show them individually. If you are on a phone the animations will probably lag when they are all running on this one page. ...

July 7, 2016 · 1 min

Consolite, a Tiny Game Console on an FPGA

If you wish to make a game from scratch, you must first invent the universe. Hardware source | Tron source | Circles source | Emulator source | Assembler source | Compiler source For my latest project, I am diving back into Verilog to create the hardware side of Consolite. For those who don’t know, Consolite is the name I’ve given to my design of a tiny hobbyist game console and associated software toolchain. In my previous posts, I demoed a compiler that translates from a flavor of C to Consolite Assembly, an assembler that translates from Consolite Assembly to binary files, and an emulator that runs the resulting binaries. ...

June 8, 2016 · 6 min

Spaceship.codes - A Game for Programmers

Source code (MIT License) After a few months of development, I’m proud to announce the first release of spaceship.codes! Spaceship.codes is a browser game for programmers, with a built in code editor that the player uses to write JavaScript to control their spaceship. I will illustrate this with a simple example; it might be helpful to open spaceship.codes in a new tab so that you can follow along. First we need to load a level. We can do this by clicking the “Select Level” button, then clicking the first level (named “Thrust”), and finally clicking the “Load” button. After the level is loaded, you should see something like the following: ...

April 2, 2016 · 3 min

Dana Scully in Colored Pencil

Click for larger image. In honor of the X-Files premiere tonight, here is my attempt at a portrait of one of my favorite characters — “The Skeptic”, aka Special Agent Dana Scully.

January 24, 2016 · 1 min

Calculating Centroids of Non-Intersecting Polygons

What Is a Centroid? The centroid is a geometric property of a shape, somewhat related to the center of mass. It is the point denoted (x̄, ȳ) that is the average of all points in the shape. For example, in a rectangle the average of all points in the shape is dead center, as shown in Figure 1 below. Figure 1. The average position of all points, or centroid, of a rectangle is precisely in the center of the shape. ...

December 23, 2015 · 9 min