## Bulge calculation

Discussion forum for contributors and developers who are using the QCAD ECMAScript development platform or the C++ plugin interface or who are otherwise looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

hungerburg
Premier Member
Posts: 160
Joined: Fri May 28, 2010 7:35 pm

### Bulge calculation

I always wanted to ask in the forum on how to simplify this. To me the calculation of the bulge seems overly complicated. Maybe because I only used the most basic triangle functions (ancient greek ones), as I am not good at geometry. One will not find the formula itself on the afralisp page, but everything to understand, what it does. Here's the drawing:

Such a hole is used eg. to fasten certain fixtures to metal sheets. The fixture is round with a thread in order to take on a nut. It is also square, in order to not turn once inserted.

The code calculates the points counterclockwise and pushes them to array SG. Then it calculates the bulge for the rounded corners and pushes it to array SB. There is only one argument, the center of both square and circle.

Code: Select all

`var c = new RVector(0, 0);/* Ein Kreis und ein Rechteck übereinander * der Kreis schneidet die rechten Ecken ab * Schnittpunkte gegen Uhrzeigersinn * bei zirka zwei Uhr beginnend */var rk = 19; // Radius Kreisvar sq = 17.5; // halbe Seitenlänge Quadratvar sv = Math.sqrt(Math.pow(rk, 2) - Math.pow(sq, 2)); // Versatz Schnittpunktvar SG = []; // Punkte der StanzlinieSG.push(new RVector(c.x + sq, c.y + sv)); //  2 HSG.push(new RVector(c.x + sv, c.y + sq)); //  1 HSG.push(new RVector(c.x - sv, c.y + sq)); // 11 HSG.push(new RVector(c.x - sq, c.y + sv)); // 10 HSG.push(new RVector(c.x - sq, c.y - sv)); //  8 HSG.push(new RVector(c.x - sv, c.y - sq)); //  7 HSG.push(new RVector(c.x + sv, c.y - sq)); //  5 HSG.push(new RVector(c.x + sq, c.y - sv)); //  4 H// siehe http://www.afralisp.net/archive/lisp/Bulges1.htmvar bs = Math.sqrt(2 * Math.pow(sq - sv, 2)) / 2; // halbe Sehne vom Kreisbogenvar bh = rk - Math.sqrt(Math.pow(rk, 2) - Math.pow(bs, 2)); // Höhe Ausbuchtungvar bulge = bh / bs; // Tangens: Gegenkathete/Ankathetevar SB = [ bulge, 0, bulge, 0, bulge, 0, bulge, 0 ]; // abwechselnd mit/ohne Beulethis.polylinie(zeichnung, true, SG, SB);`

Polylinie is just a convencience function.

Code: Select all

`/** Eine Linie über mehrere Punkte zeichnen, optional Linie schließen. * @param {Object} zeichnung die Zeichnung * @param {boolean} geschlossen Linie rundum? * @param {Array} punkte Liste von Vektoren * @param {Array} beulen Liste von Ausbuchtungen*/MyScript.prototype.polylinie = function(zeichnung, geschlossen, punkte, beulen) {   var operation = new RAddObjectsOperation(false);   var polylinie = new RPolylineData();   for (var p = 0; p < punkte.length; p++) {      if (beulen) {         polylinie.appendVertex(punkte[p], beulen[p]);      } else {         polylinie.appendVertex(punkte[p]);      }   }   polylinie.setClosed(geschlossen);   var entity = new RPolylineEntity(zeichnung.document, polylinie);   operation.addObject(entity);   zeichnung.documentInterface.applyOperation(operation);}`

This is quite easy to construct from a circle and a square. But the bulge is difficult to calculate. So many Math, is there a more general bulge formula, for easy lifting?

Thank You!

### Who is online

Users browsing this forum: No registered users and 3 guests