a. Choose a random centroid X, Y and Rotation for a Hotdog3. Repeat step 2
b. Calculate X & Y position of each end
c. Check if the Hotdog intercepts a line
d. Draw the HotDog
e. Record the throws status
f. Tally results
Sub Setup()The Column sizes aren't important but from an aesthetic point of view it looks better if the hotdogs are within a defined area.
Const HotDogLength As Double = 49.5
Worksheets("Throw").Select
Range("A1").Select
Application.ScreenUpdating = False
'Cleanup old hotdogs
CleanUp
'Setup the Throw Sheet
Columns("A:A").ColumnWidth = 1.43
Columns("B:K").ColumnWidth = 10
Rows("1:5").RowHeight = 19.5
Rows("6:17").RowHeight = HotDogLength
Rows("18:1048576").EntireRow.Hidden = True
With Range("B6:K15")
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
With .Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ThemeColor = 2
.TintAndShade = 0
.Weight = xlMedium
End With
With .Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ThemeColor = 2
.TintAndShade = 0
.Weight = xlMedium
End With
With .Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ThemeColor = 2
.TintAndShade = 0
.Weight = xlMedium
End With
With .Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ThemeColor = 2
.TintAndShade = 0
.Weight = xlMedium
End With
With .Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ThemeColor = 1
.TintAndShade = 0
.Weight = xlMedium
End With
End With
Range("Runs") = 200
Range("Runs").Select
Application.ScreenUpdating = True
End Sub
a. Choose a random centroid X, Y and Rotation for a Hotdog
b. Calculate X & Y position of each end
c. Check if the Hotdog intercepts a line
d. Draw the HotDog
e. Record the throws status
f. Tally results
Randomize
xc = XOffset + Rnd() * 10 * HotDogLength
yc = YOffset + 10 * HotDogLength * Rnd()
Rot = Rnd() * 2 * Pi
'Calc end positions
x1 = xc + Cos(Rot + Pi) * HotDogLength / 2
y1 = yc + Sin(Rot + Pi) * HotDogLength / 2
x2 = xc + Cos(Rot) * HotDogLength / 2
y2 = yc + Sin(Rot) * HotDogLength / 2
If Int((y1  YOffset) / HotDogLength) = Int((y2  YOffset) / HotDogLength) Then
Worksheets("Results").Cells(same, 1) = i
HotdogColor = RGB(0, 255, 0) 'Green
Worksheets("Results").Cells(i + 1, 6) = 10
same = same + 1
Else
Worksheets("Results").Cells(cross, 2) = i
HotdogColor = RGB(255, 0, 0) 'Red
Worksheets("Results").Cells(i + 1, 6) = 10
cross = cross + 1
End If
Sub DrawDogs(x1, y1, x2, y2, HotdogColor)
'Draw Hotdog
ActiveSheet.Shapes.AddConnector(msoConnectorStraight, x1, y1, x2, y2).Select
With Selection.ShapeRange.Line
.Visible = msoTrue
.Weight = 6
'.capType = msoRound ??? come on MS Guys complete the Object Model
.ForeColor.RGB = HotdogColor
End With
Application.ScreenUpdating = True
End Sub
Call DrawDogs(x1, y1, x2, y2, HotdogColor)
Worksheet Storage Names  
Runs  =Throw!$D$2 
Iteration  =Throw!$H$2 
Summary Names  
Cross  =COUNT(OFFSET(Results!$B$2,,,COUNTA(Results!$B:$B)1,1)) 
Same  =COUNT(OFFSET(Results!$A$2,,,COUNTA(Results!$A:$A)1,1)) 
Calculated Names  
i  =OFFSET(Results!$D$1,1,,COUNTA(Results!$D:$D)1,1) 
PiEst  =OFFSET(i,,1) 
Ind  =OFFSET(i,,2) 
PiAct  =PiEst*0+PI() 
PiVar  =(PiEstPI())/PI() 
Sub CleanUp()The code loops through the shapes in the Shapes collection and if not named "Chart" or "Button" deletes it
Dim Shp As Shape
Worksheets("Throw").Select
For Each Shp In ActiveSheet.Shapes
If Left(Shp.Name, 6) <> "Button" And Left(Shp.Name, 6) <> "Chart " Then
Shp.Delete
End If
Next Shp
Worksheets("Results").Range("A2:B10000").ClearContents
Worksheets("Results").Range("D3:F10000").ClearContents
Worksheets("Results").Range("F2").ClearContents
[Iteration] = 0
[Iteration].Select
End Sub
CounterIntuitive Illusory Contours
@ Chandoo.org"Jawdropping... For the advanced Excel user, Daniel's Blog and the Excel Hero Academy are
treasure chests full to the brim with invaluable Excel information, techniques and ideas."  Robert Mundigl
"Daniel's expertise in Excel is unrivaled in my opinion... Daniel's Excel training has literally changed the way I view Excel and use it for business purposes."  Vedantham Srinivas
"I was especially impressed with the ExcelAccess set of tools that enables Excel to used to retrieve data from and update an Access database."  Dennis Plum
"I challenge 'anyone' to put together a better course than EHA for a comparable cost. I'll go out on a limb here say, it aint gonna happen."  Calvin LeBlanc
"I've never seen anything like Daniel's course. Nothing is remotely like it. Daniel's course has paid for itself time and time again."  Michael Shallal
"History will show that Daniel Ferry has built a fabulous body of work."  Brendan Drew
"There is nothing like Daniel's course out there. The content is like discovering gold."  John Hackwood
"This is an empowerment system with so many extras. Thank you, thank you for a fabulous Excel journey and experience."  DaniÃ¨le Questiaux
"I am very very happy with the course, best I have ever invested in. I am glad I ordered the download option as I believe I will keep learning from your modules for a long time to come."  Ajay Gajree
"The content and videos in Daniel's class are the best I have seen."  Wanda Norrick
"Forget all the businessy stuff. Daniel is to Excel as Neo is to The Matrix. By the end of the course, you'll be 'walking the path' with your new powers of Excelfu. Learn from The One!"  Mark Sessoms
Enchanted Radar Chart
Infographic with Excel
1
0.25
0.25
0.25
0.25
0.25
0.25
0.25
0.25
1
0.39
0.39
0.39
0.39
0.39
0.39
0.39
0.39
1
0.26
0.26
.
.
.
Named formula  Note  Refers to 
n_ColPoints  Predefined number of data points for one category + 1 point for the gap  =9 
n_Category  Number of categories in the data table. In the example n_Category = 20  =COUNTA( Sheet1!$A$1:$A$100 ) 
n_TotPoints  Total number of data points on the radar chart In the example n_TotPoints = 180  =n_ColPoints * n_Category 
rng_h  n_Category could be used in the INDEX formula to make the data table dynamic  =Sheet1!$B$2:INDEX( Sheet1!$B$2:$B$100, n_Category) 
0.75
0.75
0.75
0.75
0.75
0.75
0.75
0.75
0.75
0.61
0.61
0.61
0.61
0.61
0.61
0.61
0.61
0.61
0.74
0.74
0.74
.
.
.
0,75
0,61
0,74
.
.
.
arr_pnt  rowsequence to number the data points from 1 to n_TotPoints {1;2;3;....;180}  =ROW( Sheet1!$A$1: INDEX(Sheet1!$A: $A,n_TotPoints)) 
arr_cat  columnsequence to number the categories from 1 to n_Category {1,2.3,.....,20}  =COLUMN( OFFSET(Sheet1!$A$1,,,,n_Category)) 
arr_pnt_cat  this array  as a sequence  identifies which category the data point belongs to. It consists of 180 numbers, repeating 9 times each number from 1 to n_Category: {1;1,1;1;1;1;1;1;1;2;2;2........;20;20}  =INT( (arr_pnt1) / n_ColPoints )+1 or an other solution: =MATCH( arr_pnt, arr_gap, 1 ) (see arr_gap below) 
arr_gap  sequence number of data points used to separate the categories (the gap) {1;10,19;28;37;.....;172}  =(ROW(rng_h) MIN(ROW(rng_h)))*n_ColPoints+1 
arr_01  Data series representing the insideout columns. Repeats 1 minus data percentage 8 times alternating gap points with value 1.  =1MMULT((arr_pnt_cat=arr_cat),rng_h)* ISERROR(MATCH(arr_pnt,arr_gap,0)) 
label_1  ISNUMBER for the data range rng_h gives back TRUE where we have data. You need to multiply by 1 to convert it to numeric values: {1;1,1;...;1}  =ISNUMBER(rng_h)*1 
labels  Dynamic range for labels  =OFFSET(rng_h,,1) 
active_row  The formula gives back the row number within the data table.  =CELL("row") CELL("row",rng_h)+1 
arr_act_cat  This array contains 0s for all the categories except the active rowcategory (9 times 1).  =(arr_pnt_cat=active_row) * arr_pnt_cat 
arr_a1  Comparing to arr_01 the only difference is in the 10 matrix: here we use the activecategory based arr_act_cat instead of arr_pnt_cat which contains all of the indexes.  =1MMULT((arr_act_cat=arr_cat),rng_h)* ISERROR(MATCH(arr_pnt,arr_gap,0)) 
arr_a2  Choose the active data from the data table using INDEX and create a vector of this data by multiplying with a 1vector. If the active row is not in the data table, we do not need this circle, this is why multiplied with is_in_rng  =(1  arr_pnt ^ 0* INDEX(rng_h,active_row))* is_in_rng 
is_in_rng  We have chosen this nice formula to determine if the active row is within the data range or not. If the active row is below the table, MEDIAN gives back the last row of the table, so the equation will be false. Similarly when the active row is above the table MEDIAN gives the first row of rng_h (which is CELL("row",rng_h) so the equation will be false too.  =CELL("row")= MEDIAN( CELL("row"), CELL("row",rng_h), MAX(ROW(rng_h))) 
Target.Parent.Calculate
End SubTT  This name will be added to the chart title. The formula itself is a concatenation on the active data, the name of active category and some line breaks CHAR(10).  =IF(is_in_rng, TEXT(OFFSET(OFFSET(Sheet1!$A$1,active_row,),,1),"0%") & CHAR(10) & "of Democrats viewed" & CHAR(10) & LOWER(OFFSET(Sheet1!$A$1,active_row,)) & CHAR(10) & "as a top priority" & CHAR(10)&"in 2011","") 
I figured I'd give it a go in Excel and this post documents my approach to a solution.
What to see
On the right you see a rotating array of blue crosses and 3 yellow dots.
Now fixate on the centre (watch the flashing red/green spot). Note that the yellow
spots disappear once in a while: singly, in pairs or all three simultaneously, right?
In reality, the 3 yellow spots are continuously present, honest! This is captively called "motion induced blindness" or MIB.
What to see
On the right you see a rotating array of blue crosses and 3 yellow dots.
Now fixate on the centre (watch the flashing red/green spot). Note that the yellow
spots disappear once in a while: singly, in pairs or all three simultaneously, right?
In reality, the 3 yellow spots are continuously present, honest! This is captively called "motion induced blindness" or MIB.
The actual MIB Excel model is much smoother than this animated GIF representation.
The MIB Model
There were three approaches I thought about using for this optical illusion.
1. Use a single series to define all the points (49) and place a cross at each point.
2. Use 2 series to define each cross, there are 49 crosses.
3. Use a Bitmap for the Background including crosses and rotate it.
Choice of Attack
The first method wouldn't suit the needs of the illusion as each marker doesn't rotate as the series is rotated, but instead stays fixed relative to the ordinal axis.
The second method would require a large number of
coordinates for each cross, that is 4 X and 4 Y coordinates for each cross
and there are 49 Crosses, for a total of 98 series, and 196 coordinates. Time
consuming but at least the crosses will rotate. This is the methodology I choose for the model.
The Third method of rotating a fixed bitmap although very feasible, wasn't I felt in the spirit of doing it all in an Excel Chart. I should note that this method would allow for much faster rotation than has been achieved using Method 2.
You can follow along with the real model and all associated preparatory workings in the attached file: Motion Induced Blindness.xlsm. All preparatory workings described below are on worksheet "2".
Setup
Firstly I setup a table of numbers 3 to +3 in X and Y and then added/subtracted a small amount to each one to represent the width of the cross. I settled on 0.15 as it looks about right.
This gave me a table of X and Y values for each point.
Offset 
0.15 

Pt No 
X1 
X2 
Y 
Circle Quadrant 
1 
3.15 
2.85 
3 
3 
2 
2.15 
1.85 
3 
3 
3 
1.15 
0.85 
3 
3 
4 
0.15 
0.15 
3 
3 
5 
0.85 
1.15 
3 
4 
6 
1.85 
2.15 
3 
4 
7 
2.85 
3.15 
3 
4 
8 
3.15 
2.85 
2 
3 
9 
2.15 
1.85 
2 
3 
10 
1.15 
0.85 
2 
3 
etc 




Rotation
The problem with X and Y values is that to rotate them around a point it is easier to use Polar coordinates, but Excel requires Cartesian Coordinates to plot.
So the process would be
1. Setup the 49 points of 4 sets of X, Y pairs
2. Transform them to polar coordinates.
3. Setup a named formula for each end point
4. Add a radial increment to the revised polar coordinates
5. Use a named formula to convert the polar coordinates to Cartesian coordinates
6. Plot
7. Repeat from Pt 4.
Polar Coordinates
Point 2 in the above sequence means converting each set of coordinates into polar coordinates consisting of Radius r and Angle Ã˜.
Solving the above we have
r =sqrt(x^{2} + y^{2})
= Sqrt(2.85^{2 }+ 2^{2})
Ã˜ = Atan(y/x)
=Atan(2/2.85)
This is done for every end point of each cross section, 98 pairs of X, Y Coordinates.
Now we have the polar coordinates of the end points, we can setup the rotation equations.
That is the equations to convert the original polar coordinates back to X & Y values, which Excel needs to plot.
This is done by 2 simple equations:
X = r * Cos(Ã˜)
Y = r * Sin(Ã˜)
X = 3.731*cos(3.707)
Y = 3.731*sin(3.707)
Now we can add a rotation angle, lets use t.
So that the new position after rotation is
X = r * Cos(Ã˜ + t )
Y = r * Sin(Ã˜ + t )
Xrot = 3.731*cos(3.707 + t)
Yrot = 3.731*sin(3.707 + t)
This is done for each point of the cross for all crosses.
x1 
y1 
4.350*cos(3.903+t) 
4.350*sin(3.903+t) 
3.691*cos(4.091+t) 
3.691*sin(4.091+t) 
3.213*cos(4.346+t) 
3.213*sin(4.346+t) 
3.004*cos(4.662+t) 
3.004*sin(4.662+t) 
3.118*cos(4.988+t) 
3.118*sin(4.988+t) 
3.525*cos(5.265+t) 
3.525*sin(5.265+t) 
4.138*cos(5.472+t) 
4.138*sin(5.472+t) 
3.731*cos(3.707+t) 
3.731*sin(3.707+t) 
2.936*cos(3.891+t) 
2.936*sin(3.891+t) 
2.307*cos(4.191+t) 
2.307*sin(4.191+t) 
etc. 

Matrix Arithmetic
To draw a line on a scatter chart, Excel needs 2 X values either in a Range or an Array as well as 2 Y values in a Range or Array.
Thankfully I've been a member of Daniel's Excel Hero Academy. In a Module on Matrix Arithmetic we learn that we can add 2 named formulas together to make an array in a Named Formula.
We need to do this to end up with an Array representing the X and Y values for each of the 98 segments of the 49 Crosses.
X Values = { X1, X2 }
Y Values = { Y1, Y2 }
As an Excel Named Formula I used:
Named Formula Formula
sx_08 = {1,0} * 3.731*cos(3.707+t) + {0,1} * 3.482*cos(3.753+t)
sy_08 = {1,0} * 3.731*sin(3.707+t) + {0,1} * 3.482*sin(3.753+t)
This is done for all the 98 cross segments.
To simplify the construction of all these, the coordinates, transformation to polar coordinates and construction of the rotated transform formulas was done in Excel (Refer Worksheet "2" in the example file).
This allows errors in coordinates to be checked.
Once all the named formula are ready to be uploaded, I have used a technique involving a simple VBA Named Formula upload subroutine. This is described in my post at: http://chandoo.org/wp/2011/06/23/automatingrepetitivetasks.
The VBA routine is available in Module 2 of the attached Sample File, "Load_Named_Ranges()".
Add Chart Series
Once the named formula are constructed and loaded, it is simply a matter of adding a blank scatter chart to Excel and setting up a table of Series Names, X value and Y Values:
Chart Series Name 
X values 
Y values 
S01 
=1!sx_01 
=1!sy_01 
S02 
=1!sx_02 
=1!sy_02 
S03 
=1!sx_03 
=1!sy_03 
S04 
=1!sx_04 
=1!sy_04 
S05 
=1!sx_05 
=1!sy_05 
S06 
=1!sx_06 
=1!sy_06 
S07 
=1!sx_07 
=1!sy_07 
S08 
=1!sx_08 
=1!sy_08 
S09 
=1!sx_09 
=1!sy_09 
S10 
=1!sx_10 
=1!sy_10 
Etc 


Once again I have setup a table of Named Formula name, together with X and Y Named Formula and used a small VBA routine to add these series to the chart.
The VBA routine to do this is available in Module 2 of the attached Sample File, as "Add_Cht_Series()".
The 3 Yellow Spots
The 3 yellow spots are a manually loaded series in the chart using an Array of coordinates.
X Series ={1.5, 0, 1.5}
Y Series ={1.5, 1.8, 1.5}
The Marker was set to Yellow and size 15
The Line Type was set to None
The Centre Spot
The centre spot was a manually loaded series in the chart
X Series =0
Y Series =0
The Marker was set to Red and size 12.
The Line Type was set to None.
Animation
Animation of the chart is achieved by adding a simple Named Formula "t" and the changing the value of t and updating the chart.
This is done through a simple VBA routine "Rotate()"
This is described below
Sub Rotate()
Dim t As Double 'Dimension the only variable
t = 361 'Start at 361 Degrees
Do While [AA1] 'Loop while cell AA1 is True
t = t  1 'Decrease rotation angle by 1 Deg
If t = 0 Then t = 360 'If Rotation = 0 go back to 360
ActiveWorkbook.Names.Add Name:="t", RefersToR1C1:=(t * 2 * Pi / 360)
' Add a named Formula t with value = t * 2 * Pi / 360
' t expressed in radians
DoEvents 'Refresh screen
If (t >= 0 And t < 90) Or (t >= 180 And t < 270) Then 'If t in a range set Centre Marker color Red or Green
ActiveSheet.ChartObjects("Chart 2").Chart.SeriesCollection(99).Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
Else
ActiveSheet.ChartObjects("Chart 2").Chart.SeriesCollection(99).Format.Fill.ForeColor.RGB = RGB(0, 255, 0)
End If
Loop
End Sub
Download
The above example is attached below:
Worksheet 1, contains the working model.
Worksheet 2, contains the original source data as well as all transformations of it.
Download here: Motion Induced Blindness.xlsm
FINALLY
This is my second post at ExcelHero.com and I'd like to thank Daniel for allowing me to post here again.
I am a member of the inaugural Excel Hero Academy and MVP of the Excel Hero Academy 2 & 3, where Daniel explains a lot of the techniques you will see throughout this site as well as so much more.
It is one of these techniques that made this project possible.
I am a regular contributor at Chandoo.org where I answer questions at the Forums and have contributed over 30 Posts.
For more about my Excel work please visit: http://chandoo.org/wp/abouthui/