Cohen-SutherLand 裁剪算法 (vc++)
来源:互联网 发布:win7网络图标红叉 编辑:程序博客网 时间:2024/05/17 12:06
Cohen-SutherLand实现裁剪直线的两个关键函数
//计算点 x,y的编码
void CCohenSutherLandView::CompOutCode(float x,float y,CRect* rect,OutCode* outCode)
{
outCode->all = 0;
outCode->top = outCode->bottom =0;
if (y < rect->top)
{
outCode->top = 1;
outCode->all += 1;
}
else if (y > rect->bottom)
{
outCode->bottom = 1;
outCode->all += 1;
}
outCode->right = outCode->left = 0;
if (x > rect->right)
{
outCode->right = 1;
outCode->all += 1;
}
else if(x < rect->left)
{
outCode->left = 1;
outCode->all += 1;
}
}
//CohenSutherLand线段裁剪算法
void CCohenSutherLandView::CohenSutherLineClip(CDC* pDC,float x0,float y0,float x1,float y1, CRect* rect)
{
BOOL accept,done;
OutCode outCode0,outCode1;
OutCode *outCodeOut;
float x,y;
accept = FALSE;
done = FALSE;
CompOutCode(x0,y0,rect,&outCode0);
CompOutCode(x1,y1,rect,&outCode1);
do
{
if (outCode0.all == 0 && outCode1.all == 0) //完全可见
{
accept = TRUE;
done = TRUE;
}
else if ((outCode0.all & outCode1.all) != 0) //显然可见
{
done = TRUE;
}
else //进行求交测试
{
if (outCode0.all != 0)
{
outCodeOut = &outCode0;
}
else
{
outCodeOut = &outCode1;
}
if (outCodeOut->left)
{
y = y0 + (y1 - y0) * (rect->left - x0) / (x1 - x0); //线段与窗口左边求交
x = (float)rect->left;
}
else if (outCodeOut->top)
{
x = x0 + (x1 - x0) * (rect->right - y0) / (y1 - y0); //线段与窗口上边求交
y = (float) rect->top;
}
else if (outCodeOut->right)
{
y = y0 + (y1 - x0) * (rect->right - x0) / (x1 - x0); //线段与窗口右边求交
x = (float)rect->right;
}
else if (outCodeOut->bottom)
{
x = x0 + (x1 - x0) * (rect->bottom - x0) / (y1 - y0); //线段与窗口下边求交
y = (float)rect->bottom;
}
if (outCodeOut ->all == outCode0.all)
{
x0 = x; //以交点为界,将线段位于窗口所在的直线的外侧的部分丢弃
y0 = y; //剩下的继续
CompOutCode(x0,y0,rect,&outCode0);
}
else
{
x1 = x;
y1 = y;
CompOutCode(x1,y1,rect,&outCode1);
}
}
} while(!done);
if (accept)
{
pDC->MoveTo(int(x0),int(y0));
pDC->LineTo(int(x1),int(y1));
}
}
具体原理等,参见《计算机图形学》北京大学出版社 倪明田等 第111页
- Cohen-SutherLand 裁剪算法 (vc++)
- Cohen-Sutherland裁剪算法
- Cohen-Sutherland裁剪算法
- Cohen-Sutherland线段裁剪算法
- Cohen-Sutherland算法线段裁剪
- Cohen-Sutherland线段裁剪算法
- Cohen-Sutherland线段裁剪算法
- Cohen-Sutherland算法裁剪线段
- 计算机图形学-直线裁剪(Cohen-Sutherland编码裁剪算法)
- Cohen Sutherland线段裁剪算法(C#实现)
- Cohen-Sutherland线段裁剪算法
- Cohen-Sutherland 窗口裁剪线段算法
- 计算机图形学 - 线段裁剪 - Cohen Sutherland算法
- opengl 直线裁剪Cohen-Sutherland算法
- Cohen-Sutherland直线段的裁剪算法
- Tubor C 直线裁剪算法 Cohen-Sutherland算法 (可运行代码)
- OPENGL—编码裁剪(Cohen-Sutherland)法裁剪图
- 直线矩形视口裁剪算法 Cohen–Sutherland algorithm
- Web 开发设计高手必看的CSS经典牛书
- 控制台程序如何使用DOS命令
- 在Linux上安装NetBeans来编译C程序
- 短信发送模板
- 比尔盖茨的十大经典人生定律
- Cohen-SutherLand 裁剪算法 (vc++)
- MFC 大杂烩
- 工程项目管理信息化领域中的形式化方法应用
- 初学JAVA的最佳工具
- 报刊类英语网站链接,从报纸中学习英语
- Oracle点滴收集
- Flash9.ocx彻底删除的最佳方法
- QTP中的参数传递
- 服务器应用程序不可用解决方案集