import java.applet.*; import java.awt.*; // to get Graphics object. import java.lang.*; import java.lang.Math.*; public class bendGraphic { int height; int width; double twist_R; double twist_L; public bendGraphic(int w, int h, double t_R, double t_L) { height = h; width = w; twist_R = t_R; twist_L = t_L; } public bendGraphic(int w, int h) { this(w,h,0.0,0.0); } public void setSize(int w, int h) { height = h; width = w; } public void setTwist_L(double t_L) { twist_L = t_L; } public void setTwist_R(double t_R) { twist_R = t_R; } public void draw(Graphics g) { double hcanvas = (double)height; // use local copy in case it gets double wcanvas = (double)width; // altered while we draw double length = .005; // distance between wires (m) double wideness = length; // other dimension of crystal double thickness = 5e-5; // thickness of crystal (m) double twis_L = twist_L*Math.PI/180; double twis_R = twist_R*Math.PI/180; double t_L, t_R; // here, t means torque double YoungsMod = 900e9; // in Pa double ShearMod = 500e9; // in Pa double x, y; double[] u = new double[2]; double[] v = new double[2]; double u0 = 0.05*wcanvas; double uS = 0.90*wcanvas/length; double v0 = hcanvas/2; double vS = uS*(hcanvas/wcanvas)*750; double xstep = length/100; u[1] = u0; v[1] = v0; // calculate torques from twists, // using only the shear contribution double wire_radius = 12.5e-6; // in meters double wire_length = .001; // in meters double wire_shearMod = 150e9; // in Pa t_L = wire_shearMod * twis_L * wire_radius*wire_radius*wire_radius* wire_radius * Math.PI/(2*wire_length); t_R = wire_shearMod * twis_R * wire_radius*wire_radius*wire_radius* wire_radius * Math.PI/(2*wire_length); // add label, dots g.setColor(Color.black); g.drawString("5 mm", (int)(u0 + .1 * wcanvas), (int)(hcanvas/1.11)); g.drawString("5 µm", 8, (int)(hcanvas/1.3)); g.fillOval((int)(u0 - 5), (int)v0, 10, 10); g.fillOval((int)(u0 + (uS*length) - 5), (int)v0, 10, 10); // calculate and draw curve double x1 = length; double y1 = x1 * (t_L + t_R)/(length * ShearMod * wideness * thickness) + 12 / (YoungsMod * wideness * thickness*thickness*thickness) * ( x1*x1 * t_L/2 - x1*x1*x1 * (t_L + t_R)/(length*6) ); double highest = v0, lowest = v0; for (x = 0; x < length; x += xstep) { y = x * (t_L + t_R)/(length * ShearMod * wideness * thickness) + 12 / (YoungsMod * wideness * thickness*thickness*thickness) * ( x*x * t_L/2 - x*x*x * (t_L + t_R)/(length*6) ); y = y - y1*(x/x1); u[0] = u[1]; v[0] = v[1]; u[1] = u0 + uS*x; v[1] = v0 + vS*y; if (v[1] < lowest) { lowest = v[1]; } if (v[1] > highest) { highest = v[1]; } // kludge: lines are too thin to appear unless you draw // them with lots of small segments. So we do the // scale this way. g.setColor(Color.black); g.drawLine((int)u[0], (int)(hcanvas/1.1), (int)u[1], (int)(hcanvas/1.1)); g.drawLine(1, (int)(v0 + 2.5e-6*vS), 1, (int)(v0 - 2.5e-6*vS)); g.setColor(Color.red); g.drawLine( (int)u[0], (int)v[0], (int)u[1], (int)v[1] ); } System.out.println("Highest: " + (highest - v0)/vS + ", Lowest:" + (lowest - v0)/vS); } }