Rotating Hypercubes

The discussion of dancing pendulums in javascript at SSSF led onto Rotating Hypercubes, which resulted in this javascript animation by forum regular mollwollfumble:

4D Rotations (click to view in a new window, right click to download javascript file)

See the SSSF thread for discussion on how to do these things in javascript.

Also see:

Background on the geometry of hypercubes (contains animated applets, but they don’t seem to work in IE9)

John Baez on the geometer H.S.M. Coxeter

First 31 pages of Coxeter’s Regular Polytopes 

And a nice animated gif from http://www.123opticalillusions.com/:

Update 27-Jun-11:

As noted in the comments, we had covered rotating 4D hypercubes here before (in a spreadsheet provided by Lori Miller), and I’d forgotten all about it!  The video link below shows what it looks like, but for a good look at the workings, click on the link: Hypercube.xlsx, then download the file, and have a look at the range names.

Posted in Animation, Maths, Newton | Tagged , , , | 5 Comments

Yet more pendulums

Following Dynamically Defined Dancing Pendulums, another three versions of the dancing pendulum theme.  First a POV-RAY version by PM 2Ring, complete with reflections and shadows:

POV-Ray Pendulums (click to open in a new window)

and an interactive Javascript version:

Javascript pendulums by PM2Ring (click to view, or right click to download the javascript file).

Discussion and code for the javascript version can be found at the ABC (Australia) Tech-Talk Forum.  The pendulum code is spread over three forum posts (because of forum limitations on post length), but the complete HTML file can be downloaded by right clicking on the link above.  The Tech Talk discussion also has code for a very nice animated butterfly (also by PM 2Ring):

Javascript Butterfly

Fianally Hui, a regular guest contributor at Chandoo’s Pointy Haired Dilbert Blog, has done an in-Excel version, using a scatter (XY) chart.  This is where I started, but I wasn’t able to get a smooth animation.  The secret is to use named formulas for the pendulum positions, linked to the chart ranges.  Hui gives detailed descriptions of the procedure at two blogs:

The Excel Hero Blog gives detailed descriptions of the formulas for the pendulum motion, and how to link these to named formulas, and

Chandoo’s Pointy Haired Dilbert Blog gives more details about how to automate the process.  Both posts contain links to the Excel file with working animations and full open source code.

Posted in Animation, Excel, Newton, Ray Tracing | Tagged , , , , | 1 Comment

Debugging VBA …

… especially User Defined Functions (UDF’s).

This post (and most likely several to follow) was prompted by a recent discussion at Daily Dose of Excel about various alternative debugging techniques.  It reminded me (if I had ever known) of the Debug.Assert command, but also that there are many ways to reach the same end when debugging, and the methods habitually used may not be the most efficient.

The steps in debugging an application are:

  1. Find the ways in which it does not work as intended (and for all but the most trivial application there will be some).
  2. Find the source of the errors
  3. Fix them
  4. Return to 1 until there are no more errors to be found

For any application, but particularly for engineering applications, proper attention to stage 1 is of key importance, but it’s stage 2 that tends to get all the attention.  Where possible, I like to set up an on-spreadsheet (no VBA code) prototype of any application, and use this in the debugging process.  The intermediate results of VBA code can then be compared with the values on the spreadsheet, allowing detailed comparison and detection of errors with minimum effort.

This post will describe the tools and techniques that I tend to use, and following ones will look at some of the alternatives.  The example application will be a UDF to find the ultimate bending capacity of a circular reinforced concrete section, using a parabolic/rectangular stress block.  The stages in the analysis are:

  1. Determine the stress block shape, depending on the strength of the concrete, following the Eurocode 2 procedure.
  2. Find the depth of the neutral axis (by iteration) such that the total reaction force in the concrete and steel is equal to the specified applied axial load.
  3. Take moments of all the forces about the centre of the section.
  4. Apply the reduction factors specified in the applicable code.

