C++画圆(计算机图形学)

C++画圆(计算机图形学),第1张

#include <math.h>

#include <graphics.h> /*预定义库函数*/

void circlePoint(int x,int y) /*八分法画圆程序*/

{

circle(320 x*20,240 y*20,3)

circle(320 y*20,240 x*20,3)

circle(320-y*20,240 x*20,3)

circle(320-x*20,240 y*20,3)

circle(320-x*20,240 y*20,3)

circle(320-x*20,240-y*20,3)

circle(320-y*20,240-x*20,3)

circle(320 y*20,240-x*20,3)

circle(320 x*20,240-y*20,3)

}

void MidBresenhamcircle(int r) /* 中点Bresenham算法画圆的程序 */

{

int x,y,d

x=0y=rd=1-r /* 计算初始值 */

while(x<y)

{ circlePoint(x,y) /* 绘制点(x,y)及其在八分圆中的另外7个对称点 */

if(d<0) d =2*x 3 /* 根据误差项d的判断,决定非最大位移方向上是走还是不走 */

else

{ d =2*(x-y) 5

y--

}

delay(900000)

} /* while */

}

main()

{

int i,j,r,graphmode,graphdriver

detectgraph(&graphdriver,&graphmode)

initgraph(&graphdriver,&graphmode," ")

printf("中点Bresenhamcircle算法画圆的程序\n") /*提示信息*/

printf("注意 |r|<=11")

printf("\n输入半径值 r:")

scanf("%d",&r)

printf("按任意键显示图形...")

getch()

cleardevice()

setbkcolor(BLACK)

for(i=20i<=620i =20) /*使用双循环画点函数画出表格中的纵坐标*/

for(j=20j<=460j )

putpixel(i,j,2)

for(j=20j<=460j =20) /*使用双循环画点函数画出表格中的横坐标*/

for(i=20i<=620i )

putpixel(i,j,2)

outtextxy(320,245,"0") /*原点坐标*/

outtextxy(320-5*20,245,"-5")circle(320-5*20,240,2) /*横坐标值*/

outtextxy(320 5*20,245,"5")circle(320 5*20,240,2)

outtextxy(320-10*20,245,"-10")circle(320-10*20,240,2)

outtextxy(320 10*20,245,"10")circle(320 10*20,240,2)

outtextxy(320-15*20,245,"-15")circle(320-15*20,240,2)

outtextxy(320 15*20,245,"15")circle(320 15*20,240,2)

outtextxy(320,240-5*20,"-5")circle(320,240-5*20,2) /*纵坐标值*/

outtextxy(320,240 5*20,"5")circle(320,240 5*20,2)

outtextxy(320,240-10*20,"-10")circle(320,240-10*20,2)

outtextxy(320,240 10*20,"10")circle(320,240 10*20,2)

outtextxy(20,10,"The center of the circle is (0,0) ") /*坐标轴左上角显示提示信息*/

setcolor(RED) /*标记坐标轴*/

line(20,240,620,240) outtextxy(320 15*20,230,"X")

line(320,20,320,460) outtextxy(330,20,"Y")

setcolor(YELLOW)

MidBresenhamcircle(r)

setcolor(BLUE) /*绘制圆*/

circle(320,240,r*20)

setcolor(2)

getch()

closegraph()

}

你最好找本计算机图形学的书看一下,

下面的例子,

http://www.pudn.com/downloads23/sourcecode/graph/detail75771.html

给出起点和终点:

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <graphics.h>

void swap_start_end(int &x1,int &y1,int &x2,int &y2)

void s_line(int x1,int y1,int x2,int y2)

main()

void swap_start_end(int &x1,int &y1,int &x2,int &y2)

{

int mid

mid=x1

x1=y1

y1=mid

mid=x2

x2=y2

y2=mid

if(x2-x1>=0)

dutx=1

cury+=ty

putpixel(i,j,2)

outtextxy(320,245,"0")/*原点坐标*/

outtextxy(320-5*20,245,"-5")circle(320-5*20,240,2)/*横坐标值*/

outtextxy(320 5*20,245,"5")circle(320 5*20,240,2)

outtextxy(320-10*20,245,"-10")circle(320-10*20,240,2)

outtextxy(320 10*20,245,"10")circle(320 10*20,240,2)

outtextxy(320-15*20,245,"-15")circle(320-15*20,240,2)

outtextxy(320 15*20,245,"15")circle(320 15*20,240,2)

outtextxy(320,240-5*20,"-5")circle(320,240-5*20,2)/*纵坐标值*/

outtextxy(320,240 5*20,"5")circle(320,240 5*20,2)

outtextxy(320,240-10*20,"-10")circle(320,240-10*20,2)

outtextxy(320,240 10*20,"10")circle(320,240 10*20,2)

outtextxy(20,10,"The center of the circle is (0,0) ")/*坐标轴左上角显示提示信息*/

setcolor(RED)/*标记坐标轴*/

line(20,240,620,240)outtextxy(320 15*20,230,"X")

line(320,20,320,460)outtextxy(330,20,"Y")

扩展资料:

C++语言的程序因为要体现高性能,所以都是编译型的。但其开发环境,为了方便测试,将调试环境做成解释型的。即开发过程中,以解释型的逐条语句执行方式来进行调试,以编译型的脱离开发环境而启动运行的方式来生成程序最终的执行代码。

生成程序是指将源码(C++语句)转换成一个可以运行的应用程序的过程。如果程序的编写是正确的,那么通常只需按一个功能键,即可搞定这个过程。该过程实际上分成两个步骤。

第一步是对程序进行编译,这需要用到编译器(compiler)。编译器将C++语句转换成机器码(也称为目标码);如果这个步骤成功,下一步就是对程序进行链接,这需要用到链接器(linker)。链接器将编译获得机器码与C++库中的代码进行合并。

参考资料来源:百度百科-C++


欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/yw/7753615.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-09
下一篇2023-04-09

发表评论

登录后才能评论

评论列表(0条)

    保存