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 torsion_R; double torsion_L; public bendGraphic(int w, int h, double t_R, double t_L) { height = h; width = w; torsion_R = t_R; torsion_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 setTorsion_L(double t_L) { torsion_L = t_L; } public void setTorsion_R(double t_R) { torsion_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 = .01; double wideness = length; double thickness = 1e-5; double tors_L = torsion_L; double tors_R = torsion_R; double t_L, t_R; // here, t means torque double YoungsMod = 900e9; double ShearMod = 500e9; double x, y; double[] u = new double[2]; double[] v = new double[2]; double u0 = wcanvas/20; double uS = wcanvas/(length*1.15); double v0 = hcanvas/2; double vS = uS*(hcanvas/wcanvas); double xstep = length/100; u[1] = u0; v[1] = v0; // calculate torques from torsions, using only the shear contribution double wire_radius = 12.5e-6; // in meters double wire_length = .005; // in meters double wire_shearMod = 150e9; // in Pa t_L = wire_shearMod * tors_L * wire_radius*wire_radius*wire_radius* wire_radius * Math.PI/(2*wire_length); t_R = wire_shearMod * tors_R * wire_radius*wire_radius*wire_radius* wire_radius * Math.PI/(2*wire_length); // add label, dots g.setColor(Color.black); g.drawString("1 cm", (int)(u0 + .1 * wcanvas), (int)(hcanvas/1.11)); 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.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); } }