/*_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/* * (#) Light Path around Schwarzshild Black Hole * * * * 97/02/17 by T.Murauchi * *_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/* */ import java.applet.Applet; import java.awt.*; public class light extends Applet { static double r0,s0,psi0,rmax,pai; static int au; Panel inputpanel; Panel pr0,ps0,ppsi0,pauto,pcalcu,preset; Panel epanel,spanel; Label lr0,ls0,lpsi0; TextField tr0,ts0,tpsi0; Button calcu,reset; Checkbox auto; Particle_Canvas2 p_canvas2; Title_Canvas2 t_canvas2; public void init() { r0 = 5; s0 = 0; psi0 = 150; setData(); lr0 = new Label("R0"); ls0 = new Label("S0"); lpsi0 = new Label("F0"); tr0 = new TextField("5",5); ts0 = new TextField("0",5); tpsi0 = new TextField("150",5); pr0 = new Panel(); ps0 = new Panel(); ppsi0 = new Panel(); pauto = new Panel(); pcalcu = new Panel(); preset = new Panel(); auto = new Checkbox("Auto"); calcu = new Button("Calculate"); reset = new Button("Reset"); pr0.setLayout(new FlowLayout(FlowLayout.RIGHT)); ps0.setLayout(new FlowLayout(FlowLayout.RIGHT)); ppsi0.setLayout(new FlowLayout(FlowLayout.RIGHT)); pauto.setLayout(new FlowLayout(FlowLayout.CENTER)); pcalcu.setLayout(new FlowLayout(FlowLayout.CENTER)); preset.setLayout(new FlowLayout(FlowLayout.CENTER)); pr0.add(lr0); pr0.add(tr0); ps0.add(ls0); ps0.add(ts0); ppsi0.add(lpsi0); ppsi0.add(tpsi0); pauto.add(auto); pcalcu.add(calcu); preset.add(reset); inputpanel = new Panel(); inputpanel.setLayout(new GridLayout(6,1)); inputpanel.add(pr0); inputpanel.add(ps0); inputpanel.add(ppsi0); inputpanel.add(pauto); inputpanel.add(pcalcu); inputpanel.add(preset); p_canvas2 = new Particle_Canvas2(); t_canvas2 = new Title_Canvas2(); epanel = new Panel(); spanel = new Panel(); p_canvas2.setBackground(Color.black); t_canvas2.setBackground(Color.orange); t_canvas2.resize(size().width,30); setBackground(Color.orange); setLayout(new BorderLayout()); add("Center",p_canvas2); add("West",inputpanel); add("East",epanel); add("North",t_canvas2); add("South",spanel); } public boolean action(Event e, Object o) { String label = o.toString(); if (e.target instanceof Button) { if (label.equals("Calculate")) { r0 = Double.valueOf(tr0.getText()).doubleValue(); s0 = Double.valueOf(ts0.getText()).doubleValue(); psi0 = Double.valueOf(tpsi0.getText()).doubleValue(); if (auto.getState() == true) { au = 1; } else { au = 0; } setData(); p_canvas2.repaint(); } else { setState("5","0","150",false); } } return true; } public void setState(String r0,String s0,String psi0,boolean au) { tr0.setText(r0); ts0.setText(s0); tpsi0.setText(psi0); auto.setState(au); } public void setData() { pai = Math.PI; s0 = s0*pai/180; psi0 = psi0*pai/180; rmax = 2*r0; } } class Particle_Canvas2 extends Canvas { double pai,r0,s0,rmax; double psi0,dpsi,au; double x0,y0,ds,r,s,x,y,s00,r00; double s1rkg,s2rkg,s3rkg,s4rkg,s5rkg,s6rkg; double xrkg,zrkg,vrkg,hrkg; double yrkg[] = new double[2]; double frkg[] = new double[2]; double brkg[] = new double[2]; double crkg[] = new double[2]; double fx(double r, double s) { return r*Math.cos(s); } double fy(double r, double s) { return r*Math.sin(s); } public void paint(Graphics g) { r0 = light.r0; rmax = light.rmax; pai = Math.PI; s0 = light.s0; psi0 = light.psi0; dpsi = pai/18; au = light.au; x0 = r0*Math.cos(s0); y0 = r0*Math.sin(s0); s1rkg = 0.2928932188134527; s2rkg = 0.1213203435596426; s3rkg = 0.5857864376269054; s4rkg = 1.707106781186548; s5rkg = -4.121320343559643; s6rkg = 3.414213562373097; Rectangle c = bounds(); double xrate = c.width/(2*rmax); double yrate = c.height/(2*rmax); g.setColor(new Color(13,100,219)); for (int i = 0 ; i <= 2; i++) { g.drawRect(i,i,c.width-1-2*i,c.height-1-2*i); } for (int i = 1; i <=3; i++) { g.drawLine(i*c.width/4,0,i*c.width/4,c.height/40); g.drawLine(i*c.width/4,c.height,i*c.width/4,c.height-c.height/40-1); g.drawLine(0,i*c.height/4,c.width/40,i*c.height/4); g.drawLine(c.width,i*c.height/4,c.width-c.width/40-1,i*c.height/4); } g.setColor(Color.red); g.fillOval((int)((-1+rmax)*xrate), (int)((-1+rmax)*yrate), (int)(2*xrate), (int)(2*yrate)); g.setColor(Color.yellow); g.drawOval((int)((-rmax/50+rmax+x0)*xrate), (int)((-rmax/50+rmax-y0)*yrate), (int)(rmax/25*xrate), (int)(rmax/25*yrate)); if (au == 1) { for (int i = 0; i < 36; i++) { psi0 = psi0+dpsi; if (psi0 >= 2*pai) psi0 = psi0-2*pai; loop(g); } } else { loop(g); } } public void loop(Graphics g) { Rectangle c = bounds(); double xrate = c.width/(2*rmax); double yrate = c.height/(2*rmax); xrkg = s0; yrkg[0] = 1/r0; yrkg[1] = -Math.sqrt(1-yrkg[0])/r0 *(Math.tan(psi0)*Math.tan(s0)+1)/(Math.tan(psi0)-Math.tan(s0)); ds = Math.abs(psi0-s0)/20; if (psi0-s0 < 0 || psi0-s0 > pai) { ds = -ds; } if (s0 > 0 && s0-psi0 > pai) { ds = -ds; } hrkg = ds; zrkg = xrkg; vrkg = xrkg; while (1/yrkg[0] < rmax*Math.sqrt(2) && yrkg[0] < 1) { xrkg = vrkg; s00 = xrkg; r00 = 1/yrkg[0]; FUNRKG(); for (int j = 0; j < 2; j++) { brkg[j] = hrkg*frkg[j]; yrkg[j] = yrkg[j]+0.5*brkg[j]; crkg[j] = brkg[j]; } xrkg = vrkg+0.5*hrkg; FUNRKG(); for (int j = 0; j < 2; j++) { brkg[j] = hrkg*frkg[j]; yrkg[j] = yrkg[j]+s1rkg*(brkg[j]-crkg[j]); crkg[j] = s2rkg*crkg[j]+s3rkg*brkg[j]; } xrkg = vrkg+0.5*hrkg; FUNRKG(); for (int j = 0; j < 2; j++) { brkg[j] = hrkg*frkg[j]; yrkg[j] = yrkg[j]+s4rkg*(brkg[j]-crkg[j]); crkg[j] = s5rkg*crkg[j]+s6rkg*brkg[j]; } xrkg = vrkg+hrkg; FUNRKG(); for (int j = 0; j < 2; j++) { brkg[j] = hrkg*frkg[j]; yrkg[j] = yrkg[j]+brkg[j]/6-crkg[j]/3; } vrkg = vrkg+hrkg; zrkg = zrkg+ds; vrkg = zrkg; if (yrkg[0] < 0) break; s = xrkg; r = 1/yrkg[0]; g.setColor(Color.yellow); g.drawLine((int)((rmax+fx(r00,s00))*xrate), (int)((rmax-fy(r00,s00))*yrate), (int)((rmax+fx(r,s))*xrate), (int)((rmax-fy(r,s))*yrate)); } } public void FUNRKG() { frkg[0] = yrkg[1]; frkg[1] = -yrkg[0]+1.5*yrkg[0]*yrkg[0]; } } class Title_Canvas2 extends Canvas { public void paint(Graphics g) { g.setFont(new Font("TimesRoman",Font.PLAIN,15)); g.drawString("Light Path around Schwarzshild Black Hole",40,20); } }