Skip to content

Yak digging and hole shaving

Posted on:May 30, 2023

Am I out of my ellipse shaped hole? I thought I was, I had the branch ready to push the PR and merge it. And then I tested some additional case, just to be sure. And nothing worked.

Let’s backup a little bit.

Generic Distance between two curves

After providing a solution for ellipse intersection, I realised that distance between arcs of ellipses was an even bigger problem (requiring to solve a polynomial of degree 8). So I went the other route - minimising the distance function between two segments.

So I looked around and found a fun algorithm for finding global minima of a function: the DiRect algorithm. I needed to implement the algorithm itself, as I did not find a javascript / typescript implementation, but it was not too complicated.

Why did I choose this one? First, because it finds a global minimum - which is what I need for a distance. It also works on a bounded space - which is what I have. And it does not need a gradient (which adds complexity that I do not need now).

I did hesitate to go with a Newton-like approach with the L-BFGS-B algorithm. There was two drawbacks. It required an additional algorithm to make sure I did not find a local minimum. And I would have needed to implement the bounded version in typescript (and it is more complex than DiRect).

Interlude

Once I had everything working it felt like I could move on - but very quickly broke everything by testing more thoroughly.

It feels like I have a bug somewhere, but could not track it (or perhaps the numerical methods I use do not have enough precision).

In any case I needed a distraction

Boxes!

Yep, this is what I do when I am stuck - I create new boxes.

In this particular case I wanted to create a box for some washable pens my son uses to draw on silicone. The inside of the tray has some nice rounded shape and the lid uses a simple hinge (that, to be honest needs a revision).

It works as a print in place model, but I did another version where I decorated with blingmything and printed the lid independently.

The fun part was to figure out where to put the hinge axis so that the lid closed, it opened with the back of the lid on the print bed and did not intercept the back of the wall - trigonometry is actually useful, tell your kids.

The trick is to have the axis at the same distance horizontally and vertically to open at 90 degree on the bed. But you need to be as close to the border as possible to not avoid intercepting the wall.

I have some ideas on how I could improve a bit the design, but the v1 looks nice!

Box of pencils with a hinge

What now?

I have some time until the end of June to work on pantograph (and replicad). I will then start a new consulting gig for 6 months. My aim is to have the possibility to draw with pantograph within replicad.

So I plan to put ellipses on the side for a little while and revisit them in a couple of weeks. Until then, I want to integrate Bézier (using bezier.js to do the heavy lifting).