/** * Copyright (c) 2011-2014 by Andrew Mustun. All rights reserved. * Copyright (c) 2015 by Peter Chiochetti, CC BY * * This file is part of the QCAD project. * * QCAD is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * QCAD is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with QCAD. */ include("../MathExamples.js"); /** * This action draws an approximation of an Archimedean spiral (center at 0/0). */ function ExMathSpiralA(guiAction) { MathExamples.call(this, guiAction); } ExMathSpiralA.prototype = new MathExamples(); /** * Draws a polyline and terminates. * Explode to get quarter circle arcs. */ ExMathSpiralA.prototype.beginEvent = function() { MathExamples.prototype.beginEvent.call(this); var document = this.getDocument(); var di = this.getDocumentInterface(); var operation = new RAddObjectsOperation(true); var rDelta = 0.25; // distance increment var aDelta = Math.PI / 2; // angle increment var bulge0 = Math.sin(aDelta / 2); // first segment var bulgeN = Math.tan(aDelta / 4); // further segments var polyline = new RPolylineData(); polyline.appendVertex(new RVector(0, 0), bulge0); for (var a = aDelta, r = rDelta; r <= 5; a += aDelta, r += rDelta) { polyline.appendVertex( new RVector(Math.cos(a) * r, Math.sin(a) * r), bulgeN ); } operation.addObject(new RPolylineEntity(document, polyline)); di.applyOperation(operation); this.terminate(); }; /** * Adds a menu for this action to Examples/Math Examples/Spiral. */ ExMathSpiralA.init = function(basePath) { var action = new RGuiAction(qsTr("&SpiralA"), RMainWindowQt.getMainWindow()); action.setRequiresDocument(true); action.setScriptFile(basePath + "/ExMathSpiralA.js"); action.setGroupSortOrder(79700); action.setSortOrder(100); action.setWidgetNames(["MathExamplesMenu"]); };