当前位置:首页 > 代码 > 正文

计算机图形学代码(计算机图形学代码画一个人)

admin 发布:2022-12-19 09:04 98


今天给各位分享计算机图形学代码的知识,其中也会对计算机图形学代码画一个人进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

求计算机图形学画扇形全部代码?

void CDrawtest1View::OnMouseMove(UINT nFlags, CPoint point)

{

// TODO: Add your message handler code here and/or call default

if (m_bDraw)

{

CClientDC dc(this);

dc.SetROP2(R2_COPYPEN);

CPen pen(PS_SOLID,1,RGB(255,0,0));

CPen *pOldPen = dc.SelectObject(pen);

dc.MoveTo(m_ptStart);

dc.LineTo(m_ptEnd);

dc.LineTo(point);

m_ptEnd = point;

dc.SelectObject(pOldPen);

}

CView::OnMouseMove(nFlags, point);

}

全部太多垃圾。关键部分作参考吧。

信息与计算科学专业考研方向

信息与计算科学专业考研方向如下:

计算机类:计算机系统结构、微型计算机系统、并行分布/处理与智能计算机系统、计算机软件、人工智能与智能控制、计算机图形学及计算机辅助设计、计算机信息处理与应用、计算机设计自动化与计算机科学理论。

自动化控制类:控制理论与控制工程,模式识别,测控,精密仪器,导航制导。

数学类:基础数学,计算数学,应用数学,运筹学,金融数学,系统工程。

经济类:统计学,国际贸易,国际金融,投资,产业经济学。

管理类:运筹学,企业管理。

扩展资料

信息与计算科学专业的发展目标是随着互联网发展,大数据、互联网+等一系列新理念的诞生,信息与计算科学专业得到了前所未有的发展机会。

在人才培养方面,在夯实数学基础的前提下,针对不同类型学生,培养具有数据分析、信息处理、数据库运营与维护、软件开发和大数据分析的多层次的应用型人才。

在专业建设方面,加强师资队伍和学科建设,调动教师的积极性和创造性,积极与校友和企业联系,在企业与市场需求方面,引导教师科研和教学内容改革,形成企业资助专业建设,专业建设反哺企业的全新双赢局面。

参考资料来源:百度百科—信息与计算科学

专业老师在线权威答疑 zy.offercoming.com

计算机图形学的weiler-atherton算法代码

CS 535

WEILER-ATHERTON

PROBLEM

Implement Weiler-Atherton. You should draw each polygon in a different color and fill the clip areas generated with a third color.

NOTES:

The Weiler-Atherton algorithm is the most general of the clipping algorithms. We have two 2D polygons (may be convex or concave and they both may have holes). The polygon to be clipped is called the SUBJECT polygon and the polygon defining the clipping area is called the CLIP polygon. To make the algorithm work easier (in the data structures, etc.) we usually assume that the exterior vertices are given clockwise and the hole vertices are given counterclockwise. In clipping we usually want to find the parts of the subject polygon that are inside the clip polygon. However, this algorithm can be used in modeling to find the "union", "intersection", and "difference" of the polygons.

The data structures are several circular linked lists of vertices which are also linked together and the clipping is done by traversing these. The lists could be doubly linked. This enables the traversal in either direction at any node in the list. Starting at a particular node and traversing in one direction will produce the interior polygon(s) while starting at a different node and traversing can produce the outside. Note that producing the exterior does need the doubly linking and care must be taken in performing the traversal.

STEP 1:

The first phase of the building of the data structures occurs when we input the edges and put them in two linked lists - the SUBJ list and the CLIP list. The vertices are place in order from input (thus clockwise). There are separate lists for the exterior and for each hole. Thus, the initial build is a standard queue insert (input a vertex - insert it at end of list). Note that this creates a list in which a standard list traversal is equivalent to "walking around" the polygon edge visiting the vertices in order.

STEP 2:

The second phase of the list building is computing and inserting the INTERSECTION points. If we have a SUBJECT polygon edge (SVi to SVi+1) that intersects a CLIP polygon edge (CVj to CVj+1) at a point INTER. Note that the edges form straight lines that may intersect, we are assuming that the line segments SVi to SVi+1 intersects the line segment CVj to CVj+1. The intersection point INTER is then inserted on BOTH of the linked lists - SUBJ and CLIP. It is inserted BETWEEN SVi and SVi+1 on the SUBJ list and CVj and CVj+1 on the CLIP list. The idea is still that traversing the list using a standard list traversal we would encounter the points in their geometric order. Note that there may be several intersection points between any given pair of vertices and they must be inserted in the correct order in the lists. This is done by using the t and u values computed in the vector line intersection subprogram. Each intersection point thus has TWO nodes - one on each list (SUBJ and CLIP). We link these two entries together which provides a way of getting from one list to the other.

STEP 2.5:

Any straight line divides the plane into two half-planes. Thus each polygon edge (extended to a line) will divide the plane into two half-planes. Because we listed the vertices clockwise, we consider the half-plane to the right as containing the interior of the polygon. Thus the right half-plane is called the interior half-plane. If we consider ourselves as "walking along" a polygon edge, then we can categorize each of the INTERSECTION points as "entering" or "exiting". This is usually done from the SUBJ polygon's point of view. Thus, as we walk along the SUBJ polygon edge SVi to SVi+1 and we encounter intersection point INTER, we can ask the question - am I "entering" the CLIP polygon or am I "exiting" the CLIP polygon? The second part of computing the intersection point is to classify them as "entering" or "exiting". We create one or two lists - one for entering intersections and one for exiting intersections.

STEP3:

Once the lists are built the basic idea to do the clipping is as follows

Pick an entry from the ENTERING list - it will be an intersection point (and delete it)

Locate that point on the SUBJ list

Traverse the current (SUBJ) list until you find the next intersection point - it should be an exiting or entering point. Output each vertex encountered to some data structure, say POLY

Follow the link from the current (SUBJ) list to the other (CLIP) list and

Continue the traversal until you find the next intersection (Note: delete each entering intersection from the ENTERING list - not the linked lists. By deleting it we will get the distinct intersecting polygons and not duplicate a polygon multiple times).

Terminate the traversal when you get to an intersection that is the SAME as the initial one that you removed from the ENTERING list. At this point POLY will have one of the clip regions and can be output.

REPEAT the construction and output of POLY until the ENTERING list is empty.

Remark: For the exterior, try starting with an EXITING point. Start the traversal on the SUBJ list (same direction as the Interior). At what point do you need to use the double link and to traverse in the opposite direction? (Hint: look at the CLIP polygon list).

IMPLEMENTATION:

In the below data structures we place all of the vertices and intersection points in a 1D array and use the subscript instead of the actual coordinates.

const int MAXVERT = 500;

const int MAXPOLYV = 50;

const int MAXH = 10;

struct Point2D

{float x,y;

};

typedef Point2D Vertices[MAXVERT];

enum VerType = {Polygon, Intersection};

typedef struct ClipListRec * ClipPtr;

struct ClipListRec

{ int Vindex;

ClipPtr next;

VerType Kind;

float t;

ClipPtr otherList;

}

struct Polygon

{ int nVertex;

int vert[MAXPOLYV];

ClipPtr list;

}

struct GenPolygon

{ Polygon exterior;

int numHoles;

Polygon Holes[MAXH];

}

GenPolygon Sub,Clip;

int entering[MAXVERT],exiting[MAXVERT];

Vertices V;

int numVertex = 0; // size of the array of verticies

int clipPoly[MAXVERT]; // a clip polygon

int readPoint();

{ cin inX; cin inY;

if (numVertex MAXVERT)

{ V[numVertex].x = inX;

V[numVertex].y = inY;

idNo = numVertex;

numVertex++;

}

else

idNo = -1;

return idNo;

}

void readPolygon (GenPolygon p)

{ cin p.exterior.nVertex;

for (i = 0; i p.exterior.nVertex; i++)

{ newId = readPoint();

if (newId 0)

error

else

{ insertAtRear (p.exterior.list,newId);

p.exterior.vert[i] = newId;

}

}

// now do the holes basically the same way

. . .

}

// the "main" program loop would then be (pseudocode)

while (!EMPTY(entering))

{ nextInter = delete (entering);

SEARCH (SubjectPolygon,nextInter,ptr1);

AddToOutputList (ptr1-. . .)

StartPoint = ptr1-. . .

ptr1 = prt1-next;

while (ptr1-. . . != StartPoint)

{ AddToOutputList (ptr1-. . .);

if (ptr1- . . == INTERSECTION)

ptr1 = prt1-otherList-next;

else

ptr1 = ptr1-next;

}

FixListForOutput();

DrawPolygon();

EmptyOutputList();

}

求代码注释:计算机图形学的OpenGL画四面体。高手来吧。争取每句都注释下。谢谢

#include gl/glut.h

#define WIDTH 400

#define HEIGHT 400

#include math.h

#define ColoredVertex(c, v) do{ glColor3fv(c); glVertex3fv(v); }while(0) //这段就不用解释了吧……

GLfloat angle = 0.0f; //设定转角

void myDisplay(void) //绘图函数

{

static int list = 0;

if( list == 0 )

{

// 如果显示列表不存在,则创建

GLfloat //GLfloat为OpenGL用到的数据类型,与C的float基本一致

PointA[] = {-0.5, -5*sqrt(5)/48, sqrt(3)/6}, //此处为4个顶点的坐标,因为时3D坐标系下的,所以每个坐标有3个分量,分别对应X,Y,Z轴。至于各轴方向定义……默认下屏幕水平为X,竖直为Y,里外为Z。

PointB[] = { 0.5, -5*sqrt(5)/48, sqrt(3)/6},

PointC[] = { 0, -5*sqrt(5)/48, -sqrt(3)/3},

PointD[] = { 0, 11*sqrt(6)/48, 0};

/*GLfloat

PointA[] = { 0.5f, -sqrt(6.0f)/12, -sqrt(3.0f)/6},

PointB[] = {-0.5f, -sqrt(6.0f)/12, -sqrt(3.0f)/6},

PointC[] = { 0.0f, -sqrt(6.0f)/12, sqrt(3.0f)/3},

PointD[] = { 0.0f, sqrt(6.0f)/4, 0};

*/

GLfloat

ColorR[] = {1, 0, 0}, //定义颜色数组,每个数组为一个颜色,也含有3个分量,对应红,绿,蓝,分量范围[0,1],每种颜色都可看做是这3个颜色混合得到。可一自己改变下其中的数值看看具体效果。

ColorG[] = {0, 1, 0},

ColorB[] = {0, 0, 1},

ColorY[] = {1, 1, 0};

list = glGenLists(1);

glNewList(list, GL_COMPILE); //创建一个顶点表,这个表里包含有绘图的顶点信息

glBegin(GL_TRIANGLES); //开始绘图,(GL_TRIANGLES)表示绘制三角形

// 平面ABC

ColoredVertex(ColorR, PointA); //以颜色R绘制点A,以下类推,ColoredVertex()函数在程序开头定义了。

ColoredVertex(ColorG, PointB);

ColoredVertex(ColorB, PointC);

// 平面ACD

ColoredVertex(ColorR, PointA);

ColoredVertex(ColorB, PointC);

ColoredVertex(ColorY, PointD);

// 平面CBD

ColoredVertex(ColorB, PointC);

ColoredVertex(ColorG, PointB);

ColoredVertex(ColorY, PointD);

// 平面BAD

ColoredVertex(ColorG, PointB);

ColoredVertex(ColorR, PointA);

ColoredVertex(ColorY, PointD);

glEnd();

glEndList(); //结束绘图 结束绘图顶点表。

glEnable(GL_DEPTH_TEST); //打开深度测试。打开深度测试的作用是:如果在场景中有多个物体,而它们相对观察者的距离不同(简单理解为远近),那么这个时候,前面的物体则可以挡住后面的物体(没错吧),使场景具有深度感。如果不打开深度测试,那么绘图会按绘制的顺序,后绘制的物体覆盖住现绘制的物体。这里要注意的是,深度仅影响物体重合时谁显示谁不显示,并不影响其3D效果,远处的物体仍然会变“小”,物体在空间中的位置仍为三维的。

}

// 已经创建了显示列表,在每次绘制正四面体时将调用它

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //清除颜色缓存和深度缓存

glPushMatrix(); //绘图坐标系入栈,可以简单理解为存下了这次画图时画笔的起始位置

glRotatef(angle, 1, 0.5, 0); //绘图坐标系绕(1,0.5,0)轴旋转angle角,可理解为模型绕该轴旋转angle角。

glCallList(list); //调用顶点表,绘制四面体模型

glPopMatrix(); //绘图坐标系出栈,则回到了刚才的绘图起始位置

glutSwapBuffers(); //使用双缓存(第一个在前面显示模型,另一个在后面绘制新的模型,当新模型绘制完毕后送给第一个缓存显示。这样不会出现模型上一些点已经绘制完了,而另一些点还在绘制的情况。)

}

void myIdle(void)

{

++angle;

if( angle = 360.0f )

angle = 0.0f; //转角超过360度,将其置零。

myDisplay(); //绘制模型}

int main(int argc, char* argv[]) { glutInit(argc, argv); //创建绘图窗口

glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); //设置绘图模式

glutInitWindowPosition(200, 200); //设置窗口位置

glutInitWindowSize(WIDTH, HEIGHT); //设置窗口大小

glutCreateWindow("OpenGL 窗口"); //设置窗口标题

glutDisplayFunc(myDisplay); //重复调用函数

glutIdleFunc(myIdle);//重复调用函数

glutMainLoop(); //该循环用来对上述两个重复调用函数不断调用

return 0;

}

回答完毕。

计算机图形学 画任意弧度圆弧和椭圆弧的算法代码c++

给出起点和终点:

#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++

关于计算机图形学,代码对了,但是画不出图,大虾们看看哪里错了

你代码中的n用不到,这部分你自己改。

改过后已经能在tc3.0下编译运行了。(tc3安装在C:\TC目录,已打开到图形库的连接):

#includestdio.h

#includegraphics.h

#includemath.h

#includestdlib.h

#includeconio.h

int main()

{

static float x[]={0,-50,50};

static float y[]={50,-50,-50};

int n,i,k;

float t,t1,xo,yo,xx[4],yy[4];

int gdriver = DETECT, gmode, errorcode;

initgraph(gdriver, gmode, "C:\\TC\\BGI");

errorcode = graphresult();

if (errorcode != grOk)

{

printf("Fail to call initgraph: %s\n", grapherrormsg(errorcode));

printf("Press any key to quit");

getch();

return 1;

}

printf("please input n:");

scanf("%d",n);

xo=250;yo=240;

t=0.0174532;

cleardevice();

setbkcolor(1);

setcolor(WHITE);

for(i=0;i360;i=i+10)

{

t1=i*t;

for(k=0;k4;k++)

{

xx[k]=x[k]*cos(t1)-y[k]*sin(t1)+xo;

yy[k]=x[k]*sin(t1)+y[k]*cos(t1)+yo;

}

line(xx[0],yy[0],xx[1],yy[1]);

line(xx[1],yy[1],xx[2],yy[2]);

line(xx[2],yy[2],xx[0],yy[0]);

}

getch();

closegraph();

return 0;

}

计算机图形学代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于计算机图形学代码画一个人、计算机图形学代码的信息别忘了在本站进行查找喔。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/5676.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载