⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 中子屏蔽view.cpp

📁 使用蒙特卡洛方法研究中子屏蔽以活求碰撞情况
💻 CPP
字号:
// 中子屏蔽View.cpp : implementation of the CMyView class
//

#include "stdafx.h"
#include "中子屏蔽.h"
#include <cmath>
#include "中子屏蔽Doc.h"
#include "d.h"
#include "中子屏蔽View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyView

IMPLEMENT_DYNCREATE(CMyView, CView)

BEGIN_MESSAGE_MAP(CMyView, CView)
	//{{AFX_MSG_MAP(CMyView)
	ON_COMMAND(ID_FILE_DO, OnFileDo)
	ON_WM_TIMER()
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CMyView construction/destruction

CMyView::CMyView()
{
	// TODO: add construction code here
	x_0=0.5;y_0=0;z_0=1;
	x_1=0;y_1=0.5;z_1=1;
	x_2=0.75;y_2=0.25;z_2=0;       //正交基初始化,即选定了投影面
}

CMyView::~CMyView()
{
}

BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMyView drawing

void CMyView::OnDraw(CDC* pDC)
{
	CMyDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	double x_1=1,y_1=0,z_1=1,x_2=1,y_2=1,z_2=1,x_3=0,y_3=1,z_3=1,x_4=0,y_4=0,z_4=1,x_5=1,y_5=0,z_5=0,x_6=1,y_6=1,z_6=0,x_7=0,y_7=1,z_7=0,x_8=0,y_8=0,z_8=0;
	double a=3.14/10;
	x_1=Rotatex(x_1,y_1,a);y_1=Rotatey(x_1,y_1,a);CPoint A1=Project(x_1,y_1,z_1);
	x_2=Rotatex(x_2,y_2,a);y_2=Rotatey(x_2,y_2,a);CPoint B1=Project(x_2,y_2,z_2);
	x_3=Rotatex(x_3,y_3,a);y_3=Rotatey(x_3,y_3,a);CPoint C1=Project(x_3,y_3,z_3);
	x_4=Rotatex(x_4,y_4,a);y_4=Rotatey(x_4,y_4,a);CPoint D1=Project(x_4,y_4,z_4);
	x_5=Rotatex(x_5,y_5,a);y_5=Rotatey(x_5,y_5,a);CPoint A2=Project(x_5,y_5,z_5);
	x_6=Rotatex(x_6,y_6,a);y_6=Rotatey(x_6,y_6,a);CPoint B2=Project(x_6,y_6,z_6);
	x_7=Rotatex(x_7,y_7,a);y_7=Rotatey(x_7,y_7,a);CPoint C2=Project(x_7,y_7,z_7);
	x_8=Rotatex(x_8,y_8,a);y_8=Rotatey(x_8,y_8,a);CPoint D2=Project(x_8,y_8,z_8);
	pDC->MoveTo(A1);
	pDC->LineTo(B1);
	pDC->MoveTo(B1);
	pDC->LineTo(C1);
	pDC->MoveTo(B1);
	pDC->LineTo(B2);
	pDC->MoveTo(B2);
	pDC->LineTo(A2);
	pDC->MoveTo(A2);
	pDC->LineTo(A1);
	pDC->MoveTo(B2);
	pDC->LineTo(C2);
	pDC->MoveTo(C1);
	pDC->LineTo(C2);
	pDC->MoveTo(A1);
	pDC->LineTo(D1);
	pDC->MoveTo(D1);
	pDC->LineTo(C1);
	pDC->MoveTo(D1);
	pDC->LineTo(D2);
	pDC->MoveTo(D2);
	pDC->LineTo(A2);
	pDC->MoveTo(D2);
	pDC->LineTo(C2);




	

}

/////////////////////////////////////////////////////////////////////////////
// CMyView printing

BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CMyView diagnostics

#ifdef _DEBUG
void CMyView::AssertValid() const
{
	CView::AssertValid();
}

void CMyView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CMyDoc* CMyView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
	return (CMyDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////


CPoint CMyView::Project(double x_,double y_,double z_)    //投影函数的实现,计算方法见帮助文档
{
	double x,y;
	x=300+200*((x_-x_0)*(x_1-x_0)+(y_-y_0)*(y_1-y_0)+(z_-z_0)*(z_1-z_0))/sqrt((x_1-x_0)*(x_1-x_0)+(y_1-y_0)*(y_1-y_0)+(z_1-z_0)*(z_1-z_0));
	y=100+200*((x_-x_0)*(x_2-x_0)+(y_-y_0)*(y_2-y_0)+(z_-z_0)*(z_2-z_0))/sqrt((x_2-x_0)*(x_2-x_0)+(y_2-y_0)*(y_2-y_0)+(z_2-z_0)*(z_2-z_0));
	//显示的时候以屏幕的(300,100)为投影面上一组正交基的原点
	return CPoint ((int)x,(int)y);
}

double CMyView::Rotatex(double x_,double y_,double a)
{
	x_=x_*cos(a)+y_*sin(a);
	y_=-x_*sin(a)+y_*cos(a);
	return x_;
}
double CMyView::Rotatey(double x_,double y_,double a)
{
	x_=x_*cos(a)+y_*sin(a);
	y_=-x_*sin(a)+y_*cos(a);
	return y_;
}

void CMyView::OnFileDo() 
{
	// TODO: Add your command handler code here
	SetTimer(1,0,NULL);
}

void CMyView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	srand(time(0));
	prime=new Nucleus(H);
	prime->next=new Nucleus(O);
	prime->next->previous=prime;
	prime->next->next=new Nucleus(N);
	prime->next->next->previous=prime->next;
	MainSpace ms(prime,Thickness);
	accompany=false;									//enum Nreactiontype{N2N,Elastic_Deflection,Nonelastic_Deflection,Capture};
	Neutron * pro;
	for(int k=0;k<=300;k++)
	   {
		ms.Action(0.001);
        for (pro=ms.headneutron;pro;pro=pro->next)
		CClient DC(this);
		DC.Ellipse((pro->PositionX)*100,(pro->PositionY)*100,(pro->PositionX)*100+2,(pro->PositionY)*100+2);
	}
	CView::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -