# I spent about 15 minutes staring at this

What’s wrong with this code:

959  // we don't have a lot of entropy to work with here :\
960  RtPoint2 random_pt( deterministic_float( node->center_luminance, rnd1, (uint32_t)(1280498143 * rnd0) ),
961                      deterministic_float( data_pt->p,             rnd1, (uint32_t)(3584308421 * rnd0) ) );


The compiler error:

foo.cpp:961:100: error: expected ';' before ')' token


Where’s the mismatching paren?

Answer (highlight to view): The “:\” smiley face extends its comment to the next line. My syntax highlighter didn’t pick this up.

There’s probably an underhanded c competition entry in here.

EDIT: It’s occurred to me that, based on the compiler error message, the compiler would have preferred I make a winky smiley face instead.

# Some physics about covering the Earth with Internet

Before I read that Elon Musk’s insanely-huge satellite fleet was to orbit at around 1100 kilometers above the Earth, I did some back-of-the-envelope math to figure out what satellite altitude would be necessary to carpet the planet with coverage. From this came an interesting little exercise in hypothetical logistics.

First, figuring the minimum altitude of a 4,000 station constellation: We can use a formula for the fraction of the Earth visible from a point:

$$A = \frac{1}{2} \left( 1 – \frac{R_e}{R_e + h} \right)$$

…where $$R_e$$ is the radius of Earth, $$h$$ is the altitude of the observer, and $$A$$ is a fraction of the Earth’s surface area. We can divide up the Earth into 4000 pieces and solve for h to know how high a satellite must be to see its portion of the Earth. When we do this, we get…

1.98 miles high.

What.

If you want to blanket the entire planet with internet coverage, and you’ve got 4000 things to do it with, those things only need to be floating about 2 miles off the ground!

Obviously nobody’s putting satellites in two-mile orbits. And we’d like some redundant coverage, so let’s demand that every point on Earth be covered by at least three stations and try again. What do we get? Continue reading

# On Elon Musk’s Ridiculously Huge Satellite Fleet

On Friday, Elon Musk announced SpaceX’s intent to launch a fleet of over 4000 communications satellites, whose primary purpose is to provide a low-latency broadband internet to us Earthlings:

He’s drumming up interest among potential hires for SpaceX’s new satellite branch in Seattle for, fittingly, building satellites.

This is an interesting move. 4000 is a huge fleet— Musk says in the video that this is more than double the number of currently active satellites, but from this database, it looks to be actually more than triple that number.

# Why?

## It’s faster

Currently, to travel a long distance, a packet of data must be routed through thousands of miles of fiber optic cable. Because the fiber is made of glass and is refractive, the speed of light in the cable is about 60% of the speed of light in a vacuum— so this limits how quickly data can go from one place to another on Earth.

Musk plans to route data directly from satellite to satellite through the vacuum of space, bypassing the speed limit of fiber.

Another factor is the number of hops: as a packet makes its way around the internet, it makes pit stops at routing stations, which might hold the data in memory as it waits in line to be sent to the next stop. This takes time, and may happen several hundred times for a long distance communication. This can add up to a significant fraction of a second.

Musk plans to route long distance packets in just a few hops, reducing the delay between endpoints even further. This is possible because each satellite will be in view of many others— it’s possible they’ll transmit data by pointing lasers at each other. For data, it’s the difference between taking the backroads and taking the freeway.

Notably, the proposed fleet would be orbiting at around 1100 km; far lower than the altitude of current high speed internet satellites, which hang out in geostationary orbit. Current satellites 22,000 miles away, which demands a minimum round-trip signal time of about 1/4 second. In contrast, Musk’s satellites will orbit just 3 milliseconds from the surface.

## Money

It seems there is opportunity here to enter a relatively sparse niche. Long distance communication is dominated by fiber, which is expensive to lay. Satellites are expensive too, but in a matter of months that cost will drop enormously— perhaps by an order of magnitude— when SpaceX succeeds in landing its reusable first stage rocket. Elon is in the unique position of knowing exactly how cheap space launches are about to become, and also has the ability to fully reap the benefits of cheap launches without any of the markup that he’ll be charging his competitors.

