NEFU计算机图形学实验四

编写二次插值样条曲线生成函数,然后利用该函数根据自己设计的型值点绘制出相应的曲线图形。

// erView.cpp : implementation of the CErView class
//#include "stdafx.h"
#include "er.h"#include "erDoc.h"
#include "erView.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/
// CErView
void er(POINT *p,int n,CDC* pDC)
{int x,y,i,j,k=10;double t1,t2,t3,t,a,b,c,d;p[0].x=p[1].x;p[0].y=p[1].y;p[n+1].x=p[n].x;p[n+1].y=p[n].y;t=0.5/k;pDC->MoveTo(p[1].x,p[1].y);for(i=1;i<n;i++){for(j=1;j<k;j++){t1=j*t;t2=t1*t1;t3=t1*t2;a=4.0*t2-t1-4.0*t3;		b=1.0-10.0*t2+12.0*t3;	c=t1+8.0*t2-12.0*t3;	d=4.0*t3-2.0*t2;		x=(int)(a*p[i-1].x+b*p[i].x+c*p[i+1].x+d*p[i+2].x);y=(int)(a*p[i-1].y+b*p[i].y+c*p[i+1].y+d*p[i+2].y);pDC->LineTo(x,y);}pDC->LineTo(p[i+1].x,p[i+1].y);}
}IMPLEMENT_DYNCREATE(CErView, CView)BEGIN_MESSAGE_MAP(CErView, CView)//{{AFX_MSG_MAP(CErView)// 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 commandsON_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()/
// CErView construction/destructionCErView::CErView()
{// TODO: add construction code here}CErView::~CErView()
{
}BOOL CErView::PreCreateWindow(CREATESTRUCT& cs)
{// TODO: Modify the Window class or styles here by modifying//  the CREATESTRUCT csreturn CView::PreCreateWindow(cs);
}/
// CErView drawingvoid CErView::OnDraw(CDC* pDC)
{CErDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);// TODO: add draw code for native data hereint n=4;POINT ps[6];ps[1].x=25;ps[1].y=400;ps[2].x=100;ps[2].y=100;ps[3].x=175;ps[3].y=400;ps[4].x=250;ps[4].y=100;er(ps,n,pDC);}/
// CErView printingBOOL CErView::OnPreparePrinting(CPrintInfo* pInfo)
{// default preparationreturn DoPreparePrinting(pInfo);
}void CErView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{// TODO: add extra initialization before printing
}void CErView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{// TODO: add cleanup after printing
}/
// CErView diagnostics#ifdef _DEBUG
void CErView::AssertValid() const
{CView::AssertValid();
}void CErView::Dump(CDumpContext& dc) const
{CView::Dump(dc);
}CErDoc* CErView::GetDocument() // non-debug version is inline
{ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CErDoc)));return (CErDoc*)m_pDocument;
}
#endif //_DEBUG/
// CErView message handlers

编写任意阶次的Bezier曲线生成函数,然后利用该函数根据自己设计的控制点绘制出相应的曲线图形。

