-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayFactor.js
More file actions
46 lines (45 loc) · 2.1 KB
/
Copy pathArrayFactor.js
File metadata and controls
46 lines (45 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* Array Factor (uniform linear array) — Balanis §6.4
*
* ψ = k·d·cosθ + β (k = 2π/λ, d = element spacing, β = progressive phase)
* AF(θ) = sin(N·ψ/2) / sin(ψ/2) (normalised peak = N at main lobe θ₀)
* Main lobe at ψ = 0 → cosθ₀ = −β/(k·d)
*/
document.getElementById('af-btn').addEventListener('click', function() {
var N=parseInt(document.getElementById('af-n').value);
var d=parseFloat(document.getElementById('af-d').value);
var theta0=parseFloat(document.getElementById('af-theta').value)*Math.PI/180;
if(isNaN(N)||N<2||isNaN(d)||d<=0) return;
var canvas=document.getElementById('af-canvas');
var ctx=canvas.getContext('2d');
var W=480,H=480,cx=W/2,cy=H/2,R=200;
ctx.clearRect(0,0,W,H);
ctx.strokeStyle='#ddd'; ctx.lineWidth=1;
for(var r=50;r<=R;r+=50){ctx.beginPath();ctx.arc(cx,cy,r,0,2*Math.PI);ctx.stroke();}
ctx.strokeStyle='#ccc';
for(var a=0;a<360;a+=30){
var ar=a*Math.PI/180;
ctx.beginPath(); ctx.moveTo(cx,cy); ctx.lineTo(cx+R*Math.sin(ar),cy-R*Math.cos(ar)); ctx.stroke();
}
ctx.fillStyle='#999'; ctx.font='11px monospace'; ctx.textAlign='center';
['0\u00b0','30\u00b0','60\u00b0','90\u00b0','120\u00b0','150\u00b0','180\u00b0','210\u00b0','240\u00b0','270\u00b0','300\u00b0','330\u00b0'].forEach(function(lbl,i){
var lr=(i*30)*Math.PI/180;
ctx.fillText(lbl, cx+(R+14)*Math.sin(lr), cy-(R+14)*Math.cos(lr)+4);
});
var nPts=720,maxAF=0,afs=[];
for(var i=0;i<nPts;i++){
var th=i*2*Math.PI/nPts;
var psi=2*Math.PI*d*(Math.sin(th)-Math.sin(theta0));
var af=Math.abs(psi)<1e-9?N:Math.abs(Math.sin(N*psi/2)/Math.sin(psi/2));
afs.push(af); if(af>maxAF)maxAF=af;
}
ctx.beginPath();
for(var j=0;j<nPts;j++){
var th2=j*2*Math.PI/nPts;
var r2=(afs[j]/maxAF)*R;
var x=cx+r2*Math.sin(th2),y=cy-r2*Math.cos(th2);
if(j===0) ctx.moveTo(x,y); else ctx.lineTo(x,y);
}
ctx.closePath(); ctx.strokeStyle='#AA77FF'; ctx.lineWidth=2; ctx.stroke();
ctx.fillStyle='rgba(170,119,255,0.15)'; ctx.fill();
});