Musk says he intends to capture about 10% of consumer traffic, and 50% of the “long distance” traffic. This means the network will be focused on backhaul, routing large batches of data between endpoints for telcos and ISPs. It seems he hopes to attract backhaul customers by offering significantly (“order of magnitude”) improved latency over current capability.

10% of consumer traffic is a lot— There are about 2.5 billion subscribers on the internet (that will surely grow), and Musk is therefore hoping for about 250 million SpaceX internet users. That’s incredibly ambitious, although a comparatively small amount of infrastructure (as opposed to laying fiber for the same consumer base) will provide him easy access to the entire globe. If he succeeds, and we suppose a consumer cost of, say, a conservative \$10 a month, that’s a total of 2.5 billion dollars of revenue per month. This would pay off a 15 billion dollar satellite network (Musk’s cost estimate) in just half a year. 10% of all internet subscriber traffic is pretty ludicrous, but if he’s overestimating by a factor of 10, it’s still looks to be easy money. This isn’t counting the backhaul traffic he intends to capture (whose revenue I don’t know how to estimate).

And money is the goal. Musk primarily wants something that will generate cash for his a future Mars colony venture; he seems to believe this will be a cash cow.

## Will I get satellite internet on my phone anywhere on Earth?

Probably not; the radio frequencies SpaceX is likely to get their hands on don’t penetrate buildings. It’s more likely that homes and businesses will need to pay a few hundred dollars for a dish installation on the exterior of the building.

This is maybe something for Musk to worry about; it’s quite possible that in developed countries individual subscribers will soon stop paying for high speed internet at home, and start using their phones, almost in the same way that landlines were outmoded some years ago.

Overall, it appears that Musk is vying to become a major player in the telecom industry. New competitors are rare here, though he did manage to bust into the immensely expensive and entrenched space industry. We’ll soon see how he performs.

# 3D Rotational Dynamics 1: The Basics

If you’re writing a 3D game, or a VFX simulator, or even trying to solve a 3D kinematics equation, you need to be able to compute how objects react to forces; in particular how they will spin. The mathematics of spinning objects can be quite complicated and subtle, and in this series I will attempt to make the concepts clear.

If you’ve taken high school or college physics, you’ve probably somewhat familiar with how rotation works about a fixed axis: Apply a little bit of torque (twisting force), and the object starts to spin. Apply the opposite torque, and it slows down until it reverses. This animation from Wikipedia shows it nicely enough:

A little key for what the arrows stand for:

Symbol Meaning
r Direction from the axis to the point of applied force
F Applied (linear) force
τ Torque (twisting force)
p Linear momentum
L Angular (rotational) momentum

## Wait, why are we using vectors

You’re right; In 2D, we don’t really need vectors; we could just use numbers. But since we’ll be moving on to 3D, let’s get used to our quantities being vector-valued.

## Moving on

This is a little abstract, so let’s use a more concrete example. Since this is the internet, what better way to illustrate this than with a cat gif?

Here, the cat is making the toilet paper roll spin— and he’s doing it by applying a downward force with his paw. This downward force is converted to twisting force— torque— by the fact that the toilet roll can spin freely about a fixed axis, but not move freely in space (otherwise, he’d be batting it across the floor).

We compute the amount of twisting force that Mittens here is applying by taking the cross product of the downward force F with a vector r connecting the cat’s paw to the toilet paper axis:

τ = rF

What this means: Twisting force is stronger with more force, and longer lever arm. The axis of twisting force is perpendicular to the force applied.

Note that for a fixed axis, we must take the part of the force vector which is orthogonal to the axis. Since the roll is held in place from left to right, there can be no net force along this direction. We may need to adjust an applied force to ensure this:

Forthogonal = F – (F · â) â
(â is the unit-length fixed axis)

