Bulge calculation

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

Moderator: andrew

User avatar
Premier Member
Posts: 151
Joined: Fri May 28, 2010 7:35 pm

Bulge calculation

Postby hungerburg » Sun Feb 05, 2012 10:32 pm

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 Kreis
var sq = 17.5; // halbe Seitenlänge Quadrat
var sv = Math.sqrt(Math.pow(rk, 2) - Math.pow(sq, 2)); // Versatz Schnittpunkt
var SG = []; // Punkte der Stanzlinie
SG.push(new RVector(c.x + sq, c.y + sv)); //  2 H
SG.push(new RVector(c.x + sv, c.y + sq)); //  1 H
SG.push(new RVector(c.x - sv, c.y + sq)); // 11 H
SG.push(new RVector(c.x - sq, c.y + sv)); // 10 H
SG.push(new RVector(c.x - sq, c.y - sv)); //  8 H
SG.push(new RVector(c.x - sv, c.y - sq)); //  7 H
SG.push(new RVector(c.x + sv, c.y - sq)); //  5 H
SG.push(new RVector(c.x + sq, c.y - sv)); //  4 H
// siehe http://www.afralisp.net/archive/lisp/Bulges1.htm
var bs = Math.sqrt(2 * Math.pow(sq - sv, 2)) / 2; // halbe Sehne vom Kreisbogen
var bh = rk - Math.sqrt(Math.pow(rk, 2) - Math.pow(bs, 2)); // Höhe Ausbuchtung
var bulge = bh / bs; // Tangens: Gegenkathete/Ankathete
var SB = [ bulge, 0, bulge, 0, bulge, 0, bulge, 0 ]; // abwechselnd mit/ohne Beule
this.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 {
   var entity = new RPolylineEntity(zeichnung.document, polylinie);

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!

Return to “QCAD 3 Developers and Contributors”

Who is online

Users browsing this forum: No registered users and 0 guests