// renView.cpp : implementation of the CRenView class
//#include "stdafx.h"
#include "ren.h"#include "renDoc.h"
#include "renView.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/
// CRenView
double powi(double v,int k){double temp=1.0;if(k==0||v==0)return 1;else {for(int i=1;i<=k;i++)temp=temp*v;}return temp;}long fac(int m){int i;long temp=1;if(m==1)return 1;else {for(i=2;i<=m;i++)temp=temp*i;}return temp;}void Bezier(POINT *p,int n,CDC *pDC){int x,y,i,j,k=100;double t=1.0/k,t1,u,v;double temp,temp1,temp2,bi;pDC->MoveTo(p[0].x,p[0].y);for(j=1;j<k;j++){t1=j*t;u=t1;v=1-u;x=0;y=0;for(i=0;i<=n;i++){temp=double(fac(n)/fac(i)/fac(n-i));temp1=powi(u,i);temp2=powi(v,n-i);bi=temp*temp1*temp2;x=x+bi*p[i].x;y=y+bi*p[i].y;}pDC->LineTo(x,y);}pDC->LineTo(p[n].x,p[n].y);}IMPLEMENT_DYNCREATE(CRenView, CView)BEGIN_MESSAGE_MAP(CRenView, CView)//{{AFX_MSG_MAP(CRenView)// 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 commandsON_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()/
// CRenView construction/destructionCRenView::CRenView()
{// TODO: add construction code here}CRenView::~CRenView()
{
}BOOL CRenView::PreCreateWindow(CREATESTRUCT& cs)
{// TODO: Modify the Window class or styles here by modifying//  the CREATESTRUCT csreturn CView::PreCreateWindow(cs);
}/
// CRenView drawingvoid CRenView::OnDraw(CDC* pDC)
{CRenDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);int n=5;CPoint ps[6]={CPoint(25,400),CPoint(100,100),CPoint(170,400),CPoint(250,20),CPoint(450,300),CPoint(350,400)};CPen pen1(PS_DASHDOT,1,RGB(28,28,28));pDC->SelectObject(&pen1);pDC->Polyline(ps,6);CPen pen2(PS_DASHDOT,2,RGB(255,0,0));pDC->SelectObject(&pen2);Bezier(ps,n,pDC);
} /
// CRenView printingBOOL CRenView::OnPreparePrinting(CPrintInfo* pInfo)
{// default preparationreturn DoPreparePrinting(pInfo);
}void CRenView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{// TODO: add extra initialization before printing
}void CRenView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{// TODO: add cleanup after printing
}/
// CRenView diagnostics#ifdef _DEBUG
void CRenView::AssertValid() const
{CView::AssertValid();
}void CRenView::Dump(CDumpContext& dc) const
{CView::Dump(dc);
}CRenDoc* CRenView::GetDocument() // non-debug version is inline
{ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRenDoc)));return (CRenDoc*)m_pDocument;
}
#endif //_DEBUG/
// CRenView message handlers

编写三次B样条曲线生成函数,然后利用该函数根据自己设计的控制点绘制出相应的曲线图形。

// sanView.cpp : implementation of the CSanView class
//#include "stdafx.h"
#include "san.h"#include "sanDoc.h"
#include "sanView.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/
// CSanView
void BSpLine(POINT *p,int n,CDC* pDC)
{int x,y,i,j,k=1000;double t,t1,t2,t3,a,b,c,d;t=1.0/k;p[0].x=2*p[1].x-p[2].x;p[0].y=2*p[1].y-p[2].y;p[n].x=2*p[n-1].x-p[n-2].x;p[n].y=2*p[n-1].y-p[n-2].y;pDC->MoveTo(p[1].x,p[1].y);for(i=1;i<n-1;i++)for(j=1;j<=k;j++){t1=j*t;t2=t1*t1;t3=t2*t1;a=(3*t2-t3-3*t1+1)/6;b=(3*t3-6*t2+4)/6;c=(3*t2-3*t3+3*t1+1)/6;d=t3/6;x=int(a*p[i-1].x+b*p[i].x+c*p[i+1].x+d*p[i+2].x);y=int(a*p[i-1].y+b*p[i].y+c*p[i+1].y+d*p[i+2].y);pDC->LineTo(x,y);}
}IMPLEMENT_DYNCREATE(CSanView, CView)BEGIN_MESSAGE_MAP(CSanView, CView)//{{AFX_MSG_MAP(CSanView)// 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 commandsON_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()/
// CSanView construction/destructionCSanView::CSanView()
{// TODO: add construction code here}CSanView::~CSanView()
{
}BOOL CSanView::PreCreateWindow(CREATESTRUCT& cs)
{// TODO: Modify the Window class or styles here by modifying//  the CREATESTRUCT csreturn CView::PreCreateWindow(cs);
}/
// CSanView drawingvoid CSanView::OnDraw(CDC* pDC)
{CSanDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);// TODO: add draw code for native data hereint n=5;POINT ps[6];ps[1].x=350;ps[1].y=250;ps[2].x=500;ps[2].y=20;ps[3].x=600;ps[3].y=250;ps[4].x=750;ps[4].y=30;CPen pen1(PS_DASHDOT,2,RGB(0,0,255));pDC->SelectObject(&pen1);BSpLine(ps,n,pDC);CPen pen2(PS_DASHDOT,1,RGB(28,28,28));pDC->SelectObject(&pen2);pDC->Polyline(ps,6);} /
// CSanView printingBOOL CSanView::OnPreparePrinting(CPrintInfo* pInfo)
{// default preparationreturn DoPreparePrinting(pInfo);
}void CSanView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{// TODO: add extra initialization before printing
}void CSanView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{// TODO: add cleanup after printing
}/
// CSanView diagnostics#ifdef _DEBUG
void CSanView::AssertValid() const
{CView::AssertValid();
}void CSanView::Dump(CDumpContext& dc) const
{CView::Dump(dc);
}CSanDoc* CSanView::GetDocument() // non-debug version is inline
{ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSanDoc)));return (CSanDoc*)m_pDocument;
}
#endif //_DEBUG/
// CSanView message handlers

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

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

