added Dipole element

This commit is contained in:
Ryan Tang 2022-12-23 00:08:26 -05:00
parent a290f4dc8b
commit d4818d9b00

77
geo.js
View File

@ -41,6 +41,12 @@ class basicShape{
ctx.stroke(this.shape);
ctx.restore();
}
draw(color){
let ctx = this.layer.getContext('2d');
ctx.fillStyle = color;
ctx.fill(this.shape);
}
}
class tandemClass extends basicShape{
@ -54,11 +60,6 @@ class tandemClass extends basicShape{
this.shape.arc(xy[0], xy[1]-w/2 - l, w/2, Math.PI, 2* Math.PI);
}
draw(color){
let ctx = this.layer.getContext('2d');
ctx.fillStyle = color;
ctx.fill(this.shape);
}
}
@ -117,12 +118,6 @@ class beamRectElement extends basicShape{
this.exitPos = [xy[0], xy[1] - l]
}
draw(color){
let ctx = this.layer.getContext('2d');
ctx.fillStyle = color;
ctx.fill(this.shape);
}
}
class beamCircleElement extends basicShape{
@ -142,12 +137,6 @@ class beamCircleElement extends basicShape{
let l = [r*Math.cos(rad), r*Math.sin(rad)];
return [xy[0] + l[0], xy[1] + l[1]];
}
draw(color){
let ctx = this.layer.getContext('2d');
ctx.fillStyle = color;
ctx.fill(this.shape);
}
}
class BeamSpilter extends basicShape{
@ -185,11 +174,28 @@ class BeamSpilter extends basicShape{
let l = [this.r*Math.cos(rad), this.r*Math.sin(rad)];
return translate(this.entracePos, l);
}
}
draw(color){
let ctx = this.layer.getContext('2d');
ctx.fillStyle = color;
ctx.fill(this.shape);
class dipole extends basicShape{
constructor(xy, r, rad){
super(staticLayer);
this.entracePos = xy;
let A = [xy[0] + r/2, xy[1]];
let B = [A[0] , A[1] - r*3/2*Math.tan(rad/2)];
let C = [xy[0] - r - r*3/2 * Math.cos(rad), xy[1] - r*3/2 * Math.sin(rad)];
let D = [xy[0] - r - r/2 * Math.cos(rad), xy[1] - r/2 * Math.sin(rad)];
let F = [xy[0] - r/2, xy[1]];
let E = [xy[0] - r/2, xy[1] - r/2*Math.tan(rad/2)];
this.shape.moveTo(A[0], A[1]);
this.shape.arcTo(B[0], B[1], C[0], C[1], r*3/2);
this.shape.lineTo(D[0],D[1]);
this.shape.arcTo(E[0], E[1], F[0], F[1], r/2);
this.shape.lineTo(A[0], A[1]);
this.exitPos = [(C[0] + D[0])/2, (C[1] + D[1])/2];
}
}
@ -213,9 +219,9 @@ let color = {
///========================= Sand Box;
//let windowSize = [staticLayer.width, staticLayer.height];
const deg = Math.PI/180;
let windowSize = [3840, 2160]; // 4K
//let windowSize = [2000, 1000];
let RFSource1 = new beamRectElement([windowSize[0]*0.9, windowSize[1]*0.8], 0, 40, 100);
let RFSource2 = new beamRectElement(RFSource1.exitPos, 0, 40, 20);
@ -226,13 +232,19 @@ let b1S = new beamLine(RFSource2.exitPos, 0, 200);
let tandem = new tandemClass(b1S.exitPos, 100, 100);
let b10 = new beamLine(tandem.exitPos, 0, 100); b10.offset = 8;
let b10a = new beamLine(b10.exitPos, 0, 400); b10a.offset = 11;
let bl0 = new beamLine(tandem.exitPos, 0, 300); bl0.offset = 8;
let bl0a = new beamLine(bl0.exitPos, 0, 400); bl0a.offset = 11;
let q1 = new beamRectElement(tandem.GetExitPos(50), 0, 60, 60);
let df1 = new beamRectElement(q1.GetExitPos(50), 0, 30, 40);
let df2 = new beamRectElement(df1.GetExitPos(20), 0, 30, 40);
//============ beam line for target room 1
let d1 = new dipole(bl0.exitPos, 80, Math.PI/2);
let bl1 = new beamLine(d1.exitPos, -Math.PI/2, 100);
let bfan1 = new BeamSpilter(bl1.exitPos, 50, -100 * deg);
RFSource1.draw(color.RFsourcce[0]);
@ -240,22 +252,23 @@ RFSource2.draw(color.RFsourcce[0]);
b1S.draw(color.BeamPipe[0]);
s1.draw(color.Dipole[0]);
tandem.draw(color.Tandem[0]);
b10.draw(color.BeamPipe[0]);
b10a.draw(color.BeamPipe[1]);
bl0.draw(color.BeamPipe[0]);
bl0a.draw(color.BeamPipe[1]);
q1.draw(color.Qpole[0]);
df1.draw(color.Deflector[0]);
df2.draw(color.Deflector[0]);
d1.draw(color.Dipole[0]);
bl1.draw(color.BeamPipe[0]);
bfan1.draw(color.Dipole[0]);
function lineMotion(){
b1S.march('red');
b10.march('red');
b10a.march('red');
bl0.march('red');
//bl0a.march('red');
bl1.march('red');
setTimeout(lineMotion, 20);
}
lineMotion();