计算机图形学画图代码总结
来源:互联网 发布:手机查看淘宝买家等级 编辑:程序博客网 时间:2024/05/16 19:34
///DDA画直线#include <cstdio>using namespace std;void Line(int x1, int y1, int x2, int y2, int color){ CDC *pDC = GetDC();///获取图形设备环境 float t, x, y, step; step = 1.0/(sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))); for(t=0.0; t<=1.0; t=t+step) { x = x1 + t*(x2-x1); y = y1 + t*(y2-y1); pDC->SetPixel(x,y, color); }}void DDA(int x1,int y1,int x2,int y2,int color){ CDC *pDC=GetDC(); float t,x,y,step; step=1.0/((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); for(t=0.0; t<=1.0; t+=step) { x=x1+t*(x2-x1); y=y1+t*(y2-y1); PDC->SetPiexl(x,y,color); }}void Bresenham(int x1, int y1, int x2, int y2){ CDC *pDC = GetDC();///获取图形设备环境 float dy = y2-y1; float dx = x2-x1; float m = dy/dx; int x = x1; int y = y1; float e = m-0.5; for(x=x1; x<=x2; x++) { pDC->SetPixel(x, y, RGB(0, 0, 255)); if(e>=0) { y=y+1; e=e-1; } e=e+m; }}///正负法void MidpointLine(int x0, int y0, int x1, int y1){ CDC *pDC = GetDC(); int a, b, delta1, delta2, d,x, y; a=y0-y1; b=x1-x0; d=2*a+b; delta1=2*(a+b); delta2=2*a; x=x0; y=y0; SetPixel(x, y, RGB(,,)); while(x<x1) { if(d<0) { x++; y++; d += delta1; } else { x++; d += delta2; } SetPixel(x, y, RGB(,,)); }}///bresenham生成圆弧void bresenham_arc(int R, int color){ CDC *pDC = GetDC();//获取设备环境 int x,y,d; x=0; y=R; d=3-2*R; while(x<=y) { pDC->SetPixel(x, y, color); if (d<0) d=d+4*x+6; else { d=d+4*(x-y)+10; y=y-1; } x=x+1; }}///中点画圆void MidPoint_arc(int R, int color){ CDC *pDC = GetDC();//获取设备环境 int x, y; float d; x=0; y=R; d=1.25-R; while(x<=y) { pDC->SetPixel(x, y, color); if (d<0) d=d+2*x+3; else { d=d+2*(x-y)+5; y=y-1; } x=x+1; }}///椭圆生成法void Ellipse(int a, int b, int color){ CDC *pDC = GetDC();//获取设备环境 int x, y; float d; x = 0; y = b; d = b*b +a*a*(-b+0.25); pDC->SetPixel(x, y, color); while( b*b*(x+1) < a*a*(y-0.5) ) { if (d<0) { d = d+b*b*(2*x+3); x=x+1; } else { d=d+(b*b*(2*x+3)+a*a*(-2*y+2)); x=x+1; y=y-1; } pDC->SetPixel(x, y, color); //(x, -y); (-x, y); (-x, -y); }//第一象限上部分 d = b*b*(x+0.5)*(x+0.5) + a*a*(y-1)*(y-1) - a*a*b*b; while( y > 0 ) { if (d<0) { d=d+b*b*(2*x+2)+a*a*(-2*y+3); x=x+1; y=y-1; } else { d=d+a*a*(-2*y+3); y=y-1; } pDC->SetPixel(x, y, color); }//第一象限下部分}
0 0
- 计算机图形学画图代码总结
- 计算机图形学 资源总结
- 计算机图形学知识点总结
- 计算机图形学课程总结
- 计算机图形学 几何变换代码
- 计算机图形学中的基本概念总结
- 计算机图形学知识点复习总结
- 图形学实战代码总结
- 计算机图形学几个算法的关键代码
- 计算机图形学总结(2D)
- 计算机图形学
- 计算机图形学
- 计算机图形学
- 计算机图形学
- 计算机图形学
- 计算机图形学
- 计算机图形学
- 计算机图形学
- HDU5971 Wrestling Match(二分图的判断)
- 关于静态库
- Struts2核心技术 (一)
- mui-OAuth模块管理客户端的用户登录授权验证功能,允许应用访问第三方平台的资源。
- 学习淘淘商城第四十八课(商品搜索功能Controller实现)
- 计算机图形学画图代码总结
- Java 过长与溢出
- 集合框架-集合的嵌套遍历(HashMap嵌套ArrayList)
- 随手记录--java fx(1)
- POJ2262Goldbach's Conjecture素数判定
- 计算机图形学复习小抄
- #HDU3315#My Brute(Km+余数巧用)
- AsyncTask的使用
- TextInputLayout简单用法:hintText上浮动画以及为EditText设置错误信息