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

📄 readtxtview.cpp

📁 根据空间三点坐标来计算三点所在圆心,可以应用到测量领域
💻 CPP
字号:
// ReadTxtView.cpp : implementation of the CReadTxtView class
//

#include "stdafx.h"
#include "ReadTxt.h"

#include "ReadTxtDoc.h"
#include "ReadTxtView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CReadTxtView

IMPLEMENT_DYNCREATE(CReadTxtView, CView)

BEGIN_MESSAGE_MAP(CReadTxtView, CView)
	//{{AFX_MSG_MAP(CReadTxtView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CReadTxtView construction/destruction

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

}

CReadTxtView::~CReadTxtView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CReadTxtView drawing

void CReadTxtView::OnDraw(CDC* pDC)
{
	CReadTxtDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	TEXTMETRIC tm;
	int cyChar,linecy;
	int i;
	pDC->GetTextMetrics(&tm);
	cyChar=tm.tmHeight;
	linecy=0;
	CString str;
	//int count=pDoc->n/3;
	/*for(i=0;i<pDoc->n;i++)
	{
		str.Format("x[%d]=%lf,y[%d]=%lf,z[%d]=%lf",i,pDoc->a[3*i],i,pDoc->a[3*i+1],i,pDoc->a[3*i+2]);
		pDC->TextOut(0,linecy,str);
		linecy=linecy+cyChar;
	}*/
	int count=0;
	count=(int)pDoc->n/3;
	double x1=0,y1=0,z1=0;
	double x2=0,y2=0,z2=0;
	double x3=0,y3=0,z3=0;
	double a=0,b=0,c=0;
	double x=0,y=0,z=0;
	double div1=0,div2=0;
	//求平均值
	double sumx=0,sumy=0,sumz=0;
	for(i=0;i<count;i++)
	{
		x1=pDoc->a[9*i];
		y1=pDoc->a[9*i+1];
		z1=pDoc->a[9*i+2];
		x2=pDoc->a[9*i+3];
		y2=pDoc->a[9*i+4];
		z2=pDoc->a[9*i+5];
		x3=pDoc->a[9*i+6];
		y3=pDoc->a[9*i+7];
		z3=pDoc->a[9*i+8];
		a=((z1-z2)*(y1-y3)-(z1-z3)*(y1-y2))/((x1-x2)*(y1-y3)-(x1-x3)*(y1-y2));
		b=((z1-z2)*(x1-x3)-(z1-z3)*(x1-x2))/((y1-y2)*(x1-x3)-(y1-y3)*(x1-x2));
		c=z1-a*x1-b*y1;

		div1=(x1*x1-x2*x2+y1*y1-y2*y2+z1*z1-z2*z2)/2-(z1-z2)*c;
		div2=(x1*x1-x3*x3+y1*y1-y3*y3+z1*z1-z3*z3)/2-(z1-z3)*c;
		x=((div1*(y1-y3+(z1-z3)*b))-(div2*(y1-y2+(z1-z2)*b)))/((x1-x2+a*(z1-z2))*(y1-y3+b*(z1-z3))-(x1-x3+a*(z1-z3))*(y1-y2+b*(z1-z2)));
		y=((div1*(x1-x3+(z1-z3)*a))-(div2*(x1-x2+(z1-z2)*a)))/((y1-y2+b*(z1-z2))*(x1-x3+a*(z1-z3))-(y1-y3+b*(z1-z3))*(x1-x2+a*(z1-z2)));
		z=a*x+b*y+c;
		//求出坐标输出
		str.Format("x=%lf,y=%lf,z=%lf",x,y,z);
		pDC->TextOut(0,linecy,str);
		linecy=linecy+cyChar;
		//求平均值
		sumx=sumx+x;
		sumy=sumy+y;
		sumz=sumz+z;
	}
	if(count>0)
	{
		str.Format("结果是:x=%lf,y=%lf,z=%lf",sumx/count,sumy/count,sumz/count);
		pDC->TextOut(0,linecy,str);
		linecy=linecy+cyChar;
	}
}

/////////////////////////////////////////////////////////////////////////////
// CReadTxtView printing

BOOL CReadTxtView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CReadTxtView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CReadTxtView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CReadTxtView diagnostics

#ifdef _DEBUG
void CReadTxtView::AssertValid() const
{
	CView::AssertValid();
}

void CReadTxtView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CReadTxtView message handlers

⌨️ 快捷键说明

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