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

📄 ͹

📁 读入凸轮表
💻
📖 第 1 页 / 共 2 页
字号:
// 凸轮加工仿真View.cpp : implementation of the CMyView class
//

#include "stdafx.h"
#include "凸轮加工仿真.h"

#include "凸轮加工仿真Doc.h"
#include "凸轮加工仿真View.h"
#include "math.h"
#include "MWheelDlg.h"
#include "CamDlg.h"
#include "DisplayDlg.h"

float cam_xx[3600],cam_yy[3600],cam360_xx[360],cam360_yy[360],xshift_x[3600],xshift_y[3600],r_t=45,rr=0,e=0,fDisplay_x=150,
fDisplay_y=150,fDisplay_scale=4,fMid_x=80,fMid_y=80,fMWheelDiameter=20,fxshift[3600],rotate_x[3600],rotate_y[3600],
fxshift_rotate,rotateShift_x[3600],rotateShift_y[3600];
enum {empty,cam,xshift,simulate}display;
int startangle;
CString CSCoorX[100]={"-80","-70","-60","-50","-40","-30","-20","-10","0","10","20","30","40","50","60","70","80"},CSCoorY[100]={"-80","-70","-60","-50","-40","-30","-20","-10","0","10","20","30","40","50","60","70","80"},CSAngle[360];

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

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

IMPLEMENT_DYNCREATE(CMyView, CScrollView)

BEGIN_MESSAGE_MAP(CMyView, CScrollView)
	//{{AFX_MSG_MAP(CMyView)
	ON_WM_TIMER()
	ON_COMMAND(CAL_CAM, OnCam)
	ON_COMMAND(CAL_XSHIFT, OnXshift)
	ON_COMMAND(ID_DISPLAY, OnDisplay)
	ON_COMMAND(ID_SIMULATE, OnSimulate)
	ON_WM_LBUTTONDOWN()
	ON_WM_RBUTTONDOWN()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()

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

CMyView::CMyView()
{
	// TODO: add construction code here

}

CMyView::~CMyView()
{
}

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

	return CScrollView::PreCreateWindow(cs);
}

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

void CMyView::OnDraw(CDC* pDC)
{
	CMyDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
////////////////////////////////
	CPen XShiftPen,BCPen;
	XShiftPen.CreatePen(PS_SOLID,1,RGB(255,0,0));
	BCPen.CreatePen(PS_DASHDOT,1,RGB(0,0,255));
	
	float scale;
	int pp,i,xori=100,yori=50;
	scale=fDisplay_scale;
	if(display==empty)
		pDC->TextOut(xori+50,yori-50,"升程表文件shengcheng.txt已经导入");
	if(display==cam||display==xshift){
		//画图
		pDC->TextOut(xori+50,yori-50,"凸轮轮廓(单位:mm)");
		//横坐标
		for(i=0;i<int(fDisplay_x/10)+2;i++)
		{
			pDC->TextOut(xori+i*10*scale,yori,CSCoorX[i]);
		}
		pDC->MoveTo(xori,yori);
		pDC->LineTo(xori+(int(fDisplay_x/10)*10+10)*scale,yori);
		for(i=0;i<int(fDisplay_y/10)+2;i++)
		{
			pDC->MoveTo(xori,yori+i*10*scale);
			pDC->LineTo(xori+(int(fDisplay_x/10)*10+10)*scale,yori+i*10*scale);
		}
		//纵坐标
		for(i=0;i<int(fDisplay_y/10)+2;i++)
		{
			pDC->TextOut(xori-50,yori+i*10*scale,CSCoorY[i]);
		}
		pDC->MoveTo(xori,yori);
		pDC->LineTo(xori,yori+(int(fDisplay_y/10)*10+10)*scale);
		for(i=0;i<int(fDisplay_x/10)+2;i++)
		{
			pDC->MoveTo(xori+i*10*scale,yori);
			pDC->LineTo(xori+i*10*scale,yori+(int(fDisplay_y/10)*10+10)*scale);
		}
		//凸轮轮廓
			for(pp=0;pp<3600;pp++)
			{

				if(pp==0) pDC->MoveTo(cam_xx[pp]*scale+xori+fMid_x*scale,cam_yy[pp]*scale+yori+fMid_y*scale);
				pDC->LineTo(cam_xx[pp]*scale+xori+fMid_x*scale,cam_yy[pp]*scale+yori+fMid_y*scale);
			}
			//画角度
			pDC->SelectObject(&XShiftPen);
			for(pp=0;pp<36;pp++)
				pDC->TextOut(cam360_xx[pp*10]*scale+xori+fMid_x*scale,cam360_yy[pp*10]*scale+yori+fMid_y*scale,CSAngle[pp*10]);

			//画基圆
			pDC->SelectObject(&BCPen);
			pDC->SelectStockObject(HOLLOW_BRUSH);
			pDC->Ellipse((fMid_x-(r_t-rr))*scale+xori,(fMid_y-(r_t-rr))*scale+yori,(fMid_x+(r_t-rr))*scale+xori,(fMid_y+(r_t-rr))*scale+yori);

	}
	if(display==xshift){
		pDC->SelectObject(&XShiftPen);
			for(pp=0;pp<3600;pp++)
			{

				if(pp==0) pDC->MoveTo(xshift_x[pp]*scale+xori+fMid_x*scale,xshift_y[pp]*scale+yori+fMid_y*scale);
					pDC->LineTo(xshift_x[pp]*scale+xori+fMid_x*scale,xshift_y[pp]*scale+yori+fMid_y*scale);
			}

	}
	if(display==simulate){
			float fMWheel_x,fMWheel_y;
			pDC->SelectStockObject(HOLLOW_BRUSH);
//		CString CoorP[6]={"0","10","20","30","40","50"};
			for(pp=0;pp<3600;pp++){
				if(pp==0) pDC->MoveTo(rotate_x[pp]*scale+xori+fMid_x*scale,rotate_y[pp]*scale+yori+fMid_y*scale);
				pDC->LineTo(rotate_x[pp]*scale+xori+fMid_x*scale,rotate_y[pp]*scale+yori+fMid_y*scale);
			}
			pDC->SelectObject(&XShiftPen);
			for(pp=0;pp<3600;pp++){
				if(pp==0) pDC->MoveTo(rotateShift_x[pp]*scale+xori+fMid_x*scale,rotateShift_y[pp]*scale+yori+fMid_y*scale);
				pDC->LineTo(rotateShift_x[pp]*scale+xori+fMid_x*scale,rotateShift_y[pp]*scale+yori+fMid_y*scale);
			}
			pDC->SelectStockObject(BLACK_PEN);
				fMWheel_x=xori+fMid_x*scale+fxshift_rotate*scale;
				fMWheel_y=yori+fMid_y*scale;
				pDC->Ellipse(fMWheel_x-(fMWheelDiameter/2)*scale,fMWheel_y-(fMWheelDiameter/2)*scale,
				fMWheel_x+(fMWheelDiameter/2)*scale,fMWheel_y+(fMWheelDiameter/2)*scale);
				pDC->Ellipse(fMWheel_x-0.5*scale,fMWheel_y-0.5*scale,
				fMWheel_x+0.5*scale,fMWheel_y+0.5*scale);


//			 	Invalidate(TRUE);
/*				pDC->MoveTo(0,300);
				pDC->LineTo(1100,300);
				
				pDC->MoveTo(300,0);
				pDC->LineTo(300,800);
				
				pDC->TextOut(1100,300,"p");
				
				pDC->TextOut(300,0,"s");



				for(i=0;i<6;i++)
				{
					pDC->TextOut(300+i*scale*10,300,CoorP[i]);
				}*/
		}
	
}


void CMyView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();

	CSize sizeTotal;
	// TODO: calculate the total size of this view
	sizeTotal.cx = sizeTotal.cy = 10000;
	Invalidate(TRUE);
	SetScrollSizes(MM_TEXT, sizeTotal);
}

/////////////////////////////////////////////////////////////////////////////
// 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
{
	CScrollView::AssertValid();
}

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

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

/////////////////////////////////////////////////////////////////////////////
// CMyView message handlers

void CMyView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	int pp,i;
	float fstartangle;

	if(startangle == 359) startangle=0;
	startangle=startangle+1;
	fstartangle=startangle;
	for(pp=0;pp<3600;pp++)
	{
		rotate_x[pp]=cam_xx[pp]*cos(fstartangle*3.1415926/180)-cam_yy[pp]*sin(fstartangle*3.1415926/180);
		rotate_y[pp]=cam_xx[pp]*sin(fstartangle*3.1415926/180)+cam_yy[pp]*cos(fstartangle*3.1415926/180);
	}
		for(pp=0;pp<3600;pp++)
	{
		rotateShift_x[pp]=xshift_x[pp]*cos(fstartangle*3.1415926/180)-xshift_y[pp]*sin(fstartangle*3.1415926/180);
		rotateShift_y[pp]=xshift_x[pp]*sin(fstartangle*3.1415926/180)+xshift_y[pp]*cos(fstartangle*3.1415926/180);
	}

	i=10*(fstartangle+90);
	if(i>3590) i=i-3600;
//	i=fstartangle*10;
	fxshift_rotate=fxshift[i];
	Invalidate(TRUE);
}

void CMyView::OnCam() 
{
	// TODO: Add your command handler code here
    float j[3600],h[3600],f[360],ff[3600],a[3600],b[3600],c[3600],d[3600],g[3600],l,r,m[3600],
		  s,ss,sd,p,s0,xx,yy,x,y,zz,z,fpp,dxdd,dydd;
	int max,n,k,u,pp,i=0;
	float t=0;
	char number[5];
	max=360;
	double temp;
	FILE * file;
	file=fopen("shengcheng.txt","r");
	CCamDlg CamDlg;
	CamDlg.m_fCamBCDiameter=r_t*2;
	CamDlg.m_fCamMWDiameter=rr*2;
	CamDlg.m_fE=e;
	CamDlg.DoModal();
	r_t=CamDlg.m_fCamBCDiameter/2;
	rr=CamDlg.m_fCamMWDiameter/2;
	e=CamDlg.m_fE;
	for(i=0;i<360;i++){
		fscanf(file,"%lf\n",&temp);
		f[i] =temp; 
	}
	fclose(file);
	for(i=0;i<max;i++)
		j[i]=i;

	//第2步
	for(i=0;i<max-1;i++)
	{

	h[i]=j[i+1]-j[i];

	ff[i]=(f[i+1]-f[i])/h[i];
	}
	//第3步(la,mu对应追赶法中a,c)
	for(i=0;i<max-2;i++)
	{
	a[i]=h[i+1]/(h[i+1]+h[i]);
	c[i]=1-a[i];

	g[i]=3*(c[i]*ff[i+1]+a[i]*ff[i]);
	}
	//构造追赶法中的b
	for(i=0;i<max-2;i++)
	{
		b[i]=2;
	}
	//最左侧导数
	l=0;
	//最右侧导数
	r=0;
	//构造追赶法中的d
	d[0]=g[0]-a[0]*l;

	for(i=1;i<max-3;i++)
	{
		d[i]=g[i];
	}

	d[max-3]=g[max-3]-c[max-3]*r;
	//追赶法中方程组个数
	n=max-2;
	//通过追赶法求m

⌨️ 快捷键说明

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