# A Lemma on Intersecting Circles

I was playing with some geometric constructions recently and came across this rather nice little geometric identity. It gives the length of the line intersecting two intersecting circles in terms of the distance between them and the angle to their shared chord. Notably there is no need to know the radius of either circle. It seems nice enough that it should be known, has anyone seen it before?

The proof makes an interesting exercise. The first time I did it was with pure algebra, but then I found the following argument which is a little nicer. I’m still convinced there is a better way, however. Open to you!

Proof:

Using basic trigonometric relations, we have

Constructing a further right-triangle gives us . And finally

I will leave proving the second case as an exercise.

# Re-implementing the Boost Filtered Iterator using Boost Iterator Adaptor

Recently I wanted to write my own iterator filter so that I could apply a functor directly to an iterator, before dereferencing. It took me a bit of searching around to figure out how to do it so I thought I’d share my ‘solution’ (I think there are not enough examples of Boost code on the internet).

Note that when constructing the iterator, to construct the begin() iterator, we also need the end() iterator, since the filter may go all the way to the end.

template <typename Functor, typename Iterator>
class my_filter_iterator
my_filter_iterator<Functor, Iterator>,  // Derived
Iterator,                               // Base
boost::use_default,                     // Traversal
boost::use_default,                     // Reference
boost::use_default                      // Difference
>
{

private:
struct enabler {};

Iterator    end;
Functor*    f;

/**/

public:
my_filter_iterator()
{ f=NULL; }

/**/
// Construct the filter iterator.

explicit my_filter_iterator(
Iterator  begin,
Iterator  end,
Functor*  f
) : my_filter_iterator::iterator_adaptor_(begin), end(end), f(f) {}

// Only to be used for creating the 'end' iterator.
explicit my_filter_iterator( Iterator  end, Functor*  f )

/**/

private:
friend class boost::iterator_core_access;

/**/

// This is called when the iterator is incremented.
//We skip elements  that do not conform, stopping
//if we hit end.
void increment() {
Iterator i = this->base_reference();
++i;
// The filter.
while( i != end && (! (*f)(i) ) )
++i;
this->base_reference() = i;
}

/**/

}; // my_filter_iterator


# Not-so Calypso

For reasons that are still not quite clear, I said I would re-do the Calypso alarm sound for Blackberry as a rock song.

Well, here it is as promised:

For those that don’t know the original: http://www.ventones.com/free-ringtone-ACaPc479-Blackberry-Calypso-ringtone.html.

# China: Tian Xing 2012 follow up

Well, it’s now been quite a while since I returned from China. I had originally hoped to maintain a blog on the whole trip, however it ultimately turned out that we had no access to the internet in the village where we stayed. However, all is not lost! I wrote up the log book of all the trips (in LaTeX, of course). So for those interested in the antics we got up to, you can find all of the trip reports here: China logbook.

I uploaded a small selection of the many (read: thousands) of photos taken. These can be found on my flickr account here. Note that I didn’t take all of these photos! Many of the cave photos were taken by both me and Mandy Fu.

I also stuck together a few of the videos taken on the trip. Hopefully they provide a bit of an insight into exploration caving (link to follow).

Finally, I should thank all of those that organised the expedition and came along. We all had a great time!

(Photo by me and Mandy Fu: the large chamber we found at the bottom of Da Keng Wan)

# China: First Impressions

Update. The following is an RSS feed for these posts. www.rosshemsley.co.uk/category/caving/china/feed

At some point this year I received an e-mail looking for people to join the 2012 caving expedition to Tian Xing, China. It vaguely mentioned big caves, and hanging around in China for a month. It seemed like an opportunity that was too good to miss! Despite the fact that I didn’t really know anyone, haven’t been caving for months and probably didn’t have enough money to fund the trip. But no matter, I quite like a challenge; so I booked some flights. And (finally) got a visa.

So now it has come to a point that everyone keeps asking me about my rather eccentric holiday* (I still don’t agree with calling a caving expedition a holiday) plans. So I thought I’d assemble my experiences into some kind of blog/diary – (in the spirit of online portmanteaux: diaralog? blogary?). Let’s see how it goes…

Day 1
Well I had to get to Nice airport for around 05:00am. Fortunately a very kindly friend let me stay at her place, which happens to be right next to the airport. Despite this fact she even let me drag her out of bed at four in the morning to drive me the two or so kilometres to the airport. This is how you find out who your friends are! Things then went almost disappointingly smoothly. I knew I wanted to write things up later, so of course you have to hope at least something goes wrong, otherwise it’s pretty tedious reading. So to cut things short, I flew to Paris, then Helsinki, then Chongqing, China.

Fortunately things then had the good grace to go a little awry at this point. I arrived at the terminal building and none of my cards would allow me to withdraw cash. Of course I hadn’t considered this possibility, so had no spare cash on me at all. After some fighting with the machine I decided this was probably just due to the particular branch of bank. The problem then became that I was in a tiny terminal building, with only one machine, and no obvious way to another one. After a little ferreting I managed to find a £10 note stashed amongst my things from the last time I was in the Uk. I figured I could change this to RMB and then get a bus to town, where I would find a bank. When I went to do this however, the young women at the desk laughed at me. Apparently they charge a fixed commission of around £5 to change any currency… I was left with just enough to get the bus, but not enough for a taxi which required about £2 more than I had. Armed with my slightly modest wad of cash, I sat and waited for the bus at the stop. All alone. For around half an hour. When I realised that there must be something everyone else knew that I didn’t, I decided to go for a hike to look for banks. A very short walk later, I realised that I was in fact right next to a huge terminal building with many, many cash points. Well, after a bit of a panic when the first three of these gave me a series of undecipherable ‘Engrish‘ error messages, I managed to get my hands on some currency!

Given this huge success I decided to take the ‘adventurous’ route to my hostel, using a series of public transport links instead of taking a taxi. I went to catch the bus from the much larger official-looking bus stop. I knew the name of the place I wanted to go to in English, and helpfully there was a sign saying where the bus went written in English too.

Well, perhaps not that helpfully after all: Fortunately the hostel directions were excellent, and they told me just to take the bus to the last stop. The directions then lead you on a wonderful labyrinth-like tour of the back streets of Chongqing that felt somehow like following a treasure map. Though that could just be lack of sleep. Ultimately, that brings me to the hostel, which is where I am typing this.

My plan now is to either get some sleep (my body clock says it’s time to sleep, but the wall clock says it’s early morning) or to fuel up on enough caffeine to get me through until tonight. I’m currently leaning towards the latter.

So, first impressions: On my traversal of the city I didn’t see a single westerner. Everyone was looking curiously at me, being chatty and (I assume) friendly. The food smells great, though I’ve yet to work up the courage to try and order some vegetarian dish yet. All in all, I think I’m going to like it here!

Much more interesting photos to come later, when (if) I’ve taken some.

# Boost iterator_adaptors and modifying the CGAL Finite_vertices_iterator

I recently had to solve the following problem, and I couldn’t find many examples online. Hopefully this code will make it easier for the next person! Here’s the problem, written for CGAL users and non-CGAL users).

Problem (For the CGAL proficient reader)
In my problem, I have a container containing geometric objects. I want to iterate over those objects and calculate properties about them. If the container is a vector, and the geometric objects are Vertex_handles, then I can use the standard vector<Vertex_handle>::const_iterator and expose my Vertex_handles by dereferencing the iterator. If however it is a triangulation, there is a problem. I can use the default CGAL Finite_vertices_iterator as my iterator, however CGAL treats the Finite_vertices_iterator as the same object as a Vertex_handle. Therefore when I dereference my iterator, I get a Vertex, and not a Vertex_handle. Thus my code cannot be consistent for these two containers. Thus I want to modify Finite_vertices_iterator so that dereferencing gives me a Vertex_handle instead of  a Vertex.

