【MFC】计算机图形学实验:熟悉开发环境及工具(代码)

实验内容: 

【MFC】计算机图形学实验1:熟悉开发环境及工具_绘制多义线mfc-CSDN博客

 画笔和字体只给出两处代码:

//创建刷子,设置填充色为黑色 
CBrush NewBrush;
NewBrush.CreateSolidBrush(RGB(0, 0, 0));
pDC->SelectObject(&NewBrush);
//创建画笔,设置为实线,宽度为 4 像素,黑色
CPen NewPen;
NewPen.CreatePen(PS_SOLID, 4, RGB(0, 0, 0));
pDC->SelectObject(&NewPen);
//删除原来的画笔并重新设置为黑色虚线
NewPen.DeleteObject();
NewPen.CreatePen(PS_DASH, 1, RGB(0, 0, 0));
pDC->SelectObject(&NewPen);
//创建逻辑字体,字体高度为 22,显示角度为 75 度,字体使用 Arial,宽度默认
newfont.CreateFont(22,0,750,0,FW_NORMAL,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PR
ECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH | FF_SWISS,_T("Arial"));
//删除原有字体并重新设置显示角度为-22.5
newfont.DeleteObject();
newfont.CreateFont(22,0,-225,0,FW_NORMAL,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_P
RECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH| FF_SWISS,_T("Arial"));

 圆模块:

//左圆
x1 = x0 - 56*8, y1=y0-25*8, x2=x0-6*8, y2 =y0+25 * 8;
pDC->Ellipse(x1, y1, x2, y2 );
//右大圆
x1 = x0 + (31 - 19) * 8, y1 = y0 - 19 * 8, x2 = x0 + (31 +
19) * 8, y2 = y0 + 19 * 8;
pDC->Ellipse(x1, y1, x2, y2);
//右小圆
x1 = x0 + (31 - 11) * 8, y1 = y0 - 11 * 8, x2 = x0 + (31 +
11) * 8, y2 = y0 + 11 * 8;
pDC->Ellipse(x1, y1, x2, y2);
//画上方圆弧
//获取圆心三角形左下角的正余弦值
cosx = (50 * 50.0 - 44.0 * 44 + 62 * 62.0) / (2 * 50.0 * 62.0);
sinx = sin(acos(cosx));
//计算上圆弧的圆心坐标并绘制
double x7 = 50.0* 8 * cosx+x0-31* 8, y7 = -50.0* 8 * sinx + y0;
pDC->Arc(x7-25* 8,y7-25* 8,x7 + 25* 8,y7 +25* 8,x0-31* 8,y0, x0+31*8,y0);//画下方圆弧
//获取圆心三角形左下角的正余弦值
double a8 = 94 - 25, b8 = 94 - 19;
cosx = (a8 * a8 - b8 * b8 + 62 * 62.0) / (2 * a8 * 62.0);
sinx = sin(acos(cosx));
//计算下圆弧的圆心坐标并绘制
double x8 = a8* 8 * cosx + x0 - 31* 8, y8 =-a8* 8 * sinx + y0;
pDC->Arc(x8 - 94* 8, y8 - 94* 8, x8 + 94* 8, y8 + 94* 8, x0 - 3
1* 8, y0, x0 + 31* 8, y0);

直线模块 :

//画虚线
NewPen.DeleteObject();
NewPen.CreatePen(PS_DASH, 1, RGB(0, 0, 0));// 黑色虚线
pDC->SelectObject(&NewPen); //确定边框的颜色
//画辅助线,竖直贯穿左圆
pDC->MoveTo(points8[0].x, points8[0].y-6.5*8-6.5*8);
pDC->LineTo(points8[4].x, points8[4].y + 6.5 * 8+11.5*8);
//画辅助线,竖直贯穿右圆
pDC->MoveTo(x0 + 31 * 8, points8[0].y - 6.5 * 8 - 6.5 * 8);
pDC->LineTo(x0 + 31 * 8, points8[4].y + 6.5 * 8 + 11.5 * 8);
/画辅助线,水平贯穿两个圆
pDC->MoveTo(x9, y0);
pDC->LineTo(x0 + (31 + 19) * 8+ 6 * 8, y0);//画虚线
NewPen.DeleteObject();
NewPen.CreatePen(PS_DASH, 1, RGB(0, 0, 0));// 黑色虚线
pDC->SelectObject(&NewPen); //确定边框的颜色
//画辅助线,竖直贯穿左圆
pDC->MoveTo(points8[0].x, points8[0].y-6.5*8-6.5*8);
pDC->LineTo(points8[4].x, points8[4].y + 6.5 * 8+11.5*8);
//画辅助线,竖直贯穿右圆
pDC->MoveTo(x0 + 31 * 8, points8[0].y - 6.5 * 8 - 6.5 * 8);
pDC->LineTo(x0 + 31 * 8, points8[4].y + 6.5 * 8 + 11.5 * 8);
/画辅助线,水平贯穿两个圆
pDC->MoveTo(x9, y0);
pDC->LineTo(x0 + (31 + 19) * 8+ 6 * 8, y0);

 多边形模块:

//顶上
x4 = x0 - 31 * 8, y4= y0 - 18.5 * 8;
points8[0] = CPoint(x4, y4);
//右上
x3 = x0 - 31 * 8 + 18.5 * 8 * cos(45 / 360.0 * (pai * 2)), y3
= y0 - 18.5 * 8 * sin(45 / 360.0 * (pai * 2));
points8[1] = CPoint(x3, y3);
//右
x4 = x0 - 31 * 8 +18.5 * 8, y4 = y0;
points8[2] = CPoint(x4, y4);
//右下
x3 = x0 - 31 * 8 + 18.5 * 8 * cos(45 / 360.0 * (pai * 2)), y3
= y0 + 18.5 * 8 * sin(45 / 360.0 * (pai * 2));
points8[3] = CPoint(x3, y3);
//下
x4 = x0 - 31 * 8, y4 = y0 + 18.5 * 8;
points8[4] = CPoint(x4, y4);
//左下
x5=x0 - 31 * 8- 18.5 * 8* cos(45 / 360.0 * (pai * 2)),y5=y0 + 18.
5 * 8* sin(45 / 360.0 * (pai * 2));
points8[5] = CPoint(x5, y5);
//左
x6=x0 - 31* 8-18.5* 8,y6=y0;
points8[6] = CPoint(x6, y6);
//左上
x5=x0 - 31 * 8- 18.5 * 8* cos(45 / 360.0 * (pai * 2)),y5=y0 - 18.
5 * 8* sin(45 / 360.0 * (pai * 2));
points8[7] = CPoint(x5, y5);
//绘制八边形
pDC->Polygon(points8, 8);

箭头模块:

//上圆弧上的箭头绘制
cosx = cos(75/180.0*pai); sinx = sin(75/ 180.0 * pai);
double xuparc= x7-25*8*cosx, yuparc = y7 + 25*8*sinx;//上圆弧
double degree = 60.0 / 180 * pai;
points[0].x = xuparc, points[0].y = yuparc;
points[1].x = xuparc + 3.5 * 8 * cos(degree), points[1].y = yuparc -
3.5 * 8 * sin(degree);
points[2].x = xuparc , points[2].y = yuparc - 3.5 * 8 ;
pDC->Polygon(points, 3);
pDC->MoveTo((points[1].x + points[2].x) / 2,(points[1].y + points[2].y)/2);
pDC->LineTo(x7, y7);
//下圆弧上的箭头绘制
double xdarc=8 + 94 * 8 * cosx,ydarc = y8 + 94 * 8 * sinx;
degree = 60.0 / 180 * pai;
points[0].x = xdarc, points[0].y = ydarc;
points[1].x = xdarc - 3.5 * 8 * cos(degree), points[1].y = ydarc - 3
.5 * 8 * sin(degree);
points[2].x = xdarc, points[2].y = ydarc - 3.5 * 8;
pDC->Polygon(points, 3);
x2 = x8 + 83 * 8 * cosx,y2 = y8 + 83 * 8 * sinx;
pDC->MoveTo((points[1].x + points[2].x) / 2, (points[1].y + points[2].y)
/ 2);
pDC->LineTo(x2, y2);//标注八边形上下顶点距离长度的两条水平实线和箭头线
x4 = points8[0].x, y4 = points8[0].y; //多边形上方顶点
pDC->MoveTo(x4, y4);
pDC->LineTo(x0 - 56 * 8 - 7 * 8, y4);
//绘制上方箭头
x9 = x0 - 56 * 8 - 6 * 8, y9 = y4 + 3 * 8;
points[1] = CPoint(x9, y9);
x9 = x0 - 56 * 8 - 4 * 8, y9 = y4 + 3 * 8;
points[2] = CPoint(x9, y9);
x9 = x0 - 56 * 8 - 5 * 8, y9 = y4;
points[0] = CPoint(x9, y9);
pDC->Polygon(points, 3);
x4 = points8[4].x, y4 = points8[4].y; //多边形下方顶点
pDC->MoveTo(x4, y4);
pDC->LineTo(x0 - 56 * 8 - 7 * 8, y4);
//绘制下方箭头
x10 = x0 - 56 * 8 - 6 * 8, y10 = y4-3*8;
points[1] = CPoint(x10, y10);
x10 = x0 - 56 * 8 - 4 * 8, y10 = y4 - 3 * 8;
points[2] = CPoint(x10, y10);
x10= x0 - 56 * 8 - 5 * 8, y10 = y4;
points[0] = CPoint(x10, y10);
pDC->Polygon(points, 3);
//连接箭头
pDC->MoveTo(x9, y9+ 3 * 8);
pDC->LineTo(x10, y10 - 3 * 8);
//两个圆心间距离的箭头
x1 = x0 - 31 * 8+3*8, y1 += 9 * 8;
points[0] = CPoint(x1, y1);
x1 = x0 - 31 * 8 + 3 * 8, y1 += 2 * 8;
points[1] = CPoint(x1, y1);
x1 = x0 - 31 * 8 , y1 -= 8;
points[2] = CPoint(x1, y1);
pDC->Polygon(points, 3);
x2 = x0 + 31 * 8, y2 = y1;
points[0] = CPoint(x2, y2);
x2 = x0 + 31 * 8-3*8, y2 = y1-8;
points[1] = CPoint(x2, y2);
y2 = y1 + 8;
points[2] = CPoint(x2, y2);
pDC->Polygon(points, 3);
//连接箭头,两个圆心间距离的箭头
pDC->MoveTo(x1 + 3 * 8, y1);
pDC->LineTo(x2, y1);
double xd= (x1 + 3 * 8+x2)/2, yd=y1;//存下辅助线的中点
//右小圆的箭头线
x1 = x0 + 31 * 8, y1 = y0;//右小圆圆心
cosx = cos(45 / 180.0 * pai);//获取小圆辅助线与水平线的角度余弦值
sinx = sin(45 / 180.0 * pai);
//贯穿右小圆 45 度实线
pDC->MoveTo(x1 + 11 * 8 * cosx, y1 - 11 * 8 * sinx);
pDC->LineTo(x1 - 11 * 8 * cosx, y1 + 11 * 8 * sinx);
//小圆画箭头左下,45 度
x1 = x1 - 11 * 8 * cosx, y1 = y1 + 11 * 8 * sinx;
degree = 30.0/180*pai;//箭头三角形角度
points[0].x = x1 , points[0].y = y1 ;
points[1].x = x1 -3.5*8*cos(degree), points[1].y = y1 +3.5*8*sin(degree);
points[2].x = x1 - 3.5 * 8 * cos(degree+30.0/180*pai), points[2].y = y
1 + 3.5 * 8 * sin(degree+30.0 / 180 * pai);
pDC->Polygon(points, 3);
x1 = x0 + 31 * 8, y1 = y0;//右小圆圆心
pDC->MoveTo((points[1].x+ points[2].x)/2, (points[1].y + points[2].y) / 2);
pDC->LineTo(x1 - 17 * 8 * cosx, y1 + 17 * 8 * sinx);
//小圆画箭头右上
x1 = x1 + 11 * 8 * cosx, y1 = y1 - 11 * 8 * sinx;
points[0].x = x1, points[0].y = y1;
points[1].x = x1 + 3.5 * 8 * cos(degree), points[1].y = y1 - 3.5 *
8 * sin(degree);
points[2].x = x1 + 3.5 * 8 * cos(degree + 30.0 / 180 * pai), point
s[2].y = y1 - 3.5 * 8 * sin(degree + 30.0 / 180 * pai);
pDC->Polygon(points, 3);
x1 = x0 + 31 * 8, y1 = y0;//右小圆圆心
pDC->MoveTo((points[1].x + points[2].x) / 2, (points[1].y + points[2].y)
/ 2);
pDC->LineTo(x1 + 22 * 8 * cosx, y1 - 22 * 8 * sinx);
//延伸出的水平线
DC->MoveTo(x1 + 22 * 8 * cosx+5*8, y1 - 22 * 8 * sinx);
pDC->LineTo(x1 + 22 * 8 * cosx, y1 - 22 * 8 * sinx);

//右大圆的箭头线
x1 = x0 + (31) * 8, y1 = y0 ;//右大圆圆心
cosx = cos(15 / 180.0 * pai);//获取大圆辅助线与水平线的角度余弦值
sinx = sin(15 / 180.0 * pai);
//贯穿右小圆 15 度实线
pDC->MoveTo(x1 - 19 * 8 * cosx, y1 - 19 * 8 * sinx);
pDC->LineTo(x1 + 19 * 8 * cosx, y1 + 19 * 8 * sinx);
//右大圆箭头左上,贯穿线变成 15 度
x1 = x1 -19 * 8 * cosx, y1 = y1 - 19 * 8 * sinx;
points[0].x = x1, points[0].y = y1;
points[1].x = x1 - 3.5 * 8 , points[1].y = y1;
points[2].x = x1 - 3.5 * 8 * cos(degree), points[2].y = y1 - 3.5 *
8 * sin(degree);
pDC->Polygon(points, 3);
x1 = x0 + (31) * 8, y1 = y0;//右大圆圆心
pDC->MoveTo((points[1].x + points[2].x) / 2, (points[1].y + points[2].y)
/ 2);
pDC->LineTo(x1 - 26 * 8 * cosx, y1 - 26 * 8 * sinx);
//右大圆箭头右下,贯穿线变成 15 度
x1 = x1 + 19 * 8 * cosx, y1 = y1 + 19 * 8 * sinx;
points[0].x = x1, points[0].y = y1;
points[1].x = x1 + 3.5 * 8 , points[1].y = y1;
points[2].x = x1 + 3.5 * 8 * cos(degree), points[2].y = y1 + 3.5 *
8 * sin(degree);
pDC->Polygon(points, 3);
x1 = x0 + (31) * 8, y1 = y0;//右大圆圆心
pDC->MoveTo((points[1].x + points[2].x) / 2, (points[1].y + points[2].y)
/ 2);
pDC->LineTo(x1 + 25 * 8 * cosx, y1 + 25 * 8 * sinx);
//延伸出的水平线
pDC->MoveTo(x1 + 25 * 8 * cosx, y1 + 25 * 8 * sinx);
pDC->LineTo(x1 + 25 * 8 * cosx+5*8, y1 + 25 * 8 * sinx);
//左圆圆内箭头线,22.5 度
x1 = x0 - 31 * 8, y1 = y0;//左圆
cosx = cos(22.5 / 180.0 * pai);//获取辅助线与水平线的角度余弦值
sinx = sin(22.5 / 180.0 * pai);
//箭头左上
x1 = x1 - 25 * 8 * cosx, y1 = y1 - 25 * 8 * sinx;
degree = 37.5 / 180 * pai;
points[0].x = x1, points[0].y = y1;
points[1].x = x1 + 3.5 * 8 * cos(degree), points[1].y = y1 + 3.5 *
8 * sin(degree);
degree =7.5 / 180 * pai;
points[2].x = x1 + 3.5 * 8 * cos(degree), points[2].y = y1 + 3.5 *
8 * sin(degree);
pDC->Polygon(points, 3);
double xm= (points[1].x + points[2].x) / 2, ym= (points[1].y + points[2
].y) / 2;//存箭头中点
//箭头右下
x1 = x1 + (50) * 8 * cosx, y1 = y1 + (50) * 8 * sinx;
degree = 7.5 / 180 * pai;
points[0].x = x1, points[0].y = y1;
points[1].x = x1 - 3.5 * 8 * cos(degree), points[1].y = y1 - 3.5 *
8 * sin(degree);
degree = 37.5 / 180 * pai;
points[2].x = x1 - 3.5 * 8 * cos(degree), points[2].y = y1 - 3.5 *
8 * sin(degree);
pDC->Polygon(points, 3);
//箭头连接线
pDC->MoveTo((points[1].x + points[2].x) / 2, (points[1].y + points[2].y)
/ 2);
pDC->LineTo(xm, ym);

 文本模块:

//上圆弧箭头文字
pDC->TextOut((x7 + (points[1].x + points[2].x) / 2) / 2 - 3 * 8, (y7
+ (points[1].y + points[2].y) / 2) / 2 - 4 * 8, _T("R25"), 3);
//下圆弧箭头文字
pDC->TextOut((x2 + (points[1].x + points[2].x) / 2) / 2 +3 * 8, (y2
+ (points[1].y + points[2].y) / 2) / 2 - 4 * 8, _T("R94"), 3);
//右小圆箭头文字
pDC->TextOut(x1 + 22 * 8 * cosx+8, y1 - 22 * 8 * sinx-3*8, _T("R22"
), 3);
//右大圆箭头文字
pDC->TextOut(x1 + 25 * 8 * cosx + 8, y1 + 25 * 8 * sinx - 3 *
8, _T("R38"), 3);
//左圆箭头文字
pDC->TextOut((xm+(points[1].x + points[2].x) / 2)/2-6*8, (ym+(points[1].y +
points[2].y) / 2)/2-7*8, _T("R50"), 3);
//八边形左箭头文字
pDC->TextOut(x9-4*8, y0+8+8, _T("37"), 2);
//圆心距离箭头文字
pDC->TextOut(xd, yd-25, _T("62"), 2);

效果图:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/321353.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

CNN——VGG

1.VGG简介 论文下载地址:https://arxiv.org/pdf/1409.1556.pdf VGGNet 是由牛津大学视觉几何小组(Visual Geometry Group, VGG)提出的一种深层卷积网络结构,他们以 7.32% 的错误率赢得了 2014 年 ILSVRC 分类任务的亚军&#xff…

k8s yaml文件pod的生命周期

Pod是k8s中最小限额资源管理组件,也是最小化运行容器化的应用的资源管理对象。 Pod是一个抽象的概念,可以理解为一个或者多个容器化应用的集合。 在一个pod当中运行一个容器是最常用的方式。 在一个pod当中同时运行多个容器,在一个pod当中…

jupyter更改默认路径到其它的目录或者到其它的盘 比如D盘

1.打开终端 输入jupyter notebook --generate-config 如下 2.在C:\Users\mb5958\.jupyter路径下 3.用记事本打开它,搜索directory 4.在你想要的路径下新建一个文件夹,如‘D:\jupyterFile’,然后将路径名放在c.NotebookApp.notebook_dir"…

Spring见解 1.2

2.3.Spring的IOC解决程序耦合 2.3.1.创建工程 2.3.1.1.pom.xml <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:sc…

Python 快速合并PDF表格转换输出CSV文件

单位的刷脸考勤机后台系统做得比较差&#xff0c;只能导出每个部门的出勤统计表pdf&#xff0c;格式如下&#xff1a; 近期领导要看所有部门的考勤数据&#xff0c;于是动手快速写了个合并pdf并输出csv文件的脚本。 安装模块 pypdf2&#xff0c;pdfplumber&#xff0c;前者用…

华清远见作业第二十一天——IO(第四天)

思维导图&#xff1a; 创建出三个进程完成两个文件之间拷贝工作&#xff0c;子进程1拷贝前一半内容&#xff0c;子进程2拷贝后一半内容&#xff0c;父进程回收子进程的资源。 代码&#xff1a; #include<myhead.h> int main(int argc, const char *argv[]) {if(argc!3)…

使用results.csv文件数据绘制mAP对比图

yolov5每次train完成&#xff08;如果没有中途退出&#xff09;都会在run目录下生成expX目录&#xff08;X代表生成结果次数 第一次训练完成生成exp0 第二次生成exp1…以此类推&#xff09;。expX目录下会保存训练生成的weights以及result.txt文件&#xff0c;其中weights是训练…

freeRTOS——队列集知识总结及实战

1队列集概念 可以在任务间传递不同数据类型的消息 作用&#xff1a;用于对多个队列或信号量进行“监听”&#xff0c;其中不管哪一个消息到来&#xff0c;都可让任务退出阻塞状态 2队列集API函数 1&#xff09;创建队列集 QueueSetHandle_t xQueueCreateSet( const UBaseType…

调用百度地图 API 的步骤详解

百度地图 Web 服务 API 为开发者提供 http/https 接口&#xff0c;即开发者通过 http/https 形式发起检索请求&#xff0c;获取返回 json 或 xml 格式的检索数据。用户可以基于此开发 JavaScript、C#、C、Java 等语言的地图应用。百度地图 API 在线地址为&#xff1a;baidumap.…

C#使用switch多路选择语句判断何为季节

目录 一、 switch语句 二、示例 三、生成 一、 switch语句 switch语句是多路选择语句&#xff0c;它通过一个表达式的值来使程序从多个分支中选取一个用于执行的分支。 switch表达式的值只可以是整型、字符串、枚举和布尔类型。 switch语句中多个case可以使用一个break。 在…

氢燃料电池——产品标准规范汇总和梳理

文章目录 氢燃料电池模块 氢燃料电池发动机 氢燃料电池汽车 加氢系统 总结 氢燃料电池模块 GB/T 33978-2017 道路车辆用质子交换膜燃料电池模块 GB/T 43361-2023 气体分析 道路车辆用质子交换膜燃料电池氢燃料分析方法的确认 GB/T 29729-2022 氢系统安全的基本要求 GB/T 4…

python报错:TypeError: Descriptors cannot be created directly.

问题 报错提示&#xff1a; TypeError&#xff1a;不能直接创建描述符。 如果此调用来自 _pb2.py 文件&#xff0c;则您生成的代码已过期&#xff0c;必须使用 protoc > 3.19.0 重新生成。 如果您不能立即重新生成原型&#xff0c;其他一些可能的解决方法是&#xff1a; 1.…