19,469
社区成员
发帖
与我相关
我的任务
分享
// CrankDlgDlg.cpp : implementation file
//
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "CrankDlg.h"
#include "CrankDlgDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCrankDlgDlg dialog
CCrankDlgDlg::CCrankDlgDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCrankDlgDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCrankDlgDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCrankDlgDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCrankDlgDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCrankDlgDlg, CDialog)
//{{AFX_MSG_MAP(CCrankDlgDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCrankDlgDlg message handlers
#define PI 3.1415926f
float Q1[360], Q2[360], w2[360], e2[360], s[360], v[360], a[360];
float maxs, maxv, maxa;
void Doit()
{
char prompt[260];
int i;
maxs = 0;
maxv = 0;
maxa = 0;
float l1=28.5;
float l2=64;
float e=20;
float n=44;
float p = PI / 180.0f;
float w1 = PI*n / 30.0f;
float f = (float)atan(e / sqrt((l2 - l1)*(l2 - l1) - e*e));
float f10 = PI - f;
float xc0 = (float)sqrt((l2 - l1)*(l2 - l1) - e*e);
for (i = 0;i <= 360;i++)
{
float f1 = f10 + i*p;
if (f1 > 2 * PI) f1 -= - 2 * PI;
Q1[i] = f1;
float sf2 =(float) (-(e + l1*sin(Q1[i])) / l2);
float f2 = (float)atan(sf2 / sqrt(1 - sf2*sf2));
if (f2 > 0) Q2[i] = f2;
else Q2[i] = (float)(2 * PI - fabs(f2));
w2[i] = (float)(-(l1*w1*cos(Q1[i] - Q2[i])) / l2);
e2[i] = (float)(l1*w2[i] * w2[i] * sin(Q1[i] - Q2[i])) / l2;
s[i] = (float)(l1*cos(Q1[i]) + l2*cos(Q2[i]) - xc0);
v[i] = (float)(-l1*w1*sin(Q1[i]) - l2*w2[i] * sin(Q2[i]));
a[i] = (float)(-l1*w1*w1*cos(Q1[i]) - l2*w2[i] * w2[i] * cos(Q2[i]) - l2*e2[i] * sin(Q2[i]));
if (fmod(i, 30) == 0.0)
{
sprintf(prompt,"%9.3f %9.3f %9.3f %9.3f %9.3f %9.3f %9.3f\n",
Q1[i]/p,Q2[i]/p,w2[i], e2[i], s[i], v[i]/1000,a[i]/1000);
afxDump << prompt ;
}
if (fabs(s[i]) > maxs) maxs = (float)fabs(s[i]);
if (fabs(v[i]) > maxv) maxv = (float)fabs(v[i]);
if (fabs(a[i]) > maxa) maxa = (float)fabs(a[i]);
}
}
//
void CCrankDlgDlg::drawl(float maxx, float maxy, float maxz,CDC &dc)
{
CPen *oldPen;
maxx = (float)(480 * 0.4 / maxx);
maxy = (float)(480 * 0.4 / maxy);
maxz = (float)(480 * 0.4 / maxz);
dc.MoveTo(0, 240); dc.LineTo(420,240);// --
dc.MoveTo(420, 240); dc.LineTo(413, 245);// >
dc.MoveTo(420, 240); dc.LineTo(413, 235);
dc.MoveTo(10, 0); dc.LineTo(10, 480);// |
dc.MoveTo(10, 0); dc.LineTo(5, 7);// ^
dc.MoveTo(10, 0); dc.LineTo(15, 7);
//red
dc.SetPixel(10, (int)(240-s[1] * maxx), RGB(255,0,0));
oldPen=dc.SelectObject(&m_redPen);
dc.MoveTo(35, 10); dc.LineTo(45,10);
dc.TextOut(50,0,"s",1);
dc.MoveTo(10, (int)(240 - s[1] * maxx));
for (int i = 2;i <= 360;i++)
{
dc.LineTo(i + 10, (int)(240 - s[i] * maxx));
}
//green
dc.SelectObject(&m_greenPen);
dc.SetPixel(10,(int)(240 - v[1] * maxy),RGB(0,255,0));
dc.MoveTo(35, 25); dc.LineTo(45, 25);
dc.TextOut(50,16,"v",1);
dc.MoveTo(10, (int)(240 - v[1] * maxy));
for (int j = 2;j <= 360;j++)
{
dc.LineTo(j+10, (int)(240 - v[j] * maxy));
}
//blue
dc.SelectObject(&m_bluePen);
dc.SetPixel(10,(int)(240 - a[1] * maxz),RGB(0,0,255));
dc.MoveTo(35, 40); dc.LineTo(45, 40);
dc.TextOut(50,30,"a",1);
dc.MoveTo(10, 240 - (int)(a[1] * maxz));
for (int k = 2;k <= 360;k++)
{
dc.LineTo(k + 10, (int)(240 - a[k] * maxz));
}
dc.SelectObject(oldPen);
}
BOOL CCrankDlgDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
Doit();
m_redPen.CreatePen(PS_SOLID,2,RGB(255,0,0));
m_greenPen.CreatePen(PS_SOLID,2,RGB(0,255,0));
m_bluePen.CreatePen(PS_SOLID,2,RGB(0,0,255));
return TRUE; // return TRUE unless you set the focus to a control
}
void CCrankDlgDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CCrankDlgDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC dc(this); // device context for painting
//CDialog::OnPaint();
drawl(maxs, maxv, maxa, dc);
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CCrankDlgDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}