小球撞击试实验报告 小球碰撞的四种情况

时间:2023-08-14 15:08:21 文档下载 投诉 投稿

        小球撞击试验报告

        试验目的:实现两个质量,速度不同的小球碰撞的物理过程。

        试验要求:可以任意输入两小球的速度和质量。

        试验实现过程:

        首先要有两个不同的小球,分别命名为小球A,小球B,通过画图软件画两个不同颜色的立体小球。

        其格式为.bmp。通过VC++的位图引入加载到资源当中。

         小球引入到资源后,就该实现两球的碰撞。1. 声明视图类变量。

         public:

         double mass_1,mass_2;

         double v1,v2;

         double m_ptpos1_x,m_ptpos1_y,m_ptpos2_x,m_ptpos2_y;

         CBitmap m_Bitmap,m_Bitmap1,m_Bitmap2;

         double n_FrameWidth,n_FrameWidth1,n_FrameWidth2;

         double n_FrameHeight,n_FrameHeight1,n_FrameHeight2; int i;

         CBrush m_BKBrush;

        2添加资源。

        3.初始化函数。

         mass_1=0;

         mass_2=0;

         v1=0;

         v2=0;

         i=0;

         CBitmap *pBitmap=new CBitmap;

         ASSERT(pBitmap); pBitmap->LoadBitmap(IDB_BITMAP4);

         m_BKBrush.CreatePatternBrush(pBitmap);

         delete pBitmap;

        4. 添加消息响应函数OnCreate

         CRect rect;

         GetClientRect(&rect);

         CXiaoQiudialog dlg;

         m_Bitmap2.LoadBitmap(IDB_BITMAP3);

         m_Bitmap.LoadBitmap(IDB_BITMAP1);

         m_Bitmap1.LoadBitmap(IDB_BITMAP2); BITMAP bm,bm1,bm2;

         m_Bitmap2.GetBitmap(&bm2);

         n_FrameHeight2=bm2.bmHeight;

         n_FrameWidth2=bm2.bmWidth;

         m_Bitmap1.GetBitmap(&bm1);

         n_FrameHeight1=bm1.bmHeight;

         n_FrameWidth1=bm1.bmWidth;

         m_Bitmap.GetBitmap(&bm);

         n_FrameWidth=bm.bmWidth;

         n_FrameHeight=bm.bmHeight;

         mass_1=dlg.m_M1; mass_2=dlg.m_M2;

         v1=dlg.m_V1;

         v2=dlg.m_V2;

         m_ptpos1_x=0;

         m_ptpos1_y=50;

         m_ptpos2_x=900;

         m_ptpos2_y=50;

         SetTimer(1,1,NULL);

        5.添加消息响应函数OnTimer

        CRect rect(m_ptpos1_x,m_ptpos1_y,m_ptpos1_x+n_FrameWidth,m_ptpos1_y+n_FrameHeight); CRect rect3(m_ptpos2_x,m_ptpos2_y,m_ptpos2_x+n_FrameWidth1,m_ptpos2_y+n_FrameHeight1);

         InvalidateRect(&rect3);

         InvalidateRect(&rect);

         UpdateWindow();

         CString str,str1;

         CStatusBar *pstatus=(CStatusBar*)AfxGetApp()->m_pMainWnd->GetDescendantWindow(ID_VIEW_STATUS_BAR);

         if (pstatus)

         {

         str1.Format("小球A的质量:%f,小球B的质量:%f",mass_1,mass_2); str.Format("速度:v1=%f:v2=%f",v1,v2);

         pstatus->SetPaneText(1,str);

         pstatus->SetPaneText(2,str1);

         }

         CRect rect1;

         GetClientRect(&rect1);

         CClientDC dc(this);

         CDC men,men1,men2,men3;

         if (m_ptpos1_x+n_FrameWidth>=m_ptpos2_x)

         { double v01=v1;

         double v02=v2;

         v1=((mass_1-mass_2)*v01+2*mass_2*v02)/(mass_1+mass_2);

         v2=((mass_2-mass_1)*v02+2*mass_1*v01)/(mass_1+mass_2);

         if (waveOutGetNumDevs()==0)

         {

         MessageBox("no audio device!","error");

         return;

         } MessageBeep(-1);

         if(m_ptpos1_x+n_FrameWidth>=rect1.right||m_ptpos1_x<rect1.left)//超出左右边界

         v1=-v1;

         if(m_ptpos2_x+n_FrameWidth>=rect1.right||m_ptpos2_x<=rect1.left)//超出左右边界

         v2=-v2;

         m_ptpos1_x+=v1;

         m_ptpos2_x+=v2;

         //CClientDC dc(this); men.CreateCompatibleDC(&dc);

         men1.CreateCompatibleDC(&dc);

        

         men.SelectObject(&m_Bitmap);

         CBitmap bitmapmask;

         bitmapmask.CreateBitmap(n_FrameWidth,n_FrameHeight,0,0,NULL);

         men1.SelectObject(&bitmapmask);

         men.SetBkColor(RGB(255,255,255));

         men1.BitBlt(0,0,n_FrameWidth,n_FrameHeight,&men,0,0,SRCCOPY);

         dc.BitBlt(m_ptpos1_x,m_ptpos1_y,n_FrameWidth,n_FrameHeight,&men,0,0,SRCINVERT);

         dc.BitBlt(m_ptpos1_x,m_ptpos1_y,n_FrameWidth,n_FrameHeight,&men1,0,0,SRCAND);

         dc.BitBlt(m_ptpos1_x,m_ptpos1_y,n_FrameWidth,n_FrameHeight,&men,0,0,SRCINVERT);

        

        

        

         men2.CreateCompatibleDC(&dc);

         men3.CreateCompatibleDC(&dc);

        

         men2.SelectObject(&m_Bitmap1);

         CBitmap bitmapmask1; bitmapmask1.CreateBitmap(n_FrameWidth1,n_FrameHeight1,0,0,NULL);

         men3.SelectObject(&bitmapmask1);

         men2.SetBkColor(RGB(255,255,255));

         men3.BitBlt(0,0,n_FrameWidth1,n_FrameHeight1,&men2,0,0,SRCCOPY);

         dc.BitBlt(m_ptpos2_x,m_ptpos2_y,n_FrameWidth1,n_FrameHeight1,&men2,0,0,SRCINVERT);

         dc.BitBlt(m_ptpos2_x,m_ptpos2_y,n_FrameWidth1,n_FrameHeight1,&men3,0,0,SRCAND);

         dc.BitBlt(m_ptpos2_x,m_ptpos2_y,n_FrameWidth1,n_FrameHeight1,&men2,0,0,SRCINVERT);

        6. 添加函数OnSetting

         CXiaoQiudialog dlg;

         dlg.m_V1=v1;

         dlg.m_V2=v2;

         dlg.m_M1=mass_1;

         dlg.m_M2=mass_2;

         if (dlg.DoModal()==IDOK)

         {

         v1=dlg.m_V1;

         v2=dlg.m_V2;

         mass_1=dlg.m_M1; mass_2=dlg.m_M2;

         }

        7. 添加函数OnEraseBkgnd

        CBrush *poldbrush=pDC->SelectObject(&m_BKBrush);

         CRect rect;

         pDC->GetClipBox(&rect);

         pDC->PatBlt(rect.left,rect.top,rect.Width(),rect.Height(),PATCOPY);

         pDC->SelectObject(poldbrush);

        以上就是我的设计思路与实现代码。

【小球撞击试实验报告 小球碰撞的四种情况】相关文章:

审计报告的类型 审计报告的类型及出具条件08-14

实习报告1000字【】08-14

毕业实习报告1000字 毕业实践报告5000字08-14

碰撞实验报告 碰撞实验报告结论08-14

碰撞动量守恒实验报告 碰撞与动量守恒实验报告08-14

碰撞实验实验报告 碰撞实验实验报告思考题08-14

小球撞击试实验报告 小球碰撞的四种情况08-14

碰撞实验报告 碰撞实验报告光电门数据08-14

碰撞实验实验报告 碰撞实验实验报告结论08-14

乒乓球碰撞恢复系数测量实验报告 乒乓球撞击打法08-14

研习报告 研学报告怎么写08-14

教育研习报告1 主题教育调研报告范文08-14

实习报告范文5000字 毕业实践报告范文2000字08-14