Lessons taught; Lessons learnt

Maths, teaching and beyond.

Archive for the ‘animation’ tag

A conic mini-world

without comments

Sorry, the GeoGebra Applet could not be started. Please make sure that Java 1.4.2 (or later) is installed and active in your browser (Click here to install Java now)

(Source: conic_family_plot.ggb.)

Questions and suggestions

Press the play button, and the red curve will animate, showing you some of the possible curves you can get by changing a, b, c and d.

Click 'show controls' and you can alter a, b, c and d yourself. You can also click the checkboxes next to a, b, c or d to see a 'family plot':

These family plots will also animate (and look quite pretty when they do!).

  • What are the values of a, b, c and d in the red curve?

    [Answer: at the start, they are all equal to 1.]

  • What types of curves would you get for other values of the constants?

    [Answer: The curves you get from these equations are ellipses and hyperbolas.]

The equation is a special case of the equation ax^2 + bxy + cy^2 + dx + ey + f = 0, which generates all conics.

As well as being a pretty thing to have in my room as a class enters, it could also serve as the basis of investigations into conics (either in the special case shown in the applet, or in general). For example:

  • Can we tell by looking at an equation whether it will be an ellipse or a hyperbola?
  • Can we tell by looking at the equation whether any points will appear at all, or whether the equation has no solutions?
  • Can we classify all the equations which go through one/two/three/more specified points?
  • Can we go backwards, from a diagram we want to the equation?
  • Why do the family plots look like they do?

Written by Jon Ingram

February 27th, 2010 at 7:40 pm

Posted in Maths, Resources

Tagged with , ,

Wheels within wheels: A gallery of epicycles

with 2 comments

Modelling the solar system

If you look at the night sky, the majority of the stars stay in the same position relative to each other, but others are more interesting -- they tend to wander around, sometimes moving one way, and sometimes the other:

Sorry, the GeoGebra Applet could not be started. Please make sure that Java 1.4.2 (or later) is installed and active in your browser (Click here to install Java now)

In this animation the blue circle is moving at constant angular velocity, while the white circle represents the more complicated apparent motion of a planet.

This variable motion (technically called prograde and retrograde motion) caused problems to people trying to create early models of the solar system. Obviously (to them) the Earth needs to go at the centre, and obviously the planets should travel in circles around the Earth (as the circle is the most perfect shape), but this doesn't account for the motion we see.

Around 2000 years ago, the astronomer Ptolemy introduced the concept of epicycles to explain the motion of the planets. Select all the 'Show' check boxes in the animated environment above, and you will see the following:

circles-in-circles

The large blue circle is the deferent, and the pink one, which is centred on the deferent, is the epicycle. In our model we have a third, smaller circle, centred on the epicycle, and futher complicating the motion of the planet. This was not a feature of Ptolemy's original model of the solar system (which used 34 circles), but were sometimes introduced in more complicated refinements of the model.

Each of these circles move at different rates, and it's the movement of these circles that, in Ptolemy's model, causes the variations in motion (and in brightness) of the planets. You can control the size and speed of each of these circles using the sliders at the bottom of the environment. You can also pause/restart the animation, choose which of the circles should be drawn, and draw the orbit of the planet (there will be more on orbits in the next section!).

Note that both of the epicycle circles are much larger than those that Ptolemy used -- by far the most important component of motion was given by the deferent.

Orbits and apparent motion

After we have set up a system like this, one natural question to ask is: so, what does the orbit of our planet look like? Selecting the 'Orbit' option, we see the following amazing path appear:

circles-with-orbit

My focus for the rest of this post is going to be on these orbits, rather than using epicycles to model the solar system. If you're interested in the actual Ptolemeic model, here are two excellent sites for further exploration.

Before we move on to just looking at the orbits, though, I should point out that it can be very difficult to figure out what the size and speed of the epicycles should be, given the apparent motion (which is what you actually observe). Going the other way can be interesting, as well. Here are two examples of settings to explore:

First,  (1,1), (0.5, -1), (0.5, 3). Graphically,
interesting-orbit-05-1053-settings

This has orbit:

interesting-orbit-05-1053

