| 1 | |
|---|
| 2 | |
|---|
| 3 | import java.awt.*; |
|---|
| 4 | |
|---|
| 5 | public class PlotPanel extends Panel { |
|---|
| 6 | public DiamCalculator dc; public double mu, rho, g, rho_p, u; |
|---|
| 7 | private double oRe=0; |
|---|
| 8 | private Plot fRePlot; |
|---|
| 9 | |
|---|
| 10 | public void init() { |
|---|
| 11 | setLayout(new BorderLayout()); |
|---|
| 12 | |
|---|
| 13 | fRePlot=new Plot(); add("Center",fRePlot); fRePlot.init(); |
|---|
| 14 | fRePlot.setTitle("Friction Factor Graph"); fRePlot.setGrid(true); |
|---|
| 15 | fRePlot.setNumSets(2); fRePlot.setMarksStyle("none"); |
|---|
| 16 | fRePlot.setXLabel("Reynolds Number"); fRePlot.setYLabel("Friction Factor"); |
|---|
| 17 | fRePlot.setXLog(true); fRePlot.setYLog(true); |
|---|
| 18 | |
|---|
| 19 | fRePlot.addPoint(0,.2,120,false); fRePlot.addPoint(0,.5,50,true); |
|---|
| 20 | fRePlot.addPoint(0,1,26,true); fRePlot.addPoint(0,2,14,true); |
|---|
| 21 | fRePlot.addPoint(0,5,7.1,true); fRePlot.addPoint(0,10,4.3,true); |
|---|
| 22 | fRePlot.addPoint(0,20,2.5,true); fRePlot.addPoint(0,50,1.5,true); |
|---|
| 23 | fRePlot.addPoint(0,100,1.05,true); fRePlot.addPoint(0,200,.8,true); |
|---|
| 24 | fRePlot.addPoint(0,500,.56,true); fRePlot.addPoint(0,1000,.45,true); |
|---|
| 25 | fRePlot.addPoint(0,2000,.42,true); fRePlot.addPoint(0,5000,.4,true); |
|---|
| 26 | fRePlot.addPoint(0,10000,.42,true); fRePlot.addPoint(0,20000,.46,true); |
|---|
| 27 | fRePlot.addPoint(0,50000,.49,true); fRePlot.addPoint(0,100000,.5,true); } |
|---|
| 28 | |
|---|
| 29 | public PlotPanel(double imu, double irho, double ig, double irp, double iu) { |
|---|
| 30 | mu=imu; rho=irho; g=ig; rho_p=irp; u=iu; dc=new DiamCalculator(mu,rho,g); } |
|---|
| 31 | |
|---|
| 32 | public void drawLines() { |
|---|
| 33 | if(oRe>0) { |
|---|
| 34 | for(int i=0; i<5; i++) fRePlot.erasePoint(1,0); } |
|---|
| 35 | double orat=dc.free(rho_p,u); |
|---|
| 36 | if(orat>=5e-6&&orat<600) { |
|---|
| 37 | oRe=dc.rerat(orat); |
|---|
| 38 | fRePlot.addPoint(1,oRe,.3,false); |
|---|
| 39 | fRePlot.addPoint(1,oRe,oRe*orat,true); |
|---|
| 40 | fRePlot.addPoint(1,.2,oRe*orat,true); |
|---|
| 41 | fRePlot.addPoint(1,oRe,oRe*orat,false); |
|---|
| 42 | if(orat>1.5) fRePlot.addPoint(1,.2,.2*orat,true); |
|---|
| 43 | else fRePlot.addPoint(1,.3/orat,.3,true); } |
|---|
| 44 | else { oRe=0; if(orat<5e-6) { |
|---|
| 45 | throw new Error("Reynolds number too large."); }} |
|---|
| 46 | |
|---|
| 47 | fRePlot.fillPlot(); } |
|---|
| 48 | |
|---|
| 49 | public void paint(Graphics g) { fRePlot.paint(g); }} |
|---|