📄 pbgview.cpp
字号:
// PBGView.cpp : implementation of the CPBGView class
//
#include "stdafx.h"
#include <complex>
#include "PBG.h"
#include "math.h"
#include "PBGDoc.h"
#include "PBGView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPBGView
IMPLEMENT_DYNCREATE(CPBGView, CView)
BEGIN_MESSAGE_MAP(CPBGView, CView)
//{{AFX_MSG_MAP(CPBGView)
ON_COMMAND(IDC_PBG, OnPbg)
ON_COMMAND(IDC_REFRACTIVE, OnRefractive)
ON_COMMAND(IDC_FILLING, OnFilling)
ON_COMMAND(IDC_BANDWIDTH, OnBandwidth)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPBGView construction/destruction
CPBGView::CPBGView()
{
// TODO: add construction code here
}
CPBGView::~CPBGView()
{
}
BOOL CPBGView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CPBGView drawing
void CPBGView::OnDraw(CDC* pDC)
{
CPBGDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CPBGView printing
BOOL CPBGView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CPBGView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CPBGView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CPBGView diagnostics
#ifdef _DEBUG
void CPBGView::AssertValid() const
{
CView::AssertValid();
}
void CPBGView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CPBGDoc* CPBGView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPBGDoc)));
return (CPBGDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CPBGView message handlers
void CPBGView::OnPbg()
{
CClientDC dc(this);
double Kz = 0.;
double w = 0.;
double ainc = 0.;
const double pi = 3.14159265;
const double n1 = 1.4;
const double n2 = 3.4;
const double n = 2;
const double c = 3.0*100000000;
const double a = 50.0*0.000000001;
const double b = 50.0*0.000000001;
CString str;
using namespace std;
for(Kz=0.,ainc=0.;Kz<1.0;Kz+=0.002,ainc+=0.00314)
{
for(w=0.0;w<0.3;w+=0.005)
{
complex<double> data1(w*w*n1*n1-Kz*Kz,0);
complex<double> data2(w*w*n2*n2-Kz*Kz,0);
complex<double> data3(w*w*n1*n1-n*w*w*sin(ainc)*sin(ainc),0);
complex<double> data4(w*w*n2*n2-n*w*w*sin(ainc)*sin(ainc),0);
complex<double> K2=(2*pi*sqrt((data2))/(a+b));
complex<double> K1=(2*pi*sqrt((data1))/(a+b));
complex<double> K3=2*pi*sqrt((data3))/(a+b);
complex<double> K4=2*pi*sqrt((data4))/(a+b);
complex<double> temp = cos(K2*b)*cos(K1*a)-(K2/K1+K1/K2)*sin(K2*b)*sin(K1*a)*0.5;
complex<double> temp1=(cos(K2*b)*cos(K1*a)-
(K2*n1*n1/(K1*n2*n2)+K1*n2*n2/(K2*n1*n1))*sin(K2*b)*sin(K1*a)*0.5);
complex<double> temp3= cos(K4*b)*cos(K3*a)-(K4/K3+K3/K4)*sin(K4*b)*sin(K3*a)*0.5;
complex<double> temp4=(cos(K4*b)*cos(K3*a)-
(K4*n1*n1/(K3*n2*n2)+K3*n2*n2/(K4*n1*n1))*sin(K4*b)*sin(K3*a)*0.5);
double result = (temp.real()*temp.real()+temp.imag()*temp.imag());
double result1 = (temp1.real()*temp1.real()+temp1.imag()*temp1.imag());
double result3 = (temp3.real()*temp3.real()+temp3.imag()*temp3.imag());
double result4 = (temp4.real()*temp4.real()+temp4.imag()*temp4.imag());
if(result<=1.0)
{
dc.SetPixel(Kz*350,300-350*w,RGB(255,255,0));
}
if(result>1)
{
dc.SetPixel(Kz*350,300-350*w,RGB(0,0,0));
}
if(result1<=1.0)
{
dc.SetPixel(Kz*350+400,300-350*w,RGB(255,255,0));
}
if(result1>1)
{
dc.SetPixel(Kz*350+400,300-350*w,RGB(0,0,0));
}
if(result3<=1.0)
{
dc.SetPixel(ainc*200.,700-400*w,RGB(255,255,0));
}
if(result3>1)
{
dc.SetPixel(ainc*200.,700-400*w,RGB(0,0,0));
}
if(result4<=1.0)
{
dc.SetPixel(ainc*200+400.,700-400*w,RGB(255,255,0));
}
if(result4>1)
{
dc.SetPixel(ainc*200+400,700-400*w,RGB(0,0,0));
}
}
}
MessageBox("The End");
}
void CPBGView::OnRefractive()
{
CClientDC dc(this);
CPen pen;
pen.CreatePen(PS_SOLID,10,RGB(255,255,0));
dc.SelectObject(pen);
double Kz = 0.;
double w = 0.;
double ainc = 0.;
const double pi = 3.14159265;
double n1 = 3.0;
double n2 = 3.4;
double n = 2;
const double c = 3.0*100000000;
const double a = 50.0*0.000000001;
const double b = 50.0*0.000000001;
double min[10] = {0.};
double max[10] = {10000.,10000,100000,10000,10000,10000,10000,10000,10000};
double reftactive[10]={0.};
int forbit = -1;
int in_forbit = 0;
int in_unforbit = 0;
int total_number= 0;
using namespace std;
for(n1=1.2;n1<3.0;n1+=0.2)
for(n2=n1;n2<n;n2+=n/50.)
{
n = n1*3;
total_number= 0;
for(int i=0;i<10;i++)
{
min[i]=0;
max[i]=10000;
}
for(Kz=0.02;Kz<1.0&&total_number!=-1;Kz+=0.002)
{
forbit = -1;
in_forbit = 0;
in_unforbit = 0;
for(w=0.002;w<0.3&&total_number!=-1;w+=0.002)
{
complex<double> data1(w*w*n1*n1-Kz*Kz,0);
complex<double> data2(w*w*n2*n2-Kz*Kz,0);
complex<double> K2=(2*pi*sqrt((data2))/(a+b));
complex<double> K1=(2*pi*sqrt((data1))/(a+b));
complex<double> temp = cos(K2*b)*cos(K1*a)-(K2/K1+K1/K2)*sin(K2*b)*sin(K1*a)*0.5;
complex<double> temp1=(cos(K2*b)*cos(K1*a)-
(K2*n1*n1/(K1*n2*n2)+K1*n2*n2/(K2*n1*n1))*sin(K2*b)*sin(K1*a)*0.5);
// double result = sqrt(temp.real()*temp.real()+temp.imag()*temp.imag());
double result1 = (temp1.real()*temp1.real()+temp1.imag()*temp1.imag());
if(result1>1.0)
{
if(in_forbit<3)
in_forbit++;
if(in_forbit==2)
{
if(forbit<0)
forbit=0;
else
forbit++;
if(w-0.01>min[forbit])
min[forbit] = w-0.04;
if(fabs(min[forbit]-max[forbit])<0.003&&min[forbit]!=0)
{
reftactive[forbit]=Kz/min[forbit];
total_number = -1;
}
in_unforbit=0;
}
}
if(result1<=1)
{
if(in_unforbit<3&&forbit>=0)
in_unforbit++;
if(in_unforbit==2)
{
if(w-0.01<max[forbit])
max[forbit] = w-0.04;
in_forbit = 0;
}
}
}
}
dc.SetPixel((n2/n1)*60,600-35*reftactive[1],RGB(n1*25,0,0));
}
// dc.SelectObject(oldPen);
}
void CPBGView::OnFilling()
{
CClientDC dc(this);
double Kz = 0.1;
double w = 1.0;
const double pi = 3.14159265;
const double n1 = 1.4;
const double n2 = 3.4;
const double n = 2;
const double c = 3.0*100000000;
double a = 5.0;
double b = 5.0;
CString str;
using namespace std;
for(b=0.0;b<5.;b+=0.005)
{
for(w=0.0;w<1.0;w+=0.002)
{
complex<double> data1(w*w*n1*n1-Kz*Kz,0);
complex<double> data2(w*w*n2*n2-Kz*Kz,0);
complex<double> K2=(2*pi*sqrt((data2))/(a+b));
complex<double> K1=(2*pi*sqrt((data1))/(a+b));
complex<double> temp = cos(K2*b)*cos(K1*a)-(K2/K1+K1/K2)*sin(K2*b)*sin(K1*a)*0.5;
complex<double> temp1=(cos(K2*b)*cos(K1*a)-
(K2*n1*n1/(K1*n2*n2)+K1*n2*n2/(K2*n1*n1))*sin(K2*b)*sin(K1*a)*0.5);
double result = (temp.real()*temp.real()+temp.imag()*temp.imag());
double result1 = (temp1.real()*temp1.real()+temp1.imag()*temp1.imag());
if(result<=1.0)
{
dc.SetPixel(b*70,600-350*w,RGB(255,255,0));
}
if(result>1)
{
dc.SetPixel(b*70,600-350*w,RGB(0,0,0));
}
if(result1<=1.0)
{
dc.SetPixel(b*70+400,600-350*w,RGB(255,255,0));
}
if(result1>1)
{
dc.SetPixel(b*70+400,600-350*w,RGB(0,0,0));
}
}
}
MessageBox("The End");
}
void CPBGView::OnBandwidth()
{
CClientDC dc(this);
double Kz = 0.1;
double w = 0.002;
const double pi = 3.14159265;
double n1 = 1.4;
double n2 = 3.4;
double n = 2;
const double c = 3.0*100000000;
const double a = 50.0*0.000000001;
const double b = 50.0*0.000000001;
CString str;
using namespace std;
for(n1=1.2;n1<=3.0;n1+=0.2)
{
double total_w_te = 0.0;
double total_w_tm = 0.0;
double total_w = 0.0;
n=n1*3.;
for(n2=n1;n2<=n;n2+=n/(800.*n1))
{
int end_of_te= 0;
int end_of_tm= 0;
int start_of_te = 0;
int start_of_tm = 0;
for(w=0.2;w<1.0;w+=0.005)
{
complex<double> data1(w*w*n1*n1-Kz*Kz,0);
complex<double> data2(w*w*n2*n2-Kz*Kz,0);
complex<double> K2=(2*pi*sqrt((data2))/(a+b));
complex<double> K1=(2*pi*sqrt((data1))/(a+b));
complex<double> temp = cos(K2*b)*cos(K1*a)-(K2/K1+K1/K2)*sin(K2*b)*sin(K1*a)*0.5;
complex<double> temp1=(cos(K2*b)*cos(K1*a)-
(K2*n1*n1/(K1*n2*n2)+K1*n2*n2/(K2*n1*n1))*sin(K2*b)*sin(K1*a)*0.5);
double result = (temp.real()*temp.real()+temp.imag()*temp.imag());
double result1 = (temp1.real()*temp1.real()+temp1.imag()*temp1.imag());
if(result>1&&!end_of_te)
{
total_w_te = w;
end_of_te = 1;
start_of_te = 1;
}
if(result<=1&&start_of_te)
{
end_of_te = 1;
total_w = w;
}
if(result1>1&&!end_of_tm)
{
total_w_tm += w;
start_of_tm = 1;
}
if(result1<=1&&start_of_tm)
{
end_of_tm = 1;
}
// total_w += w;
}
dc.SetPixel((n2/n1)*100,500-500*(total_w-total_w_te),RGB(0,255,0));
// dc.SetPixel((n2/n1)*100,600-5000*total_w_tm/total_w,RGB(255,0,0));
}
}
MessageBox("The End");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -