/* * h8a.java - 18 Sep 07 - width 361, height 281 * @author jackord@kw.igs.net * distant sphere moving perpendicular to the viewing direction * at relativistic speeds * the co-ord system has x positive to the right, y positive downward, * and z positive going away from you * the sphere is transparent with gridlines in blue on the near * hemisphere (z<=0), and in red on the far hemisphere (z>0) */ import java.applet.Applet; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class h8a extends Applet implements ActionListener { double pi=Math.PI; String b1s="Plot"; Button b1=new Button(b1s); Choice ch=new Choice(); public void init() { setLayout(new FlowLayout(FlowLayout.LEFT)); setBackground(new Color(211, 211, 211)); ch.setBackground(getBackground()); ch.addItem("v/c=0.0"); ch.addItem("v/c=0.2"); ch.addItem("v/c=0.4"); ch.addItem("v/c=0.6"); ch.addItem("v/c=0.8"); add(ch); add(b1); b1.addActionListener(this); ch.select(0); } public void paint(Graphics g) { double be, ga, th, ph, r, rr, x, xp, y, z; int xo, yo, n, si, x1, y1, x2, y2; n=120; r=90.; xo=180; yo=130; si=ch.getSelectedIndex(); // Get velocity be=0.2*si; ga=1./Math.sqrt(1-be*be); // Beta and Gamma g.setColor(Color.black); g.drawRect(0, 0, 360, 280); g.setFont(new Font("Arial", Font.PLAIN, 16)); g.drawString("Sphere Moving to the Right at v/c = 0."+2*si, 45, 260); for (int i=1; i<=17; i=i+1) { // Latitude grid th=10*i*pi/180; rr=r*Math.sin(th); x=r*Math.cos(th); y=rr; z=0; xp=x/ga-be*z; // Find x co-ord x1=xo+(int)(xp); y1=yo+(int)(y); g.setColor(Color.red); for (int j=1; j<=n; j=j+1) { if (j==n/2) { g.setColor(Color.blue); } ph=3*j*pi/180; y=rr*Math.cos(ph); z=rr*Math.sin(ph); xp=x/ga-be*z; // Find x co-ord x2=xo+(int)(xp); y2=yo+(int)(y); g.drawLine(x1, y1, x2, y2); x1=x2; y1=y2; } } g.setColor(Color.red); for (int i=1; i<=36; i=i+1) { // Longitude grid if (i==18) { g.setColor(Color.blue); } ph=10*i*pi/180; x=-r; y=0; z=0; xp=x/ga-be*z; // Find x co-ord x1=xo+(int)(xp); y1=yo+(int)(y); for (int j=1; j<=n/2; j=j+1) { th=3*j*pi/180; x=-r*Math.cos(th); y=r*Math.sin(th)*Math.cos(ph); z=r*Math.sin(th)*Math.sin(ph); xp=x/ga-be*z; // Find x co-ord x2=xo+(int)(xp); y2=yo+(int)(y); g.drawLine(x1, y1, x2, y2); x1=x2; y1=y2; } } } public void actionPerformed(ActionEvent e) { // Button String tst; tst=e.getActionCommand(); if (b1s.equals(tst)) { repaint(); } } }