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);
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);
}
Thank You!