I have an iterator that dereferences to the wrong type. I want to modify the iterator so that dereferencing it gives me back the original iterator (without dereferencing). I want to do this to make my behaviour consistent with other iterators.

Solution
To solve this, I decided to use boost’s iterator_adaptor. This acts like a wrapper around an iterator-type object (indeed, the object need not actually be an iterator), and allows us to modify the behaviours of the operations whilst maintaining most of the default behaviours.

I could not find much documentation apart from the official documentation, which I found quite complex. (I did however find this link, which seems to be out of date?). Ultimately it turned out to be quite easy. I just had to set the ‘Base’ to be my original iterator (the Finite_vertices_iterator, and the ‘Value’ and ‘Reference’ to be the return type I wanted (Vertex_handle). Once this was done, I could overload the dereference() procedure and simply return the bare iterator without performing any dereferencing.

	class my_vertex_iterator
my_vertex_iterator            // Derived
, Finite_vertices_iterator      // Base
, Vertex_handle                 // Value
, boost::forward_traversal_tag  // Traversal type
, Vertex_handle>                // Reference
{
private:
struct enabler {};

public:
my_vertex_iterator()

explicit my_vertex_iterator(const Finite_vertices_iterator p)

private:
friend class boost::iterator_core_access;
typename my_vertex_iterator::reference
dereference() const
{
return this->base();
}
};


To create an iterator of this type in my context I simply needed to call my iterator on the base iterator:

my_vertex_iterator begin(Delaunay* dt)
{
return my_vertex_iterator(dt->finite_vertices_begin());
}


# Chimera 2011 (trip report)

Written as a  trip report for the UBSS newsletter - Text in italics is my (attempt!) at translating Florence Ménétrier’s trip report into English. Participants: Fred, Ross, Flo for the Sophitaupes, the Faverjons (Marc, Anne et Maud) and five other Italians. This trip to Abisso Chimera (at 1006m, it is currently the 85th deepest cave in the world) was completed in October 2011.

I found myself in the sad position of having finished my degree last year, and not feeling particularly keen on entering the world of work, I somehow managed to install myself in a Ph.D position in the Côte d’Azure (UBSSians: feel free to visit!). Of course this meant leaving behind the glorious (?) caves of the Mendips, but I felt sure that there must be some kind of caving going on in the surrounding mountains (to quote a local caver, who stated with absolute seriousness: “Sure, there are some small caves in the area reaching a depth of around -500m, but don’t worry, there are some bigger ones not too far away”). A couple of weeks after arriving, I managed to get in touch with a local caving club. They (in retrospect, probably half jokingly…) said that they had been planning a trip to bottom the 1006m deep Abisso Chimera in Tuscany, Italy, leaving on Friday if I might be interested. I wasn’t going to turn them down, and before I knew it I found myself immersed in a team of French and Italian cavers (almost none of whom spoke any English!). I think I made somewhat of an impression on them, and I’ll include some translations of their club’s trip report which are quite amusing:

“To give you an idea of the legendary British hardiness; Ross is the type of guy who says “OK” when presented with a group of complete strangers who propose (on Thursday evening) that he accompanies them down a 1000m deep cave in Tuscany two days before leaving (on Saturday). – No comment!”

So, before even leaving I was faced with my first challenge: my trusty Nova had decided to break down (the classic failure between the battery box and cable gave up…). This was solved by rather dubiously strapping a combination of a Petzl Tikka and a bike light loaned by the Italians to my helmet. In actual fact running both at the same time gave me something approaching 300 lumens of light, which was better than my Nova! Plus I rather liked the Heath Robinson-esque appearance.

After a 7am rise on Saturday, we found ourselves driving up to Apuanes at an altitude of around 2000m. It is a beautiful area, replete with immense marble quarries, in the process of being serviced by similarly immense vehicles, all traversing the tiny mountain roads. The hike to the cave took around an hour and a half, and on arrival we feasted on hordes of focaccia and pizza of a quality that only Italians seem to be able to achieve. And then we were off! I had been warned that the cave was cold, and so I diligently wrapped up in thermals, furry and Warmbac oversuit. This was my first mistake, as clearly ‘cold’ is a relative term. I quickly found myself overheating, and was observed bemusedly by the local Italians, wearing their super-thin AV-suits with barely anything underneath. Not knowing how to explain in Italian that I had been “mislead” about the temperature, I could do nothing but grin and look like a novice.

Whilst I appeared to have no clue on what to wear in a cave, at least I was able to show off some of my Mendips-style caving prowess as we attacked the ‘tight’ entrance series (these guys clearly haven’t visited the end of the Virgin Series!):

“Around one hundred meters of frankly unpleasant tight passage… I regretted already that my kit was loaded with an incompressible sleeping bag and SRT kit. I turn around and observe with curiosity a certain Englishman who’s close behind. I see by his face he is perfectly happy. For him it’s spacious and easy, he’s not breaking a sweat and I see in his look he doesn’t understand why I’m not advancing more quickly!!”

Finally we arrived at Osanna, A fine and spacious 80m pitch carved out of the marble before us. I found myself struggling with the esoteric Italian re-belays, rigged to cover almost as much distance horizontally as vertically; it was impossible to pass them without using a good deal of upper body strength. I assumed they were just nuts, but I later came to understand that there was method in their madness…

Eventually we came to a series of pitches that could only be passed one by one, leaving a large gap in between each person. That seemed a little like overkill until I came to appreciate the frequent and unavoidable avalanches of rocks that fell at the slightest touch which were all around us. This cave isn’t like other caves I’ve been in. This cave feels like a 1000m extension of the “entropy increasing” scree slope in Xitu. The wide re-belays suddenly made sense. The last place you wanted to be on a pitch was underneath someone else, and I started to take comfort in even the widest and most testing re-belays.

After a slightly monotonous series 700m of pitches, we arrived at Chimera’s showpiece: “Touch in the Void”. This 160m monster of a pitch feels like an immense and impenetrable canyon; even the highest level on both of my lights failed to reveal walls opposite me, let alone below or above me.

““Touching the WHAT?? The void… The what? – The God-damned void!” Fred is in front of me and an “OH, F***”, escapes him!
Me: “What is it Fred, a rock?”.
Fred (in a small voice): “No, no, you’ll see…”

And there, I saw! Or, that is, I felt… the emptiness!
Oh my god!! It is a black hole. The most immense, horribly giant and enormous thing that the earth has created opens up in front of me and is about to swallow me up!”

This the first 1000m deep cave for my French comrade, and she was (understandably!) nervous. So was I. So once I found myself dangling from the roof on the 1cm thick rope, waiting for the next re-belay to free up, I couldn’t resist whipping out my trusty harmonica. This is an idea I unapologetically stole from OUCC’s David Rose. And what an idea! Despite my patent lack of any ability to actually play the harmonica, a stupid melody penetrating the immenseness successfully brought up the mood and we found ourselves cheerily descending the 20 Italian-style re-belays all the way to the bottom.

At this depth the cave changed character completely. We had entered a labyrinth of phreatic tubes occasionally frosted with “popcorn” type formations similar to that found in the Picos. It was here that I really started to first enjoy the caving. Winding passageways and small climbs are much more to my taste than endless pitches (I guess I have the Mendips to blame for that). But this section was all too short. It was not long before we found ourselves gazing into the turquoise waters of the final sump. A pleasing river leads up to a sandy “beach” by the edge of the water, and the passage dives straight down into the foreboding clear waters. This has been dived to a depth of 10 or so meters, and all I know of the outcome is that “It keeps going down”.

Well, now we’ve reached the bottom, I suppose I should come clean. I had decided to bring my camera with me on this trip. That is: my SLR, four high power flashes, twenty AA batteries and four sets of triggers, all in a 1.5kg Peli 1300 case. Oh, and a tripod. Yes, perhaps I overestimated my fitness when I imagined that I could carry all that, 2L of water, food, and a sleeping bag down to -1000m and back, whilst keeping up with my (somewhat less burdened) comrades. More of that later… For now, I took the opportunity to take a set of photos for the occasion, already not looking forward to the daunting climb back out.

Of course, on arriving back at the bottom of “Touch in the Void”, I couldn’t resist trying to take a photo before I ascended. Perhaps unsurprisingly, I ended up with a set of extremely underwhelming photos that I’d be embarrassed to show you. But I know you’ll still want to get some idea, so here’s an artist’s impression of what the pitch looks like from the bottom:

Due to the faff (incidentally a word that is not part of the French lexicon. I’ve started introducing it: “la faff” is already catching on in my office…) of playing with various flashes and tripods, I found myself alone at the bottom of the pitch with Marc, as we waited to ascend. I was standing probably 30m from the bottom of the rope to stay out of the way of anything that might be knocked down, and that might seem like a lot. But suddenly there was a series of crashes from above, and I instinctively new to leap up against the wall. It was flat and unforgiving, but I pressed myself against it in a star-shape. The crashes got bigger, and more frequent, and it then it literally rained rocks. Not small pebbles, but large multiple-kilogram masses that hurtled down the shaft and splintered in front of me. I remember bracing myself for the possibility that one of the several slabs of car-like proportions, that I knew to be above me, might come unhinged and plummet to the floor around me. But fortunately it died down, and all that remained was a strong smell of gunpowder and a smattering of broken stone at my feet. Ten frantic seconds were spent as we shouted to communicate with those at the various stages of the pitch and to ensure that everyone was ok.

“The line of light above and below me is making steady progress… Not a sound… but then a SCREAM! The first Italian at the top of the pitch has shouted something!
I see a BOULDER, pass in slow motion in front of my eyes… I close them… and I await the immense crash below.
Below, yes, below with the rest of my team…
I didn’t want to believe it, it was a few fractions of seconds that elapsed before hearing a voice “tutti va bene?” “bene?” “Si! Si!” “Oui! Oui!”
Everyone is alive.
I don’t remember saying any words other than: “Fred! I was scared…”
And I didn’t receive any response from him other than “Oui…””

I slightly timidly started ascending the rope, and after a further 30 minutes spent dangling around 150m off the ground at the top of the pitch waiting for the rope (which seemed to have got stuck or something? I don’t speak Italian!), I was at the top. By this point I was quite tired, and I dragged myself back to the gallery at -700m that has become camp. It’s a lovely camp, and for the first time I got to appreciate the pleasingly warm glow of carbide, as the Italians had set up some kind of huge carbide lamp in one corner that illuminated the whole chamber. But we didn’t stay up long, some hot noodles were had and we finally hit the hay at 1am (hay is probably the wrong word to use for the slab of cold rock which was the reality!).

We slept in until 9:45 the next day, and after a classic underground breakfast of whatever we could lay our hands on, we set off. It was here that I started to be worried about keeping up. With all of my photography gear filling an enormous and unwieldy tackle sack, which of course got stuck at every opportunity, I was starting to struggle to keep up pace. I didn’t want to seem unfit, and I had ended up caving next to an Italian who didn’t speak any French, let alone English, so I couldn’t really explain. Finally he saw me struggling and relieved me of a few kilograms. The going became much easier but I still felt like I was letting team-UK down by appearing to struggle with only one tackle sack! Finally though, we got to my favorite and squeezy entrance series, and we popped out to a spectacular sunset. I was more than a bit glad to be out, and after another feast on Italian focaccia, we set of on the five-hour drive back to Nice, ready for work the next day. Not too bad for a weekend’s caving!

# A lazy Saturday night’s composition

I haven’t been playing much guitar recently, and certainly not doing much writing. But now and then I have a lazy evening and feel motivated to put some riffs together. Here’s the slightly Pink Floyd’esque product of this evening. (Along with a drum track I wrote for a completely different song, which seemed to fit surprisingly well…).