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

📄 dlg_sort3.cpp

📁 bayes分类的数值实现
💻 CPP
字号:
// DLG_SORT3.cpp : implementation file
//

#include "stdafx.h"
#include "第一次作业.h"
#include "DLG_SORT3.h"

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

/////////////////////////////////////////////////////////////////////////////
// DLG_SORT3 dialog


DLG_SORT3::DLG_SORT3(CWnd* pParent /*=NULL*/)
	: CDialog(DLG_SORT3::IDD, pParent)
{
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			a[i][j]=0;
	//{{AFX_DATA_INIT(DLG_SORT3)
	Gx1 = 0.0;
	Gx2 = 0.0;
	Gx3 = 0.0;
	m_Result = _T("");
	//}}AFX_DATA_INIT
}


void DLG_SORT3::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(DLG_SORT3)
	DDX_Text(pDX, IDC_EDIT_gx1, Gx1);
	DDX_Text(pDX, IDC_EDIT_gx2, Gx2);
	DDX_Text(pDX, IDC_EDIT_gx3, Gx3);
	DDX_Text(pDX, IDC_STATIC_W, m_Result);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(DLG_SORT3, CDialog)
	//{{AFX_MSG_MAP(DLG_SORT3)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// DLG_SORT3 message handlers

void DLG_SORT3::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	int i,j;
	dc.SetBkMode(TRANSPARENT);	
	CRect rect;
	GetClientRect(rect);
	dc.FillSolidRect(rect,RGB(255,255,255)); //设置为白色背景
	CPoint p;
	float g[3];
	float x,y;
	for(i=20;i<rect.Width()-20;i++)
		for(j=20;j<rect.Height()-20;j++)
		{	
			x=float(i-rect.Width()/2)/20;//相对坐标
			y=float(rect.Height()/2-j)/20;//相对坐标	
			
			for(int k=0;k<3;k++)
				g[k]=a[k][0]*x*x+a[k][1]*y*y+a[k][2]*x+a[k][3]*y+a[k][4]*x*y+a[k][5];
	//		g[0]=(a[0][0]-a[1][0])*x*x+(a[0][1]-a[1][1])*y*y+(a[0][2]-a[1][2])*x+(a[0][3]-a[1][3])*y+(a[0][4]-a[1][4])*x*y+(a[0][5]-a[1][5]);
			p.x=i;
			p.y=j;
			if(g[0]>g[1]&&g[0]>g[2])
				dc.SetPixel(p,RGB(255,0,255));//紫色属于ω1类
			else if(g[1]>g[0]&&g[1]>g[2])
				dc.SetPixel(p,RGB(192,192,192));//灰色属于ω2类
			else if(g[2]>g[0]&&g[2]>g[1])
				dc.SetPixel(p,RGB(0,128,128));//绿色属于ω3类
			else 
				dc.SetPixel(p,RGB(0,255,255));//其他
			
		}

	dc.TextOut(rect.Width()/2+10,10,"X2");//x2
	dc.TextOut(rect.Width()-20,rect.Height()/2+5,"X1");	//x1
	dc.TextOut(rect.Width()-22,rect.Height()/2-8,">");//x1方向
	dc.MoveTo(rect.Width()/2-5,16);
	dc.LineTo(rect.Width()/2,10);
	dc.LineTo(rect.Width()/2+5,17);
	//x1轴
	dc.MoveTo(10,rect.Height()/2);
	dc.LineTo(rect.Width()-18,rect.Height()/2);
	//x2轴
	dc.MoveTo(rect.Width()/2,rect.Height()-20);
	dc.LineTo(rect.Width()/2,10);
	//原点为(rect.width()/2,rect.height()/2)
	dc.TextOut(rect.Width()/2+1,rect.Height()/2+1,"O");
	//绘制间隔
	for(i=20;i<200;i+=20)
	{		
		dc.MoveTo(rect.Width()/2+i,rect.Height()/2);
		dc.LineTo(rect.Width()/2+i,rect.Height()/2-3);		
		dc.MoveTo(rect.Width()/2-i,rect.Height()/2);
		dc.LineTo(rect.Width()/2-i,rect.Height()/2-3);		
		dc.MoveTo(rect.Width()/2,rect.Height()/2+i);
		dc.LineTo(rect.Width()/2+3,rect.Height()/2+i);		
		dc.MoveTo(rect.Width()/2,rect.Height()/2-i);
		dc.LineTo(rect.Width()/2+3,rect.Height()/2-i);	
	}
	dc.TextOut(rect.Width()/2+20,rect.Height()/2-1,"1");
	dc.TextOut(rect.Width()/2-22,rect.Height()/2-1,"-1");	
	dc.TextOut(rect.Width()/2+3,rect.Height()/2-25,"1");
	dc.TextOut(rect.Width()/2+5,rect.Height()/2+12,"-1");
	UpdateData(false);
	// Do not call CDialog::OnPaint() for painting messages
}






⌨️ 快捷键说明

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