相关文章

大型语言模型高效推理综述

论文地址&#xff1a;2404.14294.pdf (arxiv.org) 大型语言模型&#xff08;LLMs&#xff09;由于在各种任务中的卓越表现而受到广泛关注。然而&#xff0c;LLM推理的大量计算和内存需求给资源受限的部署场景带来了挑战。该领域的努力已经朝着开发旨在提高LLM推理效率的技术方…

C语言递归刷题(一)

目录 走台阶题目思路代码 西格玛题目思路代码 用函数实现数的阶乘题目思路代码 digit题目思路代码 Hermite多项式题目思路代码 排列数题目思路代码 逆序输出题目思路代码 结语 走台阶 题目 描述 小乐乐上课需要走n阶台阶&#xff0c;因为他腿比较长&#xff0c;所以每次可以选…

常见的SSH功能

SSH&#xff08;Secure Shell&#xff09;是一种加密的网络传输协议&#xff0c;用于在不安全的网络中为网络服务提供安全的传输环境。SSH最初是由芬兰的一家公司开发的&#xff0c;现在已经成为互联网上最常用的远程登录工具之一。SSH提供了许多强大的功能&#xff0c;让我们能…

挑战特斯拉?深蓝汽车与华为强强联手

作为中国乃至全球汽车行业的盛宴&#xff0c;4月25日在中国国家展览中心揭幕的2024北京国际车展&#xff0c;吸引了无数企业行业人士的关注。 而就在车展开幕当天&#xff0c;深蓝汽车发布会就爆出了一个大新闻&#xff1a;深蓝汽车将携手华为&#xff0c;打造比特斯拉更好的智…

面试逻辑题,有8个小球和一个天平,一个小球偏重,其它小球一样重,问最少称几次可以找出那个重球?

1. 问题描述 现在有8个小球和一个天平&#xff0c;已知其中1个小球偏重&#xff0c;其余小球重量相等。问&#xff1a;最少称几次一定可以找出那个重量更大的小球&#xff1f; 2. 解题思路 第一次称重&#xff1a;将任意三个小球放在天平的左边&#xff0c;将另外三个小球放…

【内附完整redis配置文件】linux服务器命令设置redis最大限制内存大小,设置redis内存回收机制,redis有哪些回收机制

redis经常出现进程自己挂掉&#xff0c;经排查后是因为redis占用内存过大&#xff0c;导致服务器内存爆满进程自己挂掉 第一步&#xff1a;打开 Redis 的配置文件 打开 Redis 的配置文件 redis.conf&#xff0c;通常位于 /etc/redis/redis.conf。 第二步&#xff1a;设置redi…

【开发问题记录】启动某个服务时请求失败(docker-componse创建容器时IP参数不正确)

问题记录 一、问题描述1.1 产生原因1.2 产生问题 二、问题解决2.1 找到自己的docker-compose.yml文件2.2 重新编辑docker-compose.yml文件2.3 通过docker-componse重新运行docker-compose.yml文件2.4 重新启动docker容器2.5 查看seata信息 一、问题描述 1.1 产生原因 因为我是…

FPGA 以太网通信UDP通信环回

1 实验任务 上位机通过网口调试助手发送数据给 FPGA &#xff0c; FPGA 通过 PL 端以太网接口接收数据并将接收到的数据发送给上位机&#xff0c;完成以太网 UDP 数据的环回。 2 系统设计 系统时钟经过PLL时钟模块后&#xff0c;生成了两种不同频率和相位的时钟信号&#…

第29篇 分布式网站

大型分布式网站架构是指将一个网站系统分解为多个独立的组件或服务&#xff0c;这些组件或服务部署在不同的物理或虚拟机器上&#xff0c;协同工作以提供高效、可靠且可扩展的网站功能。这种架构设计旨在应对高并发访问、处理海量数据、保证服务高可用性、快速响应业务变化及增…