Second, (1, 1), (1, -1), (0, 0), with orbit

interesting-orbit-1-100

What will the apparent motion of the planet be for each of these? Set them up in the interactive environment at the start and see if you were correct!

A gallery of orbits

Here's a simplified version of the environment above, concentrating on the epicycle orbits:

Sorry, the GeoGebra Applet could not be started. Please make sure that Java 1.4.2 (or later) is installed and active in your browser (Click here to install Java now)

The parameters are exactly the same as for the original animation: the size and speed of the three generating circles.

Playing around with this a while, you find that altering the 'size' parameters tends to continuously alter the final orbit, while tiny changes in the 'speed' parameters can lead to major changes in the orbit. It's actually even worse than it seems! I have deliberately chosen the 'speed' divisions to guarantee that the orbits will be closed, after a maximum of 10 revolutions. Can you see how? If so, you should be able to figure out which combinations of settings give you orbits that repeat after 2, or 5 revolutions of the first circle.

If we happened to choose an irrational value for one of the speeds, then the orbit would never exactly repeat, and we would end up with our orbit picture looking like a filled doughnut.

Here are some of my favourite orbits:

epicycle-1-2905-2epicycle-05-2105-3epicycle-05-21051epicycle-05-20319epicycle-05-1501539epicycle-05-0805-35epicycle-041803-22epicycle-04170827epicycle-06-260222

(Click on these to see them at a larger size.)

All of them were generated by keeping the size/speed of the first circle as 1 and 1, and only varying the other four parameters. It's amazing the variation in shapes you can get from such a simple set up.

If you are interested in printing these out, I have made a PDF of the orbits: epicycle-orbits.pdf. You can also download SVG files of these orbits, for editing in a vector drawing package such as Inkscape: epicycle-orbits.zip.

I have deliberately not told you the parameters for these, although the file names will give a hint! I would love to see any other interesting patterns that people find.

Orbits and Spirograph patterns

These epicycle orbits are related to (but not the same as) Spirograph patterns, more mathematically called hypocycloids and epicycloids:

These are generated by having circles rolling around the outside (or inside) of other circles. You can see the relationship if you compare the parametric equations for our curves:

x(t) = r_a \cos( \theta_a t) + r_b \cos( \theta_b t) + r_c \cos( \theta_c t),
y(t) = r_a \sin( \theta_a t) + r_b \sin( \theta_b t) + r_c \sin( \theta_c t).

with those for 2-wheel Spirographs, with circles of radius R and r:

x(t) = (R-r) \cos(t) + p \cos ( \frac{R-r}{r} t ),
y(t) = (R-r) \sin(t) + p \sin( \frac{R-r}{r} t ).

If you are interested in plotting Spirographs, a great link is this very detailed Linux Gazette article explaining how to plot them using Gnuplot.

The interactive environments above are written using Geogebra. Please feel free to download and play with either the full environment, or the orbit-only environment. Opening these files in Geogebra will let you explore exactly how I created them.

Written by Jon Ingram

April 3rd, 2009 at 12:35 pm

Curves and splines for fun and profit

with 2 comments

Imagine you are given some points, and asked to join them together. Probably the easiest way to do this is to use straight lines:

connected-with-straight-lines

What if we wanted the line joining these points together to be a curve, rather than a sequence of straight lines? Even better, to be a smooth curve (in other words, to not have any sharp changes in direction)? One of the simplest ways to do this is to move into the world of Bézier curves.

The geometry of Bézier curves

Beziér curves are a class of surprisingly easy to generate curves which can be specified completely by a small number of points. Here is how to geometrically construct the two most common types of Bézier curve:

First, a quadratic Bézier curve:

To see this Geogebra worksheet, please enable Java.

Second, a cubic Bézier curve:

To see this Geogebra worksheet, please enable Java.

(Both of these are interactive -- move the blue points around and see how the curve changes.)

It should be obvious that we could continue this process with more and more control points to get Bézier curves of even higher orders.

From curves to splines

These curves are very nice, but they only go through the first and last points, with the others acting like 'control points', influencing the direction of the curve. If we create a Bézier curve using all the points given earlier, for example, we get this:

