package mz_macros; import harmonic.mz.function.*; import harmonic.cad.shapes.*; import harmonic.cad.manager.*; import harmonic.mz.manager.*; import harmonic.mz.gui.*; import harmonic.mz.data.fields.*; import java.util.*; import java.awt.*; public class MakeHelix extends Module{ ScalarField radius = new ScalarField("radius", 1.f); ScalarField height = new ScalarField("height", 1.f); ScalarField turns = new ScalarField("turns", 1.f); IntField samplesPerTurn = new IntField("samplesPerTurn", 32); public MakeHelix(){ setName("Make Helix"); MZ.modules().loadModule("harmonic.cad.manager.CAD"); } public Component macroGUI(){ Vector nodes = new Vector(); nodes.add(radius); nodes.add(height); nodes.add(turns); nodes.add(samplesPerTurn); return new NodeValuesDialog(nodes, "Make Helix"); } public void execute(){ PolylineShape shape = new PolylineShape(); shape.setName("Helix"); float radius = this.radius.getScalar(); float turns = this.turns.getScalar(); float height = this.height.getScalar(); float samplesPerTurn = this.samplesPerTurn.getInt(); float angle = 0.f; float z = 0.f; float da = (float)(Math.PI*2.f/samplesPerTurn); float dz = height/samplesPerTurn; for(int i = 0; i < samplesPerTurn*turns + 1; i++){ float x = radius*(float)Math.cos(angle); float y = radius*(float)Math.sin(angle); shape.points.addVert(x, y, z); z += dz; angle += da; } CAD.addShape(shape); } }