中点分割裁剪算法 c语言,计算机图形学 运用 中点分割直线段裁剪算法原理

// 实验二View.cpp : implementation of the CMyView class

//

#include "stdafx.h"

#include "实验二.h"

#include "实验二Doc.h"

#include "实验二View.h"

#include

#include

#include

#ifdef _DEBUG

#define new DEBUG_NEW

#undef THIS_FILE

static char THIS_FILE[] = __FILE__;

#endif

/

// CMyView

IMPLEMENT_DYNCREATE(CMyView, CView)

BEGIN_MESSAGE_MAP(CMyView, CView)

//{{AFX_MSG_MAP(CMyView)

// 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()

/

// CMyView construction/destruction

CMyView::CMyView()

{

// TODO: add construction code here

}

CMyView::~CMyView()

{

}

BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)

{

// TODO: Modify the Window class or styles here by modifying

//  the CREATESTRUCT cs

return CView::PreCreateWindow(cs);

}

/

// CMyView drawing

int CMyView::Encode(double x,double y,double XL,double XR,double YB,double YT,CMyView *Ecode)

{

//CMyView *Ecode = new CMyView;

Ecode->left=0;

Ecode->right=0;

Ecode->top=0;

Ecode->buttom=0;

if(x

Ecode->left=1;

if(x>XR)

Ecode->right=1;

if(y>YT) Ecode->buttom=1;

if(ytop=1;

return 1;

}

int CMyView::Cut(double x0,double y0,double x1,double y1,double XL,double XR,double YB,double YT)

{

int flag;

double x,y;

x=(x0+x1)/2.0;

y=(y0+y1)/2.0;

CMyView *code0=new CMyView;

CMyView *code1=new CMyView;

flag= Encode(x0,y0,XL,XR,YB,YT,code0);

flag=Encode(x1,y1,XL,XR,YB,YT,code1);

CDC *pDC=GetDC();

if((code0->top==code1->top)&&(code0->buttom==code1->buttom) &&(code0->left==code1->left) &&(code0->right==code1->right))

{

//在矩形外面

return 0;

}

else

{

if((code0->top==code0->buttom==code0->left==code0->right==0 )&& (code1->top==code1->buttom==code1->left==code1->right==0 ))

{

pDC->MoveTo((int)x0,(int)y0);

pDC->LineTo((int)x1,(int)y1);

return 1;

}

else

{

if(((pow(x,2)+pow(y,2)) - (pow(x0,2) + pow(y0,2)) )< 10e-6)

{

return 1;

}

else

{

Cut(x1,y1,x,y,XL,XR,YB,YT);

Cut(x,y,x0,y0,XL,XR,YB,YT);

}

}

}

return 1;

}

void CMyView::OnDraw(CDC* pDC)

{

CMyDoc* pDoc = GetDocument();

ASSERT_VALID(pDoc);

// TODO: add draw code for native data here

double x0,y0,x1,y1;

double XL,XR,YB,YT;

x0=0;y0=0;x1=150;y1=200;

XL=20;XR=200;YB=150;YT=100;

pDC->MoveTo((int)x0+50,(int)y0);

pDC->LineTo((int)x1+50,(int)y1);

//Sleep(3000);  //为了显示效果,停顿3秒

int flag=Cut(x0,y0,x1,y1,XL,XR,YB,YT);

}

/

// CMyView printing

BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)

{

// default preparation

return DoPreparePrinting(pInfo);

}

void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)

{

// TODO: add extra initialization before printing

}

void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)

{

// TODO: add cleanup after printing

}

/

// CMyView diagnostics

#ifdef _DEBUG

void CMyView::AssertValid() const

{

CView::AssertValid();

}

void CMyView::Dump(CDumpContext& dc) const

{

CView::Dump(dc);

}

CMyDoc* CMyView::GetDocument() // non-debug version is inline

{

ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));

return (CMyDoc*)m_pDocument;

}

#endif //_DEBUG

/ // CMyView message handlers

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值