// sin sinDlg.cpp : implementation file
//
#include "stdafx.h"
#include "sin sin.h"
#include "sin sinDlg.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CsinsinDlg dialog
CsinsinDlg::CsinsinDlg(CWnd* pParent /*=NULL*/)
: CDialog(CsinsinDlg::IDD, pParent)
, m_fd(20)
, m_pl(1)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CsinsinDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT2, m_fd);
DDX_Text(pDX, IDC_EDIT1, m_pl);
}
BEGIN_MESSAGE_MAP(CsinsinDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON1, &CsinsinDlg::DrawSin)
ON_BN_CLICKED(IDC_BUTTON2, &CsinsinDlg::cancel)
END_MESSAGE_MAP()
// CsinsinDlg message handlers
BOOL CsinsinDlg::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
ShowWindow(SW_MINIMIZE);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CsinsinDlg::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 CsinsinDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast(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
{
CDialog::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CsinsinDlg::OnQueryDragIcon()
{
return static_cast(m_hIcon);
}
void CsinsinDlg::DrawSin()
{
Complex *A,U,W,T;
const float PI=3.1415926;
int M=10;
int N=1024;
int LE,LE1,I,J,IP;
A = new Complex[2000];
//void ReverseOrder(int ,Complex *);
CDC *pDC;
pDC=GetDC();
CRect rect;
GetClientRect(&rect);
int i;
UpdateData(TRUE);
pDC->MoveTo(100,100);
for(i=0;i {
pDC->LineTo( 100+i,100 - (m_fd)*sin((double)((m_pl)*i*3.1415926/180.0)) );
//pDC->LineTo(100+i,100+(m_fd)*sin( (double)((m_pl)*i*180/3.1415926)) +
// (m_fd)*sin( (double)((m_pl*20)*i*180/3.1415926)) );
}
for(i=0;i {
A[i].Re=(m_fd)*sin( (double)((m_pl)*i*3.1415926/180.0));
A[i].Im=0;
}
ReverseOrder(N,A);
int L=1;
while(L {
LE=(int)pow(2.0,L);
LE1=LE/2;
U.Re=1.0f;
U.Im=0.0f;
//计算W算子的值
W.Re=(float)cos(PI/(1.0*LE1));
W.Im=(float)-1.0*sin(PI/(1.0*LE1));
if(abs(W.Re) W.Re=0.0f;
if(abs(W.Im)< 1.0e-12)
W.Im=0.0f;
J=1;
while(J {
I=J;
while(I {
IP=I+LE1;
//复数运算A×U
T.Re=(float)A[IP-1].Re*U.Re-A[IP-1].Im*U.Im;
T.Im=(float)A[IP-1].Re*U.Im+A[IP-1].Im*U.Re;
//复数运算A-T
A[IP-1].Re=(float)A[I-1].Re-T.Re;
A[IP-1].Im=(float)A[I-1].Im-T.Im;
//复数运算A+T
A[I-1].Re+=T.Re;
A[I-1].Im+=T.Im;
I+=LE;
}
float temp=U.Re;
//复数运算U×W
U.Re=(float)U.Re*W.Re-U.Im*W.Im;
U.Im=(float)temp*W.Im+U.Im*W.Re;
J++;
}
L++;
}
pDC->MoveTo(100,300-100);
pDC->LineTo(100,300+100);
pDC->MoveTo(100,300);
pDC->LineTo(100+1000,300);
CPen Red;
Red.CreatePen(PS_SOLID,1,RGB(255,0,0));;
pDC->SelectObject(&Red);
pDC->MoveTo(100,300);
for(i=0;i {
pDC->LineTo(100+i,300-20*log(sqrt(A[i].Re * A[i].Re + A[i].Im * A[i].Im)));
}
// TODO: Add your control notification handler code here
}
void CsinsinDlg::cancel()
{
OnOK();
// TODO: Add your control notification handler code here
}
void CsinsinDlg::ReverseOrder(int N, Complex *A)
{
int NV2=N/2;
int NM1=N-1;
int I,J,K=0;
//用于中介的复数变量T
Complex T;
I=J=1;
while(I {
if(I< J)
{
//借助于中间变量T,将A[J-1]的内容和A[I-1]的内容互换
T=A[J-1];
A[J-1]=A[I-1];
A[I-1]=T;
}
K=NV2;
while(K< J)
{
J-=K;
K/=2;
}
J+=K;
I++;
}
}