计算机图形学 运用 中点分割直线段裁剪算法原理
来源:互联网 发布:现在开淘宝店卖什么好 编辑:程序博客网 时间:2024/05/22 00:20
// 实验二View.cpp : implementation of the CMyView class
//
#include "stdafx.h"
#include "实验二.h"
#include "实验二Doc.h"
#include "实验二View.h"
#include <stdio.h>
#include <conio.h>
#include <math.h>
#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<XL)
Ecode->left=1;
if(x>XR)
Ecode->right=1;
if(y>YT) Ecode->buttom=1;
if(y<YB)Ecode->top=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
- 计算机图形学 运用 中点分割直线段裁剪算法原理
- 计算机图形学 学习笔记(四):直线裁剪算法:Cohen-Suther land,中点分割法,Liang-Barsky
- 计算机图形学-基于OpenGL的直线段的裁剪算法
- 计算机图形学(五)线段的中点分割裁剪算法讲解与源代码
- 光栅图形学之直线段扫描算法(中点画线法)
- 中点分割裁剪算法
- 中点分割裁剪算法
- 计算机图形学 - 全斜率直线中点生成算法
- 计算机图形学-直线裁剪(Cohen-Sutherland编码裁剪算法)
- 裁剪算法(计算机图形学)
- 光栅图形学之直线段扫描算法(中点画线法之代码)
- 光栅图形学之直线段扫描算法(中点画线法之matlab代码)
- 光栅图形学之直线段扫描算法(中点画线法之java代码)
- 计算机图形学 学习笔记(一):光栅图形学算法:直线扫描算法(DDA,中点画线算法,Bresenham算法)
- 计算机图形学----直线与多边形的裁剪
- 中点画线算法(计算机图形学)
- 计算机图形学 - 抛物线的中点生成算法
- 计算机图形学 - 多边形裁剪算法
- 自定义标签简介
- Win32汇编中资源的创建与编辑
- ICE的自动编码转换
- http://poj.org/problem?id=3159
- java finalize方法的使用
- 计算机图形学 运用 中点分割直线段裁剪算法原理
- 在SQL Server 2005(2008)中用T-SQL插入中文数据时出现的问号或乱码的解决方案
- 如何选择虚拟机
- int main(int argc,char *argv[])中参数的意义
- 学习
- VC中CPropertySheet 属性对话框
- 浅析反射、工厂和配置文件
- 基于matlab的语音识别系统设计
- 面试题:输出1,2,2,3,4,5的所有排列组合,4不能在第三位,3和5不能相邻