From the above equations, it may also be apparent that the torque vector is always aligned with the rotation axis, since F and r are defined to be perpendicular to it. (This is not so for free rotation, but we will get to that later). The length of the torque vector shows how much twisting force is being applied, and therefore how quickly the toilet roll is going to spin up.

Using the knowledge that our vectors are perpendicular, we can come up with a simplified scalar version of τ = rF. We’ll also make use of the identity that |a x b| = |a||b|sin(θ):

τ = rF
|τ| = |r||F|sin(90°)
|τ| = |r||F|

Intuitively, this should all make some sense: You can get more twisting force by using a wrench with a long handle, or better yet, a cheater bar (which is a length of pipe you use to extend a wrench handle), when compared to using your hand. The wrench has much longer r than the bolt you’d be grabbing.

The integral of torque is the angular momentum, which is a vector describing how the mass of the object is currently spinning. It is aligned with the axis about which the mass is spinning.

L(t) = ∫τ(t) dt

What this means:  The longer you apply torque, the more rotational inertia your object will have.

After Mittens has applied some torque for a short moment, that integral will be nonzero, and the toilet roll will be spinning:

In the absence of friction, the inertia of the roll will keep it spinning indefinitely. In reality, the roll will rub against the mount and come to a stop after a short time. This tells us that friction can exert torque too!

OK, so that’s great, but if we were coding a game (a cat toilet-roll simulator? See you at the top of the casual gaming charts), how would you compute the position of the toilet roll at each instant of time? Put another way, if I know how hard Mittens/the player swats the roll, and how for how long, can we figure out how much toilet paper has unrolled?

For a fixed rotation axis (like our toilet roll mounted to the wall), the connection between angular momentum and rotation rate ω is pretty simple: There is a factor which relates the two called the moment of inertia, I, which describes the object’s resistance to being spun:

ω(t) = dθ / dt = |L(t)| / I     (2D rotation)

What this means: The rate of rotation of the toilet roll is proportional to the length of the angular momentum vector. The larger the moment of inertia, the more slowly the roll will spin.

It’s harder for a heavy thing to get rolling.

The moment of inertia is computed based on the mass of the object and its distribution about the axis of rotation. More on this later.

From this we can very easily figure out the absolute angle by integrating the rate of rotation:

θ(t) = ∫ω(t) dt

What this means: The rotation angle at any point in time is the cumulative total of the rate of rotation up to that moment.

To this I will add two more equations involving the angular acceleration, α:

α(t) = d/dt ω(t)
τ(t) = I α(t)

## Putting it all together

Now we have enough to make a complete picture of 2D rotation:From this diagram, you can figure out how to relate any aspect of rotation to any other at a glance.

I find this much easier to understand and navigate than a set of written equations; this way it’s clear how the information flows. You could start at the bottom with information about torque, work your way up, and figure out how the object is oriented; or you could start at the top with a changing angle, work downwards, and figure out what the torque is. Because there are some redundant equations, you even have a choice of paths/methods!

Neat!

## But all of this is useless for 3D

OK, well, not useless. It’s really pretty important that all the above makes sense so that we can understand things when we get to 3D. And believe me, dear reader, it gets crazy. Take a look at the video, taken on the International Space Station, which inspired me to try and simulate 3D rotational dynamics in the first place:

What. The. Hell.

What’s going on here? I assure you that there is nothing special about that handle; there are no tiny rockets on it, or fluid inside, or anything else weird. It’s just a T-shaped thing. Nothing is touching it to make it flip like that, so there cannot be any torque. What the hell is happening?

I’ll give a little preview of things to come: This phenomenon is called torque-free precession. You rarely see it on Earth because most of the spinny-things you deal with from day to day are fixed to axles, and are governed by the simple equations above.

More complicated cases like spinning tops still have some amount of torque applied, because they are resting on a surface like a table, and the weight of the top tries to tip it over. Pretty much only in free fall or zero-G can you see something precisely like the above, so not surprisingly, we Earth-bound humans have zero intuition for it.

To begin understanding how we can simulate the physics of the T-handle, we’ll have to wait for the next installment!