The main UDF (CircU) calls a number of other functions to perform the necessary calculations, and these have been written so that they can also be called directly from the spreadsheet, which greatly aids the debugging process.  As an illustration, the screenshot below shows the code window for the function StrainLim(), which calculates the strain limits defining the stress block shape.  A “break point” has been set up in the code window, by clicking in the left margin, adjacent to a line of executable code (i.e. not a blank line, comment or Dim statement).  The function has then been initiated from the spreadsheet by:

  • Selecting a cell containing a call to the function (cell K4 in this case)
  • Press F2 to enter edit mode
  • Press Ctrl-Shift-Enter to exit edit mode, causing the function to recalculate.  (Ctrl-Shift-Enter is required because the function Strainlim returns an array.  Ordinary functions returning a single value are entered just with the Enter key)

This procedure is required because the procedures for running a Sub procedure from the VBE code window do not work with a function.

When the function is recalculated the code runs as normal until it reaches the break point, where it stops with the line of code highlighted in yellow.  At this point the code window (as displayed below) displays the value of any variable if you place the cursor over the variable name, and also lists all the variables in the current routine in the “locals” window, to be seen underneath the code window.  In the screen shot the StrainA array has been expanded to display the value of each item.  There are also other methods to retrieve the current value of any code variable, which will be examined in later posts, but they all share two major inconveniences:

  • Viewing data in a large array is slow and cumbersome
  • The data is not available for use on the spreadsheet, making comparisons with spreadsheet data difficult.

Both of these problems are avoided by writing the data back to the spreadsheet in the form of a UDF array.  In the screenshot column J (rows 6 to 12) shows the spreadsheet calculated values, and column K contains the UDF values, which can quickly be checked to be identical.

Returning results from the Strainlim function directly (click for full size view)

An alternative approach is to insert code in the main function (Circu) to return the results of the call to the Strainlim function, if a specific flag is set.  In this case the Circu function has a parameter “out1” which controls the output type.  If out1 is set to -1 the function will return the StrainA array, via the Circu function (where Circu calls Strainlim):

Strainlim results called via the Circu function

In this case either approach could be used because all the input to strainlim is available on the spreadsheet, but in cases where the called function requires data calculated within the VBA routine the second approach is necessary.

Having checked the results of the Strainlim function the options are:

  • Press F5 to continue running the code following the break point, either until completion, or if the break point was in a loop until execution returns back to the break point.
  • Press F8 to step line by line through the code.
  • When the code reaches a sub-routine (or function) press F8 to step through the subroutine or Shift-F8 to run the sub-routine code and stop at the next line in the main code.
  • To run through to a subsequent line in the code, either enter a new break point and press F5, or select the line and select “Run to cursor” from the Debug menu or the right-click menu
  • To run the code from a line other than the following line, select the line (which may be either before or after the break line) and select “Set next statement” from the  Debug menu or the right-click menu.
Posted in Excel, UDFs, VBA | Tagged , , , | 2 Comments

Dynamic Maps

Some sites providing information about the world in the form of regularly updated maps:

NASA Earth Observatory

Includes regularly updated satellite images and maps of satellite obeservations:

Image of the day (click for full size view)

Global Maps

Global Maps Sample

USGS Earthquake Maps:

Global View, last 7 days

New Zealand

Planefinder:

Locate planes equipped with satellite identification equipment, including flight number and destination:

Gloabal View

Zoom in to see who is flying over your roof:

Local view

Near Map:

High resolution photo-street maps; regularly updated with option to view earlier photos (currently Australian cities only):

Progress of Port Botany Expansion Project, Sydney:

Port Botany Expansion, 10th May 2010

Port Botany Expansion, 15 Jun 2010

Port Botany Expansion, 1 Aug 2010

Port Botany Expansion, 30 Dec 2010

Posted in Newton | Tagged , , , , | 1 Comment

High Speed Blog …

… brought to you via Smurf on Spreadsheets

If you want your spreadsheets to go faster, Charles Williams is the man to tell you how to do it.  Charles has recently started a blog on the subject: FastExcel

Well worth a quick look.

Posted in Excel, VBA | Tagged , , | Leave a comment