博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++ 生成三次贝塞尔曲线
阅读量:7109 次
发布时间:2019-06-28

本文共 2050 字,大约阅读时间需要 6 分钟。

 

// 三次贝塞尔.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include 
#include
#include
#define NUM_STEPS 30 //越大,曲线越密,越逼近using namespace std;class CvPoint{public: float x; float y; CvPoint() { x=0.0; y=0.0; } CvPoint(float a,float b) { x=a; y=b; }}; void curve4(vector
&p, double x1, double y1, //Anchor1 double x2, double y2, //Control1 double x3, double y3, //Control2 double x4, double y4) //Anchor2 { CvPoint tmp0(x1,y1); p.push_back(tmp0); double dx1 = x2 - x1; double dy1 = y2 - y1; double dx2 = x3 - x2; double dy2 = y3 - y2; double dx3 = x4 - x3; double dy3 = y4 - y3; double subdiv_step = 1.0 / (NUM_STEPS + 1); double subdiv_step2 = subdiv_step*subdiv_step; double subdiv_step3 = subdiv_step*subdiv_step*subdiv_step; double pre1 = 3.0 * subdiv_step; double pre2 = 3.0 * subdiv_step2; double pre4 = 6.0 * subdiv_step2; double pre5 = 6.0 * subdiv_step3; double tmp1x = x1 - x2 * 2.0 + x3; double tmp1y = y1 - y2 * 2.0 + y3; double tmp2x = (x2 - x3)*3.0 - x1 + x4; double tmp2y = (y2 - y3)*3.0 - y1 + y4; double fx = x1; double fy = y1; double dfx = (x2 - x1)*pre1 + tmp1x*pre2 + tmp2x*subdiv_step3; double dfy = (y2 - y1)*pre1 + tmp1y*pre2 + tmp2y*subdiv_step3; double ddfx = tmp1x*pre4 + tmp2x*pre5; double ddfy = tmp1y*pre4 + tmp2y*pre5; double dddfx = tmp2x*pre5; double dddfy = tmp2y*pre5; int step = NUM_STEPS; while(step--) { fx += dfx; fy += dfy; dfx += ddfx; dfy += ddfy; ddfx += dddfx; ddfy += dddfy; CvPoint tmp1(fx,fy); p.push_back(tmp1); } CvPoint tmp2(x4,y4); p.push_back(tmp2); } int _tmain(int argc, _TCHAR* argv[]){ CvPoint point[4]; point[0].x=1.0; point[0].y=4.0; point[1].x=2.2; point[1].y=5.0; point[2].x=6; point[2].y=3; point[3].x=8; point[3].y=9; vector
curvePoint; curve4(curvePoint, point[0].x,point[0].y, point[1].x,point[1].y, point[2].x,point[2].y, point[3].x,point[3].y ); int i=0; for(;i

 

 

转载地址:http://dclhl.baihongyu.com/

你可能感兴趣的文章
《精通Spring MVC 4》——1.4 命令行方式简介
查看>>
《C++覆辙录》——1.12:嘴上无毛,办事不牢
查看>>
阿里云大数据公众趋势预测
查看>>
git问题-更新被拒绝
查看>>
聊聊并发(四)深入分析ConcurrentHashMap
查看>>
大数据workshop:《云数据·大计算:海量日志数据分析与应用》之《数据采集:日志数据上传》篇...
查看>>
通过MongoDB安全事件来谈谈为什么要用云服务
查看>>
《C语言及程序设计》实践参考——分段函数求值
查看>>
【产品动态】云存储11月月刊
查看>>
C语言及程序设计进阶例程-11 体验结构体
查看>>
由金融服务中的智能机器人技术引发的种种思考
查看>>
【转载】如何成为Python高手
查看>>
mysql搭建多主多从
查看>>
json-lib net.sf.ezmorph.bean.MorphDynaBean cannot be cast to xxx
查看>>
工作中常用的linux命令(1)
查看>>
NGINX和PHP之间的环境变量传递
查看>>
【整理】自动的 Nginx 反向代理配置
查看>>
D语言,WEB日志导入到MongoDB
查看>>
一些颜色工具网站
查看>>
如何在Linux下如何安装多语言包
查看>>