degree6-bezier

To connect up the points we are going to need to join together several of these Bézier curves, to form a spline. The full theory of splines is very complicated, but we can make a good start by connecting together a bunch of cubic Bézier curves:

curve-to-spline

If you have ever used a vector graphics package (like Inkscape, Illustrator or Coreldraw), this is exactly how they create paths through specified points. They tend not to draw the line segment connecting the two control points together, which makes the path look like this:

Sorry, the GeoGebra Applet could not be started. Please make sure that Java 1.4.2 (or later) is installed and active in your browser (Click here to install Java now)

Playing with the path above, you soon notice that it is very easy to get kinks (cusps) at the points where the Bézier curves meet. We can avoid this by making sure that the control points before and after a curve point are on the same straight line. Drawing packages also usually make the control points the same distance away from the curve point, giving you something like this:

Sorry, the GeoGebra Applet could not be started. Please make sure that Java 1.4.2 (or later) is installed and active in your browser (Click here to install Java now)

There is still too much choice here, though -- remember that we have just been given the points for the curve to go through. We can get a fairly nice curve, which just depends on one parameter (the 'curviness', lambda), by setting the control points as follows:

Given points X_0 up to X_n, for i \in \{1, \ldots, n-1\}, set the control point to the left of X_i to be X_i - \lambda \overrightarrow{X_{i-1} X_{i+1}}, and the control point to the right of X_i to be X_i + \lambda \overrightarrow{X_{i-1} X_{i+1} }.

In other words, the line between the two control points is parallel to the line between the two neighbouring curve points, and the distance is proportional to the distance between the curve points.

We also need to decide what to do with the control points of the ends of the curve, X_0 and X_n. Probably the simplest thing to do is to set the control points equal to the curve points themselves.

This gives us something like this:

Sorry, the GeoGebra Applet could not be started. Please make sure that Java 1.4.2 (or later) is installed and active in your browser (Click here to install Java now)

I call the parameter the 'curviness', because the spline becomes more and more like a collection of straight line segments the closer lambda is to 0. The higher the value of lambda, the more pronounced the curve is -- and interesting things happen if lambda becomes negative!

Solving our original problem

We can now solve our original problem, by connecting our collection of points together with an appropriately generated set of Bézier curves. We might decide to have an 'open' curve (with endpoints):

Sorry, the GeoGebra Applet could not be started. Please make sure that Java 1.4.2 (or later) is installed and active in your browser (Click here to install Java now)

or indeed to create a 'closed' curve, treating all the points equally:

Sorry, the GeoGebra Applet could not be started. Please make sure that Java 1.4.2 (or later) is installed and active in your browser (Click here to install Java now)

Why not see what different types of shapes you can generate from these seven points? How close to a perfect circle can you get, for example?

Further notes

Without realising it, you have been looking at Bézier curves for years: every scalable Truetype font is defined using quadratic Bézier curves, and many other font systems use quadratic or cubic ones. The mass use of scalable fonts (first popularised in the Postscript printing system) was a major innovation, rendering the old bitmap system, where fonts came in one particular pixel-based size, almost entirely redundant.

Interestingly, Bézier was not the first person to discover, or to work with Bézier curves. One of the most common algorithms for drawing Bézier curves is due to de Casteljau, who was working with Bézier curves several years before Bézier! 

Although probably the most common, Bézier curves are certainly not the only choice to use for splines. If you are interested, see this Wikipedia article for more information than you probably wanted on the deeper mathematics behind them.

A Geogebra postscript

All the interactive sections above were generated using Geogebra. Double-clicking on any of them will open the interactivity in its own window, where you can save it to your computer, or explore how it was generated. If the interactivities are not there, then the Geogebra website is probably down!

One of the features introduced in version 3 of Geogebra is custom tools. I have created one of these custom tools which will let you easily create cubic Bézier curves. Simply open the following file: cubic-bezier-tool.ggt, and you will see a cubic Bézier tool appear in the toolbar.

Appendix: The algebra of Bézier curves

