《椭圆增量方程画椭圆》由会员分享,可在线阅读,更多相关《椭圆增量方程画椭圆(3页珍藏版)》请在金锄头文库上搜索。
1、椭圆增量方程椭圆增量方程是以椭圆上点P(x,y)坐标增量y与坐标增量x为递推关系的计算方法定义椭圆增量方程是以椭圆上点P(x,y)坐标增量y与坐标增量x为递推关系的计算方法,可以用此方法画椭圆推导椭圆是以(-c,0)为圆心,为半径的曲线 设有增量(1)-(2)将代入(3)式用椭圆增量方程画椭圆C语言代码如下:/ ConsoleApplication1.cpp : 定义控制台应用程序的入口点。#include stdafx.h#include iostream#include graphics.h#include stdlib.h#include stdio.h#include conio.h#
2、include dos.husing namespace std;void wholecolor(double xc,double yc,double x1,double y1,double x2,double y2,int color) putpixel(xc+x1,yc+y1,color); putpixel(xc-x1,yc-y1,color); putpixel(xc+x2,yc+y2,color); putpixel(xc-x2,yc-y2,color); void ellipse( double xc,double yc,double a,double b,double ,int
3、color) double sqa = a * a; double sqb = b * b; double sqc = (double)sqrt(sqa-sqb); double e=sqc/a; double sqe=e*e; double x = -a; double y = 0; double dx=0; double dy= sqrt(2*(sqe-1)*x*dx+(sqe-1)*dx*dx); double r; double 1,x1,y1,x2,y2; double PI=3.1415926; =(/180)*PI; r=sqrt(x+dx)*(x+dx)+(y+dy)*(y+d
4、y); 1=atan(y+dy)/(x+dx); x1=r*cos(+1); y1=r*sin(+1); x2=r*cos(-1); y2=r*sin(-1); while(dx=2*a) wholecolor(xc,yc,x1,y1,x2,y2,color); dx=dx+0.01; dy= sqrt(2*(sqe-1)*x*dx+(sqe-1)*dx*dx); r=sqrt(x+dx)*(x+dx)+(y+dy)*(y+dy); 1=atan(y+dy)/(x+dx); x1=r*cos(+1); y1=r*sin(+1); x2=r*cos(-1); y2=r*sin(-1); int main() initgraph(640,480); /启动图形库ellipse(250,200,80,50,90,BLUE); /画椭圆,五个参数,中心点坐标(x,y),长轴a,短轴b,顺时针旋转角 getchar(); closegraph(); /关闭图形库 return 0;在VS2012下,编译通过执行效果如下: