基本信息
源码名称:用C++模拟圆弧插补(图形)
源码大小:2.44KB
文件格式:.cpp
开发语言:C/C++
更新时间:2019-04-25
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
用C 模拟圆弧插补(图形) http://blog.csdn.net/z893345329/article/details/25922857

#include <graphics.h>
#include <conio.h>
#include<iostream>
using namespace std;
void main(){
	int x0,y0,xe,ye,xi=0,yi=0,x,y,Fe,i=1,shun,rr=NULL;//rr为半径的平方
	int a1,a2,b1,b2;
	cout<<"######################"<<endl;
	cout<<"#欢迎来到圆弧插补程序#"<<endl;
	cout<<"######################"<<endl<<endl;
	do{
		cout<<"请输入起点坐标:"<<endl;
		cin>>x0>>y0;
		cout<<"请输入终点坐标:"<<endl;
		cin>>xe>>ye;
		cout<<"请输入圆心坐标:"<<endl;
		cin>>x>>y;
		if((xe-x)*(xe-x) (ye-y)*(ye-y)==(x0-x)*(x0-x) (y0-y)*(y0-y))
			rr=(xe-x)*(xe-x) (ye-y)*(ye-y);
		else cout<<"您输入的坐标够不成圆弧!"<<endl<<"请重新输入"<<endl;

	}	while(rr==NULL);
	do{
		cout<<"选择圆弧方向:1、顺时针;2、逆时针"<<endl;
		cin>>shun;
	}while(shun!=1&&shun!=2);
	cout<<endl<<"*****************************************************************************"<<endl;
	

/*	x0=300;y0=200;
	xe=400;ye=300;
	x=400;y=200;
	rr=(xe-x)*(xe-x) (ye-y)*(ye-y);
	shun=1;*/
	  xi=x0;yi=y0;//起点赋给xiyi
	initgraph(600, 600);
	while(xi!=xe||yi!=ye)//没有到达终点时
	{
		Fe=(xi-x)*(xi-x) (yi-y)*(yi-y)-rr;
		//cout<<"Fe:"<<Fe<<endl;//system("pause");
		if(Fe>=0)
		{
			if(shun==1){
				if(xi>=x&&yi<=y)
					xi--;
				else if(xi<=x&&yi<=y)
					yi  ;
				else if(xi<=x&&yi>=y)
					xi  ;
				else if(xi>=x&&yi>=y)
					yi--;
			}
			else if(shun==2){
				if(xi>=x&&yi<=y)
					yi  ;//xi--;
				else if(xi<=x&&yi<=y)
					xi  ;//yi  ;
				else if(xi<=x&&yi>=y)
					yi--;//xi  ;
				else if(xi>=x&&yi>=y)
					xi--;//yi--;
			}
		}
		else
		{
			if(shun==1){
				if(xi>=x&&yi<=y)
					yi--;//xi--;
				else if(xi<=x&&yi<=y)
					xi--;//yi  ;
				else if(xi<=x&&yi>=y)
					yi  ;//xi  ;
				else if(xi>=x&&yi>=y)
					xi  ;//yi--;
			}
			else if(shun==2){
				if(xi>=x&&yi<=y)
					xi  ;//yi  ;//xi--;
				else if(xi<=x&&yi<=y)
					yi--;//xi  ;//yi  ;
				else if(xi<=x&&yi>=y)
					xi--;//yi--;//xi  ;
				else if(xi>=x&&yi>=y)
					yi  ;//xi--;//yi--;
			}

		}

			b1=xi;b2=yi;
			if(i==1){
				a1=b1;a2=b2;
			}
		
			line(a1,(600-a2),b1,(600-b2));//line(a1,a2,b1,b2);
			a1=b1;a2=b2;
		
		cout<<i<<":\t"<<xi<<","<<yi<<endl;
		i  ;
		//system("pause");
	}
	//cout<<x0<<y0<<xe<<ye<<xi<<yi<<x<<y<<Fe<<i<<shun<<rr;
	

		




	cout<<endl<<"*****************************************************************************"<<endl<<endl;
		getch();	// 按任意键继续
	 closegraph();	// 关闭图形界面
	system("pause");

}