//photon.java import java.awt.Graphics; import java.awt.Color; import java.awt.Point; class interPoint { public double x,y; public interPoint(double x, double y) { this.x =x; this.y = y; } } public class photon { public double length = 0; public double y = 0; boolean left = false; double pos = 0; Einstein EIN; public photon(Einstein EIN) { this.EIN = EIN; left = false; pos = 0; } public void setLength(double st) { length = st; } public double dist(double x1, double y1, double x2, double y2) { return (Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))); } public interPoint intersects(double x1, double y1, double m1,double x2, double y2, double m2) { double x_int = 0; double y_int = 0; if (m2 == 0) { x_int = x2; } else { double x_top = (m1*x1 - y1 - m2*x2 + y2); double x_bot = (m1 - m2); x_int = ( x_top / x_bot ); } y_int = m1*(x_int-x1)+y1; return (new interPoint(x_int,y_int)); } public void spacedraw(double theTime, double position, double gamma,double theV, int height, Graphics g) { g.setColor(Color.yellow); double L = 2*length; if (left) { for(int loop=0;loop<4;loop++) { g.drawLine(EIN.space.mapX(position)+(int)(length)-(int)(pos*L)-loop,EIN.space.mapY(0)-(int)(height*.5),EIN.space.mapX(position)+(int)(length)-(int)(pos*L)-loop,EIN.space.mapY(0)+(int)(height*.5)); //g.drawLine(EIN.space.mapX(position)+(int)(length)-(int)(pos*L-1),EIN.space.mapY(0)-(int)(height*.5),EIN.space.mapX(position)+(int)(length)-(int)((pos*L)-1),EIN.space.mapY(0)+(int)(height*.5)); } } else { for (int loop=0;loop<4;loop++) { g.drawLine(EIN.space.mapX(position)-(int)(length)+(int)(pos*L)-loop,EIN.space.mapY(0)-(int)(height*.5),EIN.space.mapX(position)-(int)(length)+(int)(pos*L)-loop,EIN.space.mapY(0)+(int)(height*.5)); //g.drawLine(EIN.space.mapX(position)-(int)(length)+(int)(pos*L)-1,EIN.space.mapY(0)-(int)(height*.5),EIN.space.mapX(position)-(int)(length)+(int)(pos*L)-1,EIN.space.mapY(0)+(int)(height*.5)); } } /*double v = 0; if (theV != 0) { v = 1/theV; } double startx = -length; double starty = 0; double total =0; boolean stopped = false; double L = 2*length; while(total < theTime) { //Right side first interPoint test = intersects(startx,starty,1,length,0,v,g); if (theTime > test.y) { total = test.y; startx = test.x; starty = test.y; } else { //EIN.time.drawLine(startx,starty,startx+(theTime - total),theTime,g); g.drawLine(EIN.space.mapX(position)-(int)(length/gamma)+(int)((theTime - total)/(L/gamma)),EIN.space.mapY(0)-(int)(height*.5),EIN.space.mapX(position)-(int)(length/gamma)+(int)((theTime - total)/(L/gamma)),EIN.space.mapY(0)+(int)(height*.5)); g.drawLine(EIN.space.mapX(position)-(int)(length/gamma)+(int)(((theTime - total)/(L/gamma))-1),EIN.space.mapY(0)-(int)(height*.5),EIN.space.mapX(position)-(int)(length/gamma)+(int)(((theTime - total)/(L/gamma))-1),EIN.space.mapY(0)+(int)(height*.5)); stopped = true; total = theTime; } //Left side now if (!stopped) { test = intersects(startx,starty,-1,-length,0,v,g); g.drawString("I: x "+test.x+" y "+test.y,(int)EIN.time.mapX(0),100); if (theTime > test.y) { total = test.y; startx = test.x; starty = test.y; } else { //EIN.time.drawLine(startx,starty,startx-(theTime - total),theTime,g); g.drawLine(EIN.space.mapX(position)+(int)(length/gamma)-(int)((theTime - total)/(L/gamma)),EIN.space.mapY(0)-(int)(height*.5),EIN.space.mapX(position)+(int)(length/gamma)-(int)((theTime - total)/(L/gamma)),EIN.space.mapY(0)+(int)(height*.5)); g.drawLine(EIN.space.mapX(position)+(int)(length/gamma)-(int)(((theTime - total)/(L/gamma))-1),EIN.space.mapY(0)-(int)(height*.5),EIN.space.mapX(position)+(int)(length/gamma)-(int)(((theTime - total)/(L/gamma))-1),EIN.space.mapY(0)+(int)(height*.5)); stopped = true; total = theTime; } } }*/ } public void draw(double theTime, double theX, double theV, Graphics g) { g.setColor(Color.yellow); /*double start = -length; double ystart = y; boolean right = true; while (theTime > 0) { if (right) { if ((theTime-length) > (theX+length)) { EIN.time.drawLine(start,ystart,(theX+length),(theX+length) */ double v = 0; if (theV != 0) { v = 1/theV; } /*interPoint test = intersects(-length,y,1,length,y,v,g); g.drawString("I: x "+test.x+" y "+test.y,(int)EIN.time.mapX(0),50); if (theTime > test.y) { EIN.showStatus("Dist "+dist(test.x,test.y,theX,theTime)+" "+dist(1,-1.5,56,70)); EIN.time.drawLine(test.x,test.y,test.x-(theTime-test.x-length),theTime,g); }*/ double startx = -length; double starty = 0; double total =0; boolean stopped = false; while(total < theTime) { //Right side first interPoint test = intersects(startx,starty,1,length,0,v); if (theTime > test.y) { EIN.time.drawLine(startx,starty,test.x,test.y,g); total = test.y; startx = test.x; starty = test.y; } else { EIN.time.drawLine(startx,starty,startx+(theTime - total),theTime,g); left = false; if ((test.x-startx) != 0) pos = (theTime - total)/(test.x-startx); else pos = 0; stopped = true; total = theTime; } //Left side now if (!stopped) { test = intersects(startx,starty,-1,-length,0,v); if (theTime > test.y) { EIN.time.drawLine(startx,starty,test.x,test.y,g); total = test.y; startx = test.x; starty = test.y; } else { EIN.time.drawLine(startx,starty,startx-(theTime - total),theTime,g); left = true; if ((startx-test.x) != 0) pos = (theTime - total)/(startx-test.x); else pos = 0; stopped = true; total = theTime; } } } //EIN.showStatus((theTime - total)+" Percent:"+pos); } }