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

📄 bsplineview.cpp

📁 Bpline曲线生成
💻 CPP
字号:
// BSplineView.cpp : implementation of the CBSplineView class
//

#include "stdafx.h"
#include "BSpline.h"

#include "BSplineDoc.h"
#include "BSplineView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CBSplineView

IMPLEMENT_DYNCREATE(CBSplineView, CView)

BEGIN_MESSAGE_MAP(CBSplineView, CView)
	//{{AFX_MSG_MAP(CBSplineView)
	ON_COMMAND(IDC_Bezier, OnBezier)
	ON_UPDATE_COMMAND_UI(IDC_Bezier, OnUpdateBezier)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CBSplineView construction/destruction

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

}

CBSplineView::~CBSplineView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CBSplineView drawing

void CBSplineView::OnBezier(CDC* pDC)
{
	CBSplineDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	static double p[4][2]={50,400,140,20,400,40,635,420};
    const NO=4;          
    int i;
	double t,t2,t3,xt,yt;
    int rate=200,x,y;

   for (i=1;i<NO;i++)
   { 
	   if(i==1)pDC->MoveTo(p[0][0],p[0][1]);
	   pDC->LineTo(p[i][0],p[i][1]);
   }
  

     for (t=0;t<=1;t+=1.0/rate)
	 {

        t2=t*t;
		t3=t2*t;
        xt=((-1)*t3+3*t2-3*t+1)*p[0][0]+(3*t3-6*t2+4)*p[1][0]+(-3*t3+3*t2+3*t+1)*p[2][0]+t3*p[3][0];
        yt=((-1)*t3+3*t2-3*t+1)*p[0][1]+(3*t3-6*t2+4)*p[1][1]+(-3*t3+3*t2+3*t+1)*p[2][1]+t3*p[3][1];
		xt=xt/6;
		yt=yt/6;
        x=(int)(xt);
        y=(int)(yt);
	   if(t==0)pDC->MoveTo(x,y);
        pDC->LineTo(x,y);
	 }
}

/////////////////////////////////////////////////////////////////////////////
// CBSplineView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CBSplineView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CBSplineView message handlers

/*void CBSplineView::OnBezier(CDC* pDC) 
{
	// TODO: Add your command handler code here
	CBSplineDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	static double p[4][2]={50,400,140,20,400,40,635,420};
    const NO=4;          
    int i;
	double t,t2,t3,xt,yt;
    int rate=200,x,y;

   for (i=1;i<NO;i++)
   { 
	   if(i==1)pDC->MoveTo(p[0][0],p[0][1]);
	   pDC->LineTo(p[i][0],p[i][1]);
   }
  

     for (t=0;t<=1;t+=1.0/rate)
	 {

        t2=t*t;
		t3=t2*t;
        xt=((-1)*t3+3*t2-3*t+1)*p[0][0]+(3*t3-6*t2+4)*p[1][0]+(-3*t3+3*t2+3*t+1)*p[2][0]+t3*p[3][0];
        yt=((-1)*t3+3*t2-3*t+1)*p[0][1]+(3*t3-6*t2+4)*p[1][1]+(-3*t3+3*t2+3*t+1)*p[2][1]+t3*p[3][1];
		xt=xt/6;
		yt=yt/6;
        x=(int)(xt);
        y=(int)(yt);
	   if(t==0)pDC->MoveTo(x,y);
        pDC->LineTo(x,y);
	 }
}

void CBSplineView::OnUpdateBezier(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	
}

⌨️ 快捷键说明

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