Project download
Http://pan.baidu.com/s/1o7OEMc6
Tcddd.rar
This is the TC graphics program running under Windows, and the Easyx library is used;
Easyx Library can be consulted:
http://blog.csdn.net/bcbobo21cn/article/details/51207782
http://www.easyx.cn
Code reference
Http://blog.sina.com.cn/s/articlelist_1287275024_9_1.html
13-dimensional perspective projection transformation algorithm
#include <math.h> #include <graphics.h> #include <conio.h> #include <stdio.h>void draw (float z[ ][4],float xt0,float yt0,float ts0); void matrix (float t[][4]); #define N 22float p[n][4]={{45,30,0,1},{27,30,0,1},{ 27,30,10,1},{18,30,10,1}, {18,30,0,1},{0,30,0,1},{0,30,15,1},{45,30,15,1}, {45,30,0,1},{ 45,0,0,1},{45,0,15,1},{45,15,27,1}, {0,15,27,1},{0,30,15,1},{45,30,15,1},{45,15,27,1}, { 45,10,15,1},{45,10,5,1},{45,20,5,1},{45,20,15,1}, {0,0,15,1},{0,0,0,1}};int tp[]={-1,0,1 , 2,3,4,5,6,7,0,-1,0,7,11,10,9,0,-1,16,17,18,19,16,-1,9,10,20,21,9,-1,10,11,12,20,10,-1,6,7,11,12,6,-1, 5,6,12, 20,21,5,-100};main () {static float tx[4][4]; float b1,b2,h,e,a,l,m,n,k,d,q; int i; Initgraph (640, 480); int Driver,mode; Driver=detect; Initgraph (&driver,&mode, ""); Settextstyle (3,0,_t ("The Song Body")); Settextstyle (0, _t ("Song Body")); SetColor (GREEN); OutTextxy (20,20, "3D Perspective drawing Matrix convert"); for (i=1;i<6;i++) printf ("\ n"); printf ("Input==>ab,bc,h,θ,α:"); /*θ, Alpha Input Method hint: alt+233,alt+224 *///scanf ("%f,%f,%f,%f,%f", &b1,&b2,&h,&e,&a); b1=15; b2=10; h=15; e=233; a=224; e=e*3.14159/180.0; a=a*3.14159/180.0; L=-1* (B2*cos (e)-b1*sin (e))/2; m=-(B2*sin (e) +b1*cos (e)); N=-2*H/3; K=b1*sin (e) +b2*cos (e)-b1*cos (e) *tan (A/2)-b2*sin (e) *tan (A/2); d=k/(2*tan (A/2)); q=-1/d; Tx[0][0]=cos (e); Tx[0][3]=q*sin (e); Tx[1][0]=-sin (e); Tx[1][3]=q*cos (e); tx[2][2]=1;tx[3][0]=1;tx[3][2]=n;tx[3][3] =m*q+1; SetColor (YELLOW); Matrix (tx[0]); Matrix (TX); Getch (); Closegraph ();} void matrix (float t[][4]) {float z[n][4],xt0,yt0,ts0; int i,j,k; for (i=0;i<n;i++) for (j=0;j<4;j++) {z[i][j]=0; for (k=0;k<4;k++) z[i][j]=z[i][j]+p[i][k]*t[k][j]; }//draw (z[0],300,200,z[3][3]);d Raw (z,300,200,z[3][3]);} void Draw (float z[][4],float xt0,float yt0,float ts0) {float x[n],y[n]; int i; for (i=0;i<n;i++) {x[i]=xt0-z[i][0]/z[i][3]*ts0*4; y[i]=yt0-z[i][2]/z[i][3]*ts0*4; } for (i=0;i<1000;i++) {if (tp[i]==-100) break; if (tp[i]==-1) {i++; MoveTo (X[tp[i]],y[tp[i]); } if (tp[i]>=0) LineTo (X[tp[i]],y[tp[i]); }}
Two or three view projection transformation algorithm
#include <math.h> #include <graphics.h> #include <conio.h> #include <stdio.h>void draw (float z[ ][4],float xt0,float yt0,float ts0); void matrix (float t[][4]); #define N 25float p[n][4]={{0,0,5,1},{0,0,0,1},{40,0,0,1 },{40,0,5,1}, {40,25,5,1},{0,25,5,1},{0,25,0,1},{40,25,0,1}, {0,25,0,1},{0,0,0,1},{35,5,5,1},{35,5,35, 1}, {35,10,35,1},{35,10,30,1},{35,15,30,1},{35,20,5,1}, {5,20,5,1},{5,5,5,1},{5,5,35,1},{35,5,35,1}, {35,10,35,1},{5,10,35,1},{5,10,30,1},{5,15,30,1}, {35,15,30,1}};int tp[]={-1,0,1,2,3,0,5,6,1, -1,3,4,5,6,7,2,-1,4,7,-1,10,11,12,13, 14,15,10,-1,17,18,21,22,23,16,17,-1,10,17,-1,11,18,-1,12,21, -1,13,22,-1,1 4,23,-1,15,16,-100};main () {static float tv[4][4],th[4][4],tw[4][4]; int Driver,mode; Driver=detect; Initgraph (&driver,&mode, ""); Initgraph (640, 480); Settextstyle (1,0,_t ("The Song Body")); SetColor (RED); Outtextxy (30,20, "3 Sides View graphic matrix convert");Tv[0][0]=1;tv[2][2]=1;tv[3][3]=1; Th[0][0]=1;th[1][2]=-1;th[3][2]=-10;th[3][3]=1; Tw[1][0]=-1;tw[2][2]=1;tw[3][0]=-10;tw[3][3]=1; SetColor (white); Matrix (tv[0]); Matrix (th[0]); Matrix (tw[0]); Matrix (TV); Matrix (TH); Matrix (TW); Getch (); Closegraph ();} void matrix (float t[][4]) {float z[n][4],xt0,yt0,ts0; int i,j,k; for (i=0;i<n;i++) for (j=0;j<4;j++) {z[i][j]=0; for (k=0;k<4;k++) z[i][j]=z[i][j]+p[i][k]*t[k][j]; }//draw (z[0],310,270,4);d Raw (z,310,270,4);} void Draw (float z[][4],float xt0,float yt0,float ts0) {float x[n],y[n]; int i; for (i=0;i<n;i++) {x[i]=xt0-z[i][0]*ts0; Y[I]=YT0-Z[I][2]*TS0; } for (i=0;i<1000;i++) {if (tp[i]==-100) break; if (tp[i]==-1) {i++; MoveTo (X[tp[i]],y[tp[i]); } if (tp[i]>=0) LineTo (X[tp[i]],y[tp[i]); } }
33-D Projection transformation algorithm for positive axis measurement
#include <math.h> #include <graphics.h> #include <conio.h> #include <stdio.h>void draw (float z[ ][4],float xt0,float yt0,float ts0); void matrix (float t[][4]); #define N 18float p[n][4]={{0,0,0,1},{0,40,0,1},{ 45,40,0,1},{45,0,0,1}, {45,0,8,1},{45,40,8,1},{8,40,8,1},{8,0,8,1}, {8,0,28,1},{8,40,28,1} , {0,40,28,1},{0,0,28,1}, {40,24,8,1},{8,24,8,1},{8,24,24,1},{8,16,24,1}, {8,16,8,1},{40,16 , 8,1}};int TP []={-1,0,1,2,3,0,5,6,1,-1,3,4,5,6,7,2,-1,4,7,-1,10,11,12,13,14,15,10,-1,17,18,21,22,23,16,1 7,-1,10,17,-1,11,18,-1,12,21,-1,13,22,-1,14,23,-1,15,16,-100};main () {static float tx[4][4]; float Beta,cita; int Driver,mode; Driver=detect; Initgraph (&driver,&mode, ""); Initgraph (640, 480); Settextstyle (1,0,_t ("The Song Body")); Settextstyle (0, _t ("Song Body")); SetColor (BROWN); Outtextxy (140,20, "3D graphic matrix convert"); printf ("input==>β,θ:"); The input methods for/*β and θ are: alt+225, Alt +233*/ scanf ("%f,%f", &beta,&cita); beta=225; cita=233; beta=beta*3.14159/180.0; cita=cita*3.14159/180.0; Tx[0][0]=cos (Beta), Tx[0][2]=-sin (Beta) *sin (CITA); Tx[1][0]=-sin (beta); Tx[1][2]=-cos (Beta) *sin (CITA); Tx[2][2]=cos (CITA); tx[3][3]=1; SetColor (CYAN); Matrix (tx[0]); Matrix (TX); Getch (); Closegraph ();} void matrix (float t[][4]) {float z[n][4],xt0,yt0,ts0; int i,j,k; for (i=0;i<n;i++) for (j=0;j<4;j++) {z[i][j]=0; for (k=0;k<4;k++) z[i][j]=z[i][j]+p[i][k]*t[k][j]; }//draw (z[0],300,200,4);d Raw (z,300,200,4);} void Draw (float z[][4],float xt0,float yt0,float ts0) {float x[n],y[n]; int i; for (i=0;i<n;i++) {x[i]=xt0-z[i][0]*ts0; Y[I]=YT0-Z[I][2]*TS0; } for (i=0;i<1000;i++) {if (tp[i]==-100) break; if (tp[i]==-1) {i++; MoveTo (X[tp[i]],y[tp[i]); } if (tp[i]>=0) LineTo (X[tp[i]],y[tp[i]); }}
Four related programming problems 12-dimensional arrays do function parameters
The above three programs use a two-dimensional array to do function parameters; Look at a two-dimensional array to do the function parameter example;
#include <stdio.h> void print_array (int *array, int len) { int i = 0; for (; i < Len; i++) { printf ("%d", Array[i]); } Putchar (' \ n '); } void func (int array[3][10]) { Print_array (array[0], ten); Print_array (Array[1], ten); Print_array (Array[2], ten); Print_array (Array[3], ten); Print_array (Array[4], 10); } int Main () { int array[5][10] = { {0,1,2,3,4,5,6,7,8,9}, {10,11,12,13,14,15,16,17,18,19}, {20,21,22,23,24,25,26,27,28,29}, {30,31,32,33,34,35,36,37,38,39}, {40,41,42,43,44,45,46,47,48,49} }; Func (array); return 0; }
Improvement of TC function in 2 Easyx library
Settextstyle (1,0,4);
Need to change
Settextstyle (0, _t ("Song Body"));
and other improvements, see
Easyx Help Manuals and
http://www.easyx.cn/skills/View.aspx?id=89
Graphic computer graphics three-dimensional transformation algorithm