I loved the question that Steve recently asked on his blog about what your earliest computer experiences were. It brought back a lot of memories, but quickly turned into something that's too long for... read more >>
I loved the question that Steve recently asked on his blog about what your earliest computer experiences were. It brought back a lot of memories, but quickly turned into something that's too long for a comment on his blog. I thought it would be worth sharing here, because I was extremely lucky to be in the right place at the right time, and I saw the world of computing change suddenly and dramatically. If you're interested in the computer graphics (I assume you are if you're reading this blog), then it's a bit of history that you should probably know about. I first started using computers when I got to MIT in 1976. At that time, we were writing our code on IBM 029 keypunches. And we were preparing our data using ...read more >>
The dodecahedron is a particularly interesting polyhedron. It's full of interesting five-fold symmetries. Let's take a look at a couple of them.
First we'll need the vertices. There's an interesting pattern to them.
p = (1+sqrt(5))/2; q = 1/p; verts = [-1 -1 -1; ... -1 -1 1; ... 1 -1 1; ... 1 -1 -1; ... -q 0 -p; ... -p -q 0; ... 0 -p q; ... -p q 0; ... 0 -p -q; ... q 0 -p; ... -q 0 p; ... 0 p q; ... p -q 0; ... 0 p -q; ... p q 0; ... q 0 p; ... -1 1 1; ... -1 1 -1; ... 1 1 -1; ... 1 1 1];We can draw them with scatter3.
grey = [.25 .25 .25]; scatter3(verts(:,1),verts(:,2),verts(:,3),'filled','MarkerFaceColor',grey) axis vis3d grid off box onAnd we can draw the edges like so:
s = [1 1 1 2 2 2 3 3 3 4 4 4 5 5 6 7 8 8 10 11...read more >>
Another new feature that I really like in R2016a is the upgraded fplot function and all of the new members of the fplot family.
The fplot function has been around for a long time. The basic idea is that you pass it a function which takes X coordinates as inputs and returns Y coordinates as outputs. Then fplot will use that function to draw a curve.
fplot(@(x) sin(x))This is really useful for getting a "quick feel" for the shape of a function, or a family of functions.
fplot(@(x) besselj(x,1),[0 2*pi]) hold on fplot(@(x) besselj(x,2),[0 2*pi]) fplot(@(x) besselj(x,3),[0 2*pi]) fplot(@(x) besselj(x,4),[0 2*pi]) fplot(@(x) besselj(x,5),[0 2*pi]) hold off legend showIn addition to functions, if you have the Symbolic Math Toolbox, fplot can also accept
...read more >>
One of the features I love in R2016a is the new yyaxis function. This is a new way to create plots which have two independent Y's, like the older plotyy function. Let's take a look at how yyaxis works, and why I think it's cool.
First we'll need some data. This type of chart is really useful for looking for relationships between data which has wildly different values. For example, I'm interested in the relationship between the price of gas and how much people drive. The Federal Reserve Bank of St. Louis maintains a great collection of historical records of all sorts of economic data like this. I can get the price of what they call "U.S. Gulf Coast, Regular" from this page, and load it into MATLAB using readtable.
tgas =...read more >>
As the Wind Blows
NOAA maintains a number of buoys that collect weather data, and they publish the data from them on their website.
There are four of these buoys just outside Boston harbor. They are the red squares on this map.
For example, the data for buoy 44013, which is the bottom one on that map, is available at this URL.
I downloaded the data for 2015, and I can read it into MATLAB like this:
t=readtable('44013c2015.txt','Format','%d%d%d%d%f%f%f%f%f%f','HeaderLines',2); t.Properties.VariableNames = {'YY','MM','DD','hh','mm','WDIR','WSPD','GDR','GST','GTIME'};We can see that there are 52,460 rows in this table. That's one measurement every ten minutes for the entire year.
size(t) t(3805:3810,:) ans =...read more >>
Recently I heard from a MATLAB user who was trying to draw tubes along a curve using this blog post I wrote a while back. Unfortunately her curve was a bit more complex than the ones I used in that post. That approach of sweeping a 2D shape along a curve has a number of interesting edge cases that you'll encounter when your curves are complex.
In particular, her curve actually had a "fork" in it. This is a particularly tough case for the sweep approach. You basically need to sweep each of the two halves of the fork, and then slice off the parts of one sweep that are inside the other one. The math for this gets rather tricky.
Luckily there's another approach to this problem. This one is fairly compute intensive, but it's quite a bit simpler to implement. It's called signed distance fields. Let's take a look at how you would
...read more >>
One type of question that I'm often asked is about how to use various visualization techniques with what is sometimes called "scatter data". This is data that is a list of individual measurements. These measurements often have locations associated with them, but that's not enough for many visualization techniques. These techniques also want grid information. This is information about how the measurements connect to each other. Let's take a look at a couple of ways in which we can get this grid information.
First we'll need some example data. Here I have 250 measurements. Each one has a 2D location and a value.
npts = 250; rng default x = 2*randn(npts,1); y = 2*randn(npts,1); v = sin(x) .* sin(y);Scatter data, which is sometimes known as column data, gets its name from the fact that the scatter plot is the one visualization technique which is really designed for this type of
...read more >>
Last time, when I was talking about permutohedra, we saw how truncated octahedra fill 3D space with no gaps. There are a number of shapes with this property, and they have the lovely old family name convex uniform honeycomb. There's another interesting family that is related to the honeycombs. They're called apeirohedra or "infinite skew polyhedra". You make the apeirohedra by removing some of the faces of a honeycomb. This gives you an infinite set of faces that divide 3D space into two halves. These two halves pass through each other in very interesting and complicated ways.
Today I'm going to take a look at the simplest of these. It's called the mucube. It's basically an infinite stack of cubes with half of the faces removed. I can draw a tiny
...read more >>
In earlier posts we've looked at tiling quadrilaterals and pentagons. So what about hexagons? I'm sure you've seen tilings of regular hexagons. They're popular in floor tiles and game tiles. Even bees know about this one. But there's one interesting feature of this tiling that you might not be familiar with. To see this feature, we need to start in a very different place.
We're going to start by making all of the permutations of the sequence [1 2 3]. As you probably know, for n items, there are n! permutations. So there are 6 different ways we can arrange these 3 numbers.
n = 3; np = factorial(n); pts = perms(1:n) pts = 3 2 1 3 1 2 2 3 1 2 1 3 1 2 3 1 3 2Now we have an array with 6 rows and 3 columns. Since
...read more >>
I recently answered a question on MATLAB Answers about how patch interpolates color data. This is a question I get a lot because it's a bit more complicated than you might expect. Let's take a close look at what it can and can't do.
First we'll need a patch with FaceColor='interp'. I'll start with this simple polygon and use the X coordinate as the color data.
ang = 0:pi/4.5:6; x = cos(ang); y = sin(ang); c = x; patch('XData',x,'YData',y,'CData',c,'FaceColor','interp') colorbarThat’s simple, isn’t it? We can work out what color each pixel should be by inserting the X coordinate into the colormap. But the Patch object is actually doing something a little subtler here. It’s actually creating a set of triangles which subdivide the interior of the polygon and then handing those off to the graphics system and asking it to figure out the color of each pixel in each of the triangles. The graphics system does that using linear interpolation. That works
...read more >>