The reason for the names 'quadratic' and 'cubic' becomes clearer when we try to figure out an algebraic way to generate Bézier curves. It is apparent from the geometric construction that the key to constructing these curves is to move a certain proportion of the way between pairs of points, and then repeat this process until we have only one point, which will trace out the Bézier curve.

We will build up the formulae from the simplest case:

linear-bezier

Straight lines (linear Bézier curves): If t is a parameter between 0 and 1, then the point tth of the way between A and B is P_{AB} = (1-t)A + t B. As t changes, P_{AB} will trace out the line segment AB. This is sometimes called linear interpolation.

quadratic-bezier

Quadratic Bézier curves: We are given points A, B, and C. From these we generate the two points P_{AB} = (1-t)A + t B and P_{BC} = (1-t)B + t C. Moving tth of the way between these two points we generate P_{ABC}:

eqn5007

Rearranging and simplifying, we get

P_{ABC} = (1-t)^2 A + 2 (1-t) t B + t^2 C.

This will trace out our quadratic Bézier curve.

cubic-bezier

Cubic Bézier curves: We are now given four points, A to D. We can generate two quadratic points, P_{ABC} and P_{BCD}, with equations as above. Combining them, we get P_{ABCD}, which will trace out our cubic Bézier curve. The simplified form of its equation is:

P_{ABCD} = (1-t)^3 A + 3 (1-t)^2 t B + 3 (1-t) t^2 C + t^3 D.

We could continue this as far as we wanted, to get equations for higher order Bézier curves.

Written by Jon Ingram

March 31st, 2009 at 10:56 pm

Geogebra 3.2 beta: Now with animation

without comments

The next version of Geogebra is nearing release, with quite an impressive list of changes and additions. One of the key additions, for me, is the integration of animation into Geogebra itself. It takes the approach of animating sliders: you can specify the increment, the speed, and what to do when you hit a boundary (bounce, or repeat).

At first I didn’t think there was any way of getting the animation to start automatically, but it looks like all you need to do is to save the worksheet with the animation running. It will then still be running when you reload it. This means we no longer need Javascript to kludge together animated Geogebra files on webpages.

Here, for example, are some animated rotating squares, which originally appeared in non-animated form last year:

You need to enable Java to see this Geogebra applet.

(Source: rotating_tesselation_2.ggb)

The only change I had to made was to alter the animation properties, right click on the slider, and select ‘Animation On’. To put it on the webpage I basically copy-and-pasted the ‘applet’ tag from the ‘Dynamic Webpage’ export option. No extra Javascript is needed.

The pre-release isn’t quite ready for prime time yet (when I tested it, it had a habit of losing its containing window, for example), but I look forward to spending some time exploring the other features, like the spreadsheet view. There also seem to be a whole host of statistics-related features (such as the drawing of histograms and box-and-whisker plots).

Written by Jon Ingram

March 27th, 2009 at 8:08 am

Visualisation: Six moving lines

without comments

As promised, here is an animated Geogebra visualisation. Click ‘Start’, and six moving lines will appear.

  • What behaviours do the lines exhibit?
  • What relationships are there between the different lines?
  • How are these lines defined?


Geogebra applet (enable Java to see it).

(Source: movinglines.ggb and movinglines.html.)

Click on ‘Show Values’ and three values will appear — all six of these lines are generated from these three values. If you click on ‘Stop’, and move the sliders, then the lines will be automatically updated to reflect those new values.

  • Can you make any conjectures now about how the lines are defined?
  • What values would we need to make one (or more) pair of the lines
    • perpendicular?
    • parallel?
    • vertical?
    • horizontal?
  • Can we generate any line we wish by setting the values appropriately?

I managed to captivate both a lower school class and an A-level class with this visualisation for quite a while last year, and the A-level class made good progress in making and justifying conjectures about what was going on.

Technical Note

One of the few downsides of Geogebra compared to other dynamic geometry software, is that it contains no in-built facility for animation. Thus, to create any animations using Geogebra, you have to create the animations manually in Javascript. It’s not particularly difficult to do, particularly if you know some Javascript, as you can see if you view the source of the .html file above. Putting the ability to animate inside Geogebra itself is, though, my one big wish for future versions.

Written by Jon Ingram

August 29th, 2008 at 11:04 pm