Python 面向对象——6.封装

本章学习链接如下&#xff1a; Python 面向对象——1.基本概念 Python 面向对象——2.类与对象实例属性补充解释&#xff0c;self的作用等 Python 面向对象——3.实例方法&#xff0c;类方法与静态方法 Python 面向对象——4.继承 Python 面向对象——5.多态 1. 封装的基…

unity cinemachine相机 (案例 跟随角色移动)

安装相机包 打开包管理工具 在 unity registry 搜索cinemachine 会在maincamera中生成一个组件cinemachineBrain 只能通过虚拟相机操控 主相机 虚拟相机的参数 案例 1.固定相机效果 位置 在固定的地方 默认的模式 2.相机跟随人物效果 焦距设置 20 跟随设置 把playere…

使用Tortoise 创建远程分支

1。首先创建本地分支branch1&#xff0c;右键tortoise git->创建分支&#xff0c;输入分支名称branch1&#xff0c;确定。 2。右键tortoise git->推送&#xff0c;按下图设置&#xff0c;确定&#xff0c;git会判断远程有没有分支branch1&#xff0c;如果没有会自动创建…

centOS7.9| 无root安装 openssl 1.1.1

这里写自定义目录标题 0.先安装 gcc121.下载和编译 openssl 1.1.12. 让 pkg-config 能找到.pc文件 0.先安装 gcc12 见之前的博客: 无root编译安装 gcc12 1.下载和编译 openssl 1.1.1 https://www.openssl.org/source/https://github.com/openssl/openssl/releases?page3 (2…

重看Spring聚焦Environment分析

目录 一、理解Environment的设计 &#xff08;一&#xff09;整体理解 &#xff08;二&#xff09;聚焦Profiles分析 &#xff08;三&#xff09;聚焦Properties分析 二、Environment类图结构分析 三、PropertyResolver源码分析 &#xff08;一&#xff09;源码展示说明…

C语言学习/复习36

一、程序的环境与预处理 二、翻译环境与执行环境 三、运行环境 四、预编译(预处理)详解

【SpringBoot】92、SpringBoot中使用SSE实现服务端向客户端推送实时消息

在Spring Boot中整合Server-Sent Events (SSE) 是一种简单且有效的方法,用于实现服务器向客户端推送实时更新的功能。SSE 是一种服务器到客户端的单向通信协议,允许服务器推送消息到客户端,而不需要客户端发出请求。 1、添加依赖 首先,确保你的Spring Boot项目中已经包含…

mac电脑搭建vue环境(上篇)

第一步&#xff1a;mac电脑要有homebrew&#xff0c;如何安装homebrew 点击下方 MAC安装homebrew-CSDN博客 第二步&#xff1a;homebrew安装node.js 第三步&#xff1a;安装npm 第四步&#xff1a;安装webpack 第五步&#xff1a;安装vue脚手架 第六步&#xff1a;可以在…

大文件分片上传前端手写

此前介绍过&#xff0c;文件上传前端有造好的轮子可以方便使用&#xff0c;比如百度fex的webuploader。那么我们离开这些轮子&#xff0c;自己手写一个难不难呢&#xff1f;完成基本功能确实不难&#xff0c;但是要把方方面面的情况都考虑到&#xff0c;那可就不简单了。我们先…

NumPy 1.26 中文官方指南(一)

NumPy 用户指南 原文&#xff1a;numpy.org/doc/1.26/user/index.html 本指南是一个概述&#xff0c;解释了重要特性&#xff1b;细节请参阅 NumPy 参考文档。 入门指南 什么是 NumPy? 安装 NumPy 快速入门 NumPy&#xff1a;初学者的绝对基础 基础知识和用法 NumPy 基础…

工信部绿色工厂、绿色设计产品、绿色供应链企业、绿色园区名单数据集(2017-2022年)

01、数据简介 工信部致力于推动制造业的绿色转型&#xff0c;为了表彰在绿色制造领域取得显著成绩的企业和园区&#xff0c;工信部发布了绿色工厂公示名单、绿色设计产品公示名单、绿色供应链企业公示名单和绿色园区公示名单。 这些企业和园区在绿色制造方面做出了卓越的贡献…