📄 pointview.cpp
字号:
// PointView.cpp : implementation of the CPointView class
//
#include "stdafx.h"
#include "Point.h"
#include "PointDoc.h"
#include "PointView.h"
#include "MyPoint.h"
#include "MyDialog.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPointView
IMPLEMENT_DYNCREATE(CPointView, CView)
BEGIN_MESSAGE_MAP(CPointView, CView)
//{{AFX_MSG_MAP(CPointView)
ON_COMMAND(IDM_POINT, OnPoint)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CPointView construction/destruction
CPointView::CPointView()
{
// TODO: add construction code here
point[0].x = 20;
point[0].y = 20;
point[1].x = 30;
point[1].y = 50;
point[2].x = 110;
point[2].y = 110;
point[3].x = 130;
point[3].y = 180;
point[4].x = 210;
point[4].y = 240;
point[5].x = 310;
point[5].y = 20;
flags = FALSE;
}
CPointView::~CPointView()
{
}
BOOL CPointView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CPointView drawing
void CPointView::OnDraw(CDC* pDC)
{
CPointDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CPen pen,*oldPen;
pen.CreatePen(1,1,RGB(255,0,0));
oldPen = pDC->SelectObject(&pen);
U[0] = 0;
for (int i = 1; i < 6; i++)
{
U[i] = U[i - 1] + sqrt( (point[i].x - point[i-1].x)*
(point[i].x - point[i-1].x) + (point[i].y - point[i-1].y)*
(point[i].y - point[i-1].y) );
}
for (int j = 0; j < 5; j++)
{
deltar[j] = U[j+1] - U[j];
}
for (int n = 1; n < 5; n++)
{
pdao[n].x = (deltar[n] / deltar[n-1] * (point[n].x-point[n-1].x) +
deltar[n-1] / deltar[n] * (point[n+1].x-point[n].x) )/
(deltar[n-1]+deltar[n]);
pdao[n].y = (deltar[n] / deltar[n-1] * (point[n].y-point[n-1].y) +
deltar[n-1] / deltar[n] * (point[n+1].y-point[n].y) )/
(deltar[n-1]+deltar[n]);
}
pdao[0].x = 2*(point[1].x-point[0].x)/deltar[0]-pdao[1].x;
pdao[0].y = 2*(point[1].y-point[0].y)/deltar[0]-pdao[1].y;
pdao[5].x = 2*(point[5].x-point[4].x)/deltar[4]-pdao[4].x;
pdao[5].y = 2*(point[5].y-point[4].y)/deltar[4]-pdao[4].y;
CString str[6];
for (int h = 0; h < 6; h++)
{
str[h].Format("p%d",h);
pDC->TextOut(point[h].x,
point[h].y-5,"*");
pDC->TextOut(point[h].x,
point[h].y-20,str[h]);
}
// CPen pen,*oldPen;
// pen.CreatePen(1,1,RGB(255,0,0));
// oldPen = pDC->SelectObject(&pen);
double t;
int x, y;
// if (flags == TRUE){
for (int m = 0; m < 5; m++)
{
for (float uu = U[m]; uu < U[m+1]; )
{
uu += 0.1;
t = (uu - U[m]) / deltar[m];
x = static_cast<int>((2*t*t*t-3*t*t+1)*point[m].x
+(3*t*t-2*t*t*t)*point[m+1].x
+t*(t-1)*(t-1)*pdao[m].x*deltar[m]
+t*t*(t-1)*pdao[m+1].x*deltar[m]);
y = static_cast<int>((2*t*t*t-3*t*t+1)*point[m].y
+(3*t*t-2*t*t*t)*point[m+1].y
+t*(t-1)*(t-1)*pdao[m].y*deltar[m]
+t*t*(t-1)*pdao[m+1].y*deltar[m]);
pDC->SetPixel(x,y, RGB(255, 0, 0));
}
}
// }
}
/////////////////////////////////////////////////////////////////////////////
// CPointView printing
BOOL CPointView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CPointView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CPointView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CPointView diagnostics
#ifdef _DEBUG
void CPointView::AssertValid() const
{
CView::AssertValid();
}
void CPointView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CPointDoc* CPointView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPointDoc)));
return (CPointDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CPointView message handlers
void CPointView::OnPoint()
{
// TODO: Add your command handler code here
CMyDialog dialog;
dialog.m_Point1 = point[0].x;
dialog.m_Point2 = point[0].y;
dialog.m_Point3 = point[1].x;
dialog.m_Point4 = point[1].y;
dialog.m_Point5 = point[2].x;
dialog.m_Point6 = point[2].y ;
dialog.m_Point7 = point[3].x;
dialog.m_Point8 = point[3].y;
dialog.m_Point9 = point[4].x;
dialog.m_Point10 = point[4].y;
dialog.m_Point11 = point[5].x;
dialog.m_Point12 = point[5].y;
UpdateData(FALSE);
if ( IDOK == dialog.DoModal() )
{
point[0].x = dialog.m_Point1;
point[0].y = dialog.m_Point2;
point[1].x = dialog.m_Point3;
point[1].y = dialog.m_Point4;
point[2].x = dialog.m_Point5;
point[2].y = dialog.m_Point6;
point[3].x = dialog.m_Point7;
point[3].y = dialog.m_Point8;
point[4].x = dialog.m_Point9;
point[4].y = dialog.m_Point10;
point[5].x = dialog.m_Point11;
point[5].y = dialog.m_Point12;
}
UpdateData(TRUE);
Invalidate();
/*
U[0] = 0;
for (int i = 1; i < 6; i++)
{
U[i] = U[i - 1] + sqrt( (point[i].x - point[i-1].x)*
(point[i].x - point[i-1].x) + (point[i].y - point[i-1].y)*
(point[i].y - point[i-1].y) );
}
for (int j = 0; j < 5; j++)
{
deltar[j] = U[j+1] - U[j];
}
for (int n = 1; n < 5; n++)
{
pdao[n].x = (deltar[n] / deltar[n-1] * (point[n].x-point[n-1].x) +
deltar[n-1] / deltar[n] * (point[n+1].x-point[n].x) )/
(deltar[n-1]+deltar[n]);
pdao[n].y = (deltar[n] / deltar[n-1] * (point[n].y-point[n-1].y) +
deltar[n-1] / deltar[n] * (point[n+1].y-point[n].y) )/
(deltar[n-1]+deltar[n]);
}
pdao[0].x = 2*(point[1].x-point[0].x)/deltar[0]-pdao[1].x;
pdao[0].y = 2*(point[1].y-point[0].y)/deltar[0]-pdao[1].y;
pdao[5].x = 2*(point[5].x-point[4].x)/deltar[4]-pdao[4].x;
pdao[5].y = 2*(point[5].y-point[4].y)/deltar[4]-pdao[4].y;
flags = TRUE;*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -