用c或c++编一个画三维图形的程序
发布网友
发布时间:2022-11-09 18:34
我来回答
共3个回答
热心网友
时间:2023-11-21 12:54
TurboC 立方体
#include <dos.h>
#include <math.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
void DrawCube(int color);
int cx[9], cy[9];
int CubeCorners[9][4];
int CurX, CurY;
int Angle = 0;
int step = 2;
int Radius;
const double Pi = 3.14159265358979;
int main()
{
int GraphDriver;
int GraphMode;
int a, b;
GraphDriver = DETECT;
initgraph(&GraphDriver, &GraphMode, "");
Radius = 150;
CubeCorners[1][2] = 200 / 2;
CubeCorners[2][2] = 200 / 2;
CubeCorners[3][2] = -200 / 2;
CubeCorners[4][2] = -200 / 2;
CubeCorners[5][2] = 200 / 2;
CubeCorners[6][2] = 200 / 2;
CubeCorners[7][2] = -200 / 2;
CubeCorners[8][2] = -200 / 2;
DrawCube(12);
getch();
}
void DrawCube(int color)
{
int i;
for (i = 1; i <= 3; i += 2)
{
CubeCorners[i][3] = Radius * cos((Angle) * Pi / 180);
CubeCorners[i][1] = Radius * sin((Angle) * Pi / 180);
}
for (i = 2; i <= 4; i += 2)
{
CubeCorners[i][3] = Radius * cos((Angle + 2 * 45) * Pi / 180);
CubeCorners[i][1] = Radius * sin((Angle + 2 * 45) * Pi / 180);
}
for (i = 5; i <= 7; i += 2)
{
CubeCorners[i][3] = Radius * cos((Angle + 6 * 45) * Pi / 180);
CubeCorners[i][1] = Radius * sin((Angle + 6 * 45) * Pi / 180);
}
for (i = 6; i <= 8; i += 2)
{
CubeCorners[i][3] = Radius * cos((Angle + 4 * 45) * Pi / 180);
CubeCorners[i][1] = Radius * sin((Angle + 4 * 45) * Pi / 180);
}
for (i = 1; i <= 8; i++)
{
cx[i] = 300 + CubeCorners[i][1] + CubeCorners[i][3] / 8;
if (CubeCorners[i][2] > 0)
cy[i] = 200 + CubeCorners[i][2] + CubeCorners[i][3] / 8;
else if (CubeCorners[i][2] < 0)
cy[i] = 200 + CubeCorners[i][2] - CubeCorners[i][3] / 8;
else
cy[i] = 200 + CubeCorners[i][2];
}
setcolor(color);
moveto(cx[3], cy[3]);
lineto(cx[4], cy[4]);
lineto(cx[8], cy[8]);
lineto(cx[6], cy[6]);
lineto(cx[2], cy[2]);
lineto(cx[4], cy[4]);
moveto(cx[3], cy[3]);
lineto(cx[7], cy[7]);
lineto(cx[8], cy[8]);
moveto(cx[3], cy[3]);
lineto(cx[1], cy[1]);
lineto(cx[2], cy[2]);
moveto(cx[6], cy[6]);
lineto(cx[5], cy[5]);
lineto(cx[1], cy[1]);
moveto(cx[7], cy[7]);
lineto(cx[5], cy[5]);
}
热心网友
时间:2023-11-21 12:55
gogogo!
热心网友
时间:2023-11-21 12:55
c, vc
简单
c 参考
http://blog.csdn.net/ecjtuync/archive/2007/04/23/1576478.aspx
热心网友
时间:2023-11-21 12:54
TurboC 立方体
#include <dos.h>
#include <math.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
void DrawCube(int color);
int cx[9], cy[9];
int CubeCorners[9][4];
int CurX, CurY;
int Angle = 0;
int step = 2;
int Radius;
const double Pi = 3.14159265358979;
int main()
{
int GraphDriver;
int GraphMode;
int a, b;
GraphDriver = DETECT;
initgraph(&GraphDriver, &GraphMode, "");
Radius = 150;
CubeCorners[1][2] = 200 / 2;
CubeCorners[2][2] = 200 / 2;
CubeCorners[3][2] = -200 / 2;
CubeCorners[4][2] = -200 / 2;
CubeCorners[5][2] = 200 / 2;
CubeCorners[6][2] = 200 / 2;
CubeCorners[7][2] = -200 / 2;
CubeCorners[8][2] = -200 / 2;
DrawCube(12);
getch();
}
void DrawCube(int color)
{
int i;
for (i = 1; i <= 3; i += 2)
{
CubeCorners[i][3] = Radius * cos((Angle) * Pi / 180);
CubeCorners[i][1] = Radius * sin((Angle) * Pi / 180);
}
for (i = 2; i <= 4; i += 2)
{
CubeCorners[i][3] = Radius * cos((Angle + 2 * 45) * Pi / 180);
CubeCorners[i][1] = Radius * sin((Angle + 2 * 45) * Pi / 180);
}
for (i = 5; i <= 7; i += 2)
{
CubeCorners[i][3] = Radius * cos((Angle + 6 * 45) * Pi / 180);
CubeCorners[i][1] = Radius * sin((Angle + 6 * 45) * Pi / 180);
}
for (i = 6; i <= 8; i += 2)
{
CubeCorners[i][3] = Radius * cos((Angle + 4 * 45) * Pi / 180);
CubeCorners[i][1] = Radius * sin((Angle + 4 * 45) * Pi / 180);
}
for (i = 1; i <= 8; i++)
{
cx[i] = 300 + CubeCorners[i][1] + CubeCorners[i][3] / 8;
if (CubeCorners[i][2] > 0)
cy[i] = 200 + CubeCorners[i][2] + CubeCorners[i][3] / 8;
else if (CubeCorners[i][2] < 0)
cy[i] = 200 + CubeCorners[i][2] - CubeCorners[i][3] / 8;
else
cy[i] = 200 + CubeCorners[i][2];
}
setcolor(color);
moveto(cx[3], cy[3]);
lineto(cx[4], cy[4]);
lineto(cx[8], cy[8]);
lineto(cx[6], cy[6]);
lineto(cx[2], cy[2]);
lineto(cx[4], cy[4]);
moveto(cx[3], cy[3]);
lineto(cx[7], cy[7]);
lineto(cx[8], cy[8]);
moveto(cx[3], cy[3]);
lineto(cx[1], cy[1]);
lineto(cx[2], cy[2]);
moveto(cx[6], cy[6]);
lineto(cx[5], cy[5]);
lineto(cx[1], cy[1]);
moveto(cx[7], cy[7]);
lineto(cx[5], cy[5]);
}
热心网友
时间:2023-11-21 12:55
gogogo!
热心网友
时间:2023-11-21 12:55
c, vc
简单
c 参考
http://blog.csdn.net/ecjtuync/archive/2007/04/23/1576478.aspx