中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net  论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

游客:  注册 | 登录 | 命令行 | 会员 | 搜索 | 上传 | 帮助 »
« [1] [2] [3] [4] [5] »
作者:
标题: 一个c语言图形库和数学库 上一主题 | 下一主题
leafmaple
新手上路





积分 4
发帖 2
注册 2010-11-18
状态 离线
『第 61 楼』:  

谢谢分享......

2010-12-21 08:18
查看资料  发短消息 网志   编辑帖子  回复  引用回复
svols
新手上路





积分 2
发帖 1
注册 2010-12-29
状态 离线
『第 62 楼』:  

学习了,多谢lz啊

2010-12-30 18:56
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
angussx
新手上路





积分 2
发帖 1
注册 2010-11-28
状态 离线
『第 63 楼』:  

支持一下了

2011-1-24 12:13
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
qingwashaoye
中级用户




积分 271
发帖 74
注册 2004-11-17
状态 离线
『第 64 楼』:  

顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶
顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶          顶顶
顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶                顶顶
顶顶顶顶顶顶顶顶顶顶    顶顶          顶顶顶顶顶顶顶
顶顶顶顶顶顶        顶顶  顶顶顶    顶顶顶顶顶顶顶顶
顶             顶顶顶顶顶顶顶   顶顶顶顶顶顶顶顶顶
顶           顶顶顶顶顶顶顶顶         顶顶顶顶
顶顶         顶顶顶顶顶顶顶顶            顶顶
顶顶顶 顶顶顶    顶顶顶顶顶顶    顶顶顶顶顶     顶顶
顶顶顶顶顶顶顶顶   顶顶顶顶顶顶  顶顶顶 顶顶顶顶   顶顶顶
顶顶顶顶顶顶顶顶   顶顶顶顶顶   顶顶顶  顶顶顶   顶顶顶
顶顶顶顶顶顶顶顶   顶顶顶顶顶   顶顶顶  顶顶顶   顶顶顶
顶顶顶顶顶顶顶顶   顶顶顶顶顶   顶顶   顶顶顶   顶顶顶
顶顶顶顶顶顶顶顶   顶顶顶顶顶   顶顶   顶顶顶   顶顶顶
顶顶顶顶顶顶顶顶   顶顶顶顶顶   顶顶   顶顶顶   顶顶顶
顶顶顶顶顶顶顶顶   顶顶顶顶顶   顶顶   顶顶顶   顶顶顶
顶顶顶顶顶顶顶顶   顶顶顶顶顶  顶顶顶  顶顶顶顶   顶顶顶
顶顶顶顶顶顶顶顶   顶顶顶顶顶  顶顶顶  顶顶顶顶   顶顶顶
顶顶顶        顶顶顶顶顶顶 顶顶  顶顶顶顶    顶顶顶
顶顶顶顶       顶顶顶顶顶顶顶顶顶  顶顶 顶顶顶  顶顶顶
顶顶顶顶顶顶     顶顶顶顶顶顶顶顶   顶顶    顶顶顶顶顶
顶顶顶顶顶顶顶顶   顶顶顶顶顶顶顶    顶顶顶      顶顶
顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶     顶顶顶顶顶      顶
顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶    顶顶顶顶顶顶顶顶     顶
顶顶顶顶顶顶顶顶顶顶顶顶顶     顶顶顶顶顶顶顶顶顶顶    顶
顶顶顶顶顶顶顶顶顶顶顶顶  顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶  顶顶
顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶

2017-2-1 01:08
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
fsyzwuli
新手上路





积分 16
发帖 8
注册 2017-11-23
状态 离线
『第 65 楼』:  

资料这么齐全!强啊!!!

2017-12-6 08:53
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
zzz19760225
超级版主




积分 3673
发帖 2020
注册 2016-2-1
状态 离线
『第 66 楼』:  楼主文件铺开

数学与图形库
|
|---MATH.INC
|---MYGRAPH.INC
|---MYHEAD.H
|---readme.txt
|
|---3ddemo.rar
        |----3DDEMO.C
        |----3DDEMO.exe
        |----3DDEMO2.C
        |----3DDEMO2.exe
        |----3DDEMO3.C
        |----3DDEMO3.exe
---------------------------------------------------------------------------------------------------
|---MATH.INC

/*Math.Inc   BY BIANMING 2004-11-24
/*  by   边明明,西安邮电学院。*/
/*这个是俺自己写的一个c语言数学库,在tc2.0下测试通过。请大家放心使用O_o!

  特别加入了三维向量的运算TDA,用于图形库中的画向量。


Radians   -  converts degrees to radians
Degrees   -  converts radians to degrees
CosD      -  cosine in degrees
SinD      -  sine   in degrees
Power     -  power a^n
Log       -  log base 10
Exp10     -  exp base 10
Sign      -  negative=-1   positive=1   null=0
IntSign   -  negative=-1   positive=1   null=0
IntSqrt   -  integer aquare root
IntPower  -  integer power a^n
*/

#define Ln10          2.30258509299405E+000
#define Pi            3.1415927
#define PiOver180     1.74532925199433E-002
#define PiUnder180    5.72957795130823E+001

typedef enum {false, true} Boolean;
typedef unsigned char      Byte;
typedef unsigned int       Word;

int Round(float x)
   {
    return((int)(x+0.5));
   }

int Trunc(float x)
   {
    return((int)(x));
   }

float SqrFP(float x)
   {
    return(x*x);
   }

int Sqr(int x)
   {
    return(x*x);
   }

float Radians(float Angle)
   {
    return(Angle*PiOver180);
   }

float Degrees(float Angle)
   {
    return(Angle*PiUnder180);
   }

float CosD(float Angle)
   {
    return(cos(Radians(Angle)));
   }

float SinD(float Angle)
   {
    return(sin(Radians(Angle)));
   }

float Power(float Base,int E)
   {
    float BPower;
    int   t;

    if(E==0) return(1);
    else
      {
       BPower=1.0;
       for(t=1;t<=E;t++)
          BPower*=Base;
       return(BPower);
      }
   }

float Log(float x)
   {
    return(log(x)/Ln10);
   }

float Exp10(float x)
   {
    return(exp(x*Ln10));
   }

float Sign(float x)
   {
    if(x<0) return(-1);
    if(x>0) return(1);
    else    return(0);
   }

int IntSign(int x)
   {
    if(x<0) return(-1);
    if(x>0) return(1);
    else    return(0);
   }

int IntSqrt(int x)
   {
    int OddInt,OldArg,FirstSqrt;

    OddInt=1;
    OldArg=x;
    while(x>=0)
       {
        x-=OddInt;
        OddInt+=2;
       }
    FirstSqrt=OddInt >> 1;
    if(Sqr(FirstSqrt)-FirstSqrt+1 > OldArg)
      return(FirstSqrt-1);
    else
      return(FirstSqrt);
   }

int IntPower(int Base,int E)
   {
    int BPower;
    int   t;

    if(E==0) return(1);
    else
      {
       BPower=1;
       for(t=1;t<=E;t++)
          BPower*=Base;
       return(BPower);
      }
   }

/*三维向量操作
vec           -   Make Vector三参数生成一实数向量
VecInt        -   Make Integer Vector三参数生成一整数向量
UnVec         -   Get Components of Vector实向量x,y,z轴传给三个数
UnVecInt      -   Get Components of Integer Vector整向量x,y,z轴传给三个数
VecDot        -   Vector Dot Product两向量的点乘积
VecCross      -   Vector Cross Product向量叉乘积
VecLen        -   Vector length向量长度
VecNormalize  -   Vector Normalize 规格化向量,0长度向量不能规格化
VecMatxMult   -   Vector Matrix Multiple 一个4×4矩阵于一向量乘积
VecSub        -   Vector Subtraction俩向量的差赋值给另一向量
VecSubInt     -   Vector Subtraction Integer整数向量差赋值
VecAdd        -   Vector Addition俩向量和赋值给另一向量
VecAdd3       -   Vector Addition仨向量和赋值给另一向量
VecCopy       -   Vector Copy向量拷贝
VecLinComb    -   Vector Linear Combination  C=R*A+S*B
VecScalMult   -   Vector Scalar Multiple实向量与实数乘积
VecScalMultI  -   Vector Scalar Multiple整向量与实数乘积
VecScalMultInt-   Vector Scalar Multiple and Rounding整向量与整数乘积
VecAddScalMult-   Vector Add scalar Multiple  C=R*A+B
VecNull       -   Vector Null  实向量置零
VecNullInt    -   Vector Null Integer整向量置零
VecElemMult   -   Vector Element Mulitiple C=R*A*B
*/

typedef float TDA[3];
typedef int   TDIA[3];
typedef float FDA[4];
typedef float Matx4x4[4][4];

void Vec(float r,float s,float t,TDA a)
    {
     a[0]=r;a[1]=s;a[2]=t;
    }

void VecInt(int r,int s,int t,TDIA a)
    {
     a[0]=r;a[1]=s;a[2]=t;
    }

void UnVec(TDA a,float *r,float *s,float *t)
    {
     *r=a[0];*s=a[1];*t=a[2];
    }

void UnVecInt(TDIA a,int *r,int *s,int *t)
    {
     *r=a[0];*s=a[1];*t=a[2];
    }

float VecDot(TDA a,TDA b)
    {
     return(a[0]*b[0]+a[1]*b[1]+a[2]*b[2]);
    }

void VecCross(TDA a,TDA b,TDA c)
    {
     c[0]=a[1]*b[2]-a[2]*b[1];
     c[1]=a[2]*b[0]-a[0]*b[2];
     c[2]=a[0]*b[1]-a[1]*b[0];
    }

float VecLen(TDA a)
    {
     return(sqrt(SqrFP(a[0])+SqrFP(a[1])+SqrFP(a[2])));
    }

void VecNormalize(TDA a)
    {
     float dist,invdist;

     dist=VecLen(a);
     if(!(dist==0.0))
       {
        invdist=1.0/dist;
        a[0]*=invdist;
        a[1]*=invdist;
        a[2]*=invdist;
       }
     else
       {
        puts("Zero-Length Vectors Cannot be Nomalized!!!");
        exit(1);
       }
    }

void VecMatxMult(FDA a,Matx4x4 Matrix,FDA b)
    {
     int mrow, mcol;

     for(mcol=0;mcol<4;mcol++)
        {
         b[mcol]=0;
         for(mrow=0;mrow<4;mrow++)
         b[mcol]+=a[mrow]*Matrix[mrow][mcol];
        }
    }

void VecSub(TDA a,TDA b,TDA c)
    {
     c[0]=a[0]-b[0];
     c[1]=a[1]-b[1];
     c[2]=a[2]-b[2];
    }

void VecSubInt(TDIA a,TDIA b,TDIA c)
    {
     c[0]=a[0]-b[0];
     c[1]=a[1]-b[1];
     c[2]=a[2]-b[2];
    }

void VecAdd(TDA a,TDA b,TDA c)
    {
     c[0]=a[0]+b[0];
     c[1]=a[1]+b[1];
     c[2]=a[2]+b[2];
    }

void VecAdd3(TDA a,TDA b,TDA c,TDA d)
    {
     d[0]=a[0]+b[0]+c[0];
     d[1]=a[1]+b[1]+c[1];
     d[2]=a[2]+b[2]+c[2];
    }

void VecCopy(TDA a,TDA b)
    {
     b[0]=a[0];
     b[1]=a[1];
     b[2]=a[2];
    }

void VecLinComb(float r,TDA a,float s,TDA b,TDA c)
    {
     c[0]=r*a[0]+s*b[0];
     c[1]=r*a[1]+s*b[1];
     c[2]=r*a[2]+s*b[2];
    }

void VecScalMult(float r,TDA a,TDA b)
    {
     b[0]=r*a[0];
     b[1]=r*a[1];
     b[2]=r*a[2];
    }

void VecScalMultI(float r,TDIA a,TDA b)
    {
     b[0]=r*a[0];
     b[1]=r*a[1];
     b[2]=r*a[2];
    }

void VecScalMultInt(float r,TDA a,TDIA b)
    {
     b[0]=Round(r*a[0]);
     b[1]=Round(r*a[1]);
     b[2]=Round(r*a[2]);
    }

void VecAddScalMult(float r,TDA a,TDA b,TDA c)
    {
     c[0]=r*a[0]+b[0];
     c[1]=r*a[1]+b[1];
     c[2]=r*a[2]+b[2];
    }

void VecNull(TDA a)
    {
     a[0]=0.0;
     a[1]=0.0;
     a[2]=0.0;
    }

void VecNullInt(TDIA a)
    {
     a[0]=0;
     a[1]=0;
     a[2]=0;
    }

void VecElemMult(float r, TDA a,TDA b,TDA c)
    {
     c[0]=r*a[0]*b[0];
     c[1]=r*a[1]*b[1];
     c[2]=r*a[2]*b[2];
    }

/*
ZeroMatrix            -   zeros the elements of a 4x4 matrix
Translate3D           -   make translation matrix把一向量线性转换道空间的新位置生成新矩阵
Scale3D               -   make Scaling matrix使一向量转换成矩阵
Rotate3D              -   make rotation matrix使一向量旋转生成一矩阵
ZeroAllMatricies      -   zeros all matricies used in tranformation
Multiply3DMatricies   -   multiply 2 4x4 matricies矩阵相乘
PrepareMatrix         -   prepare the transformation matrix (Tm=S*R*T)生成一个完整的仿射变换矩阵
PrepareInvMatrix      -   prepare the inverse transformation matrix
Transform             -   multiply a vertex by the transformation matrix 向量与矩阵相乘生成新向量
*/

void ZeroMatrix(Matx4x4 a)
    {
     int i,j;

     for(i=0;i<4;i++)
        for(j=0;j<4;j++)
           a[j]=0.0;
    }

void Translate3D(float tx, float ty, float tz,Matx4x4 a)
    {
     int i;

     ZeroMatrix(a);
     for(i=0;i<4;i++)
        a=1.0;
     a[0][3]=-tx;
     a[1][3]=-ty;
     a[2][3]=-tz;
    }

void Scale3D(float sx,float sy,float sz,Matx4x4 a)
    {
     ZeroMatrix(a);
     a[0][0]=sx;
     a[1][1]=sy;
     a[2][2]=sz;
     a[3][3]=1.0;
    }

void Rotate3D(int m,float theta, Matx4x4 a)
    {
     int m1,m2;
     float c,s;

     ZeroMatrix(a);
     a[m-1][m-1]=1.0;
     a[3][3]=1.0;
     m1=(m%3)+1;
     m2=(m1%3);
     m1=-1;
     c=CosD(theta);
     s=SinD(theta);
     a[m1][m1]=c;
     a[m1][m2]=s;
     a[m2][m2]=c;
     a[m2][m1]=-s;
    }

void Multiply3DMatricies(Matx4x4 a,Matx4x4 b,Matx4x4 c)
    {
     int i,j,k;
     float ab;

     for(i=0;i<4;i++)
        {
         for(j=0;j<4;j++)
            {
             ab=0;
             for(k=0;k<4;k++)
                ab+=a[k]*b[k][j];
             c[j]=ab;
            }
        }
    }

void MatCopy(Matx4x4 a,Matx4x4 b)
    {
     int i,j;

     for(i=0;i<4;i++)
        for(j=0;j<4;j++)
           b[j]=a[j];
    }

void PrepareMatrix(float tx,float ty,float tz,
                   float sx,float sy,float sz,
                   float rx,float ry,float rz,
                   Matx4x4 XForm)
    {
     Matx4x4 m1,m2,m3,m4,m5,m6,m7,m8,m9;

     Scale3D(sx,sy,sz,m1);
     Rotate3D(1,rx,m2);
     Rotate3D(2,ry,m3);
     Rotate3D(3,rz,m4);
     Translate3D(tx,ty,tz,m5);
     Multiply3DMatricies(m2,m1,m6);
     Multiply3DMatricies(m3,m6,m7);
     Multiply3DMatricies(m4,m7,m8);
     Multiply3DMatricies(m5,m8,m9);
     MatCopy(m9,XForm);
    }

void PrepareInvMatrix(float tx,float ty,float tz,
                      float sx,float sy,float sz,
                      float rx,float ry,float rz,
                      Matx4x4 XForm)
    {
     Matx4x4 m1,m2,m3,m4,m5,m6,m7,m8,m9;

     Scale3D(sx,sy,sz,m1);
     Rotate3D(1,rx,m2);
     Rotate3D(2,ry,m3);
     Rotate3D(3,rz,m4);
     Translate3D(tx,ty,tz,m5);
     Multiply3DMatricies(m4,m5,m6);
     Multiply3DMatricies(m3,m6,m7);
     Multiply3DMatricies(m2,m7,m8);
     Multiply3DMatricies(m1,m8,m9);
     MatCopy(m9,XForm);
    }

void Transform(TDA a,Matx4x4 m,TDA b)
    {
     b[0]=m[0][0]*a[0]+m[0][1]*a[1]+m[0][2]*a[2]+m[0][3];
     b[1]=m[1][0]*a[0]+m[1][1]*a[1]+m[1][2]*a[2]+m[1][3];
     b[0]=m[2][0]*a[0]+m[2][1]*a[1]+m[2][2]*a[2]+m[2][3];
    }

---------------------------------------------------------------------------------------------------
|---MYGRAPH.INC

/*MYGraph.Inc  BY BIANMING 2005-11-27
InitGraphics     -   initialize graphics
                 -   屏幕初始化,指明图形驱动路径 gpath
ExitGraphics     -   sound and wait for key press before exiting grapgics
                 -   生成图型后的调用
SetAxisZP        -   设置图形原点座标,默认下以(0,439)为原点
SetAxisMid       -   设置图形原点座标为屏幕中央
Plot             -   place pixel to screen
CylPlot          -   极坐标画点法
GetPixel         -   gets  pixel
                 -   从指定点返回颜色
Circle           -   circle draw routine
                 -   画给定圆心,半径,颜色的圆
Line             -   line draw routine
                 -   从给定点到另一点给定颜色的线
ShowAxis         -   显示2D坐标轴 ,set X-Axis color,set Y-Axis color.
Title            -   set up text screen colors
                 -   为以文本方式输出准备屏幕
*/


int CentreX ,CentreY;    /* 原点坐标*/
int MaxX; /*getmaxx*/
int MaxY; /*getmaxy*/
int MaxXres;
int MaxYres;
int MaxColor;  /*最大颜色种数*/


void InitGraphics(char *gpath)
    {
     int gd=DETECT,gm;
     initgraph(&gd,&gm,gpath);
     MaxX=getmaxx(); /*getmaxx*/
     MaxY=getmaxy(); /*getmaxy*/
     MaxXres=MaxX+1;
     MaxYres=MaxY+1;
     MaxColor=getmaxcolor();
     CentreX=0;
     CentreY=MaxY;
    }

void ExitGraphics(void)
    {
     sound(1000);
     delay(500);
     nosound();
     getch();
     cleardevice();
     closegraph();
    }

void SetAxisZP(int x,int y)  /* 设置图形原点座标,默认下以(0,439)为原点*/
    {
     CentreX=x;
     CentreY=y;
    }

void SetAxisMid(void)  /*设置图形原点座标为屏幕中央*/
    {
     int x,y;
     x=MaxX>>1;
     y=MaxY>>1;
     SetAxisZP(x,y);
    }

void Plot(int x,int y,unsigned char color)
    {
     int ScreenX,ScreenY;
     ScreenX=x+CentreX;
     ScreenY=MaxY-(y+CentreY);
     if((ScreenX>=0)&&(ScreenX<=MaxX)&&(ScreenY>=0)&&(ScreenY<=MaxY))
       putpixel(ScreenX,ScreenY,color);
    }
void CylPlot(float R,float Theta,Byte color)
    {
     int x,y;

     Theta=Radians(Theta);
     x=(int)(R*sin(Theta));
     y=(int)(R*cos(Theta));
     Plot(x,y,color);
    }

int GetPixel(int x,int y)
    {
     int ScreenX,ScreenY;
     ScreenX=x+CentreX;
     ScreenY=MaxY-(y+CentreY);
     if((ScreenX>=0)&&(ScreenX<=MaxX)&&(ScreenY>=0)&&(ScreenY<=MaxY))
        return(getpixel(ScreenX,ScreenY));
     else
        return(0);
    }

void Swap(int *first,int *second)
    {
     int tmp;

     tmp=*first;
     *first=*second;
     *second=tmp;
    }

void Circle(int x,int y,int radius, Byte color)  /*600×480  16 color*/
    {
     int a,af,b,bf,target,r2,asp;

     asp=94;

     target=0;
     a=radius;
     b=0;
     r2=Sqr(radius);
     while(a>=b)
        {
         b=Round(sqrt(r2-Sqr(a)));
         Swap(&target,&b);
         while(b<target)
            {
             af=(asp*a)/100;
             bf=(asp*b)/100;
             Plot(x+af,y+b,color);
             Plot(x+bf,y+a,color);
             Plot(x-af,y+b,color);
             Plot(x-bf,y+a,color);
             Plot(x-af,y-b,color);
             Plot(x-bf,y-a,color);
             Plot(x+af,y-b,color);
             Plot(x+bf,y-a,color);
             ++b;
            }
         --a;
        }
    }

void Line(int xx1,int yy1,int xx2,int yy2,Byte color)
    {
     int LgDelta,ShDelta,Cycle,LgStep,ShStep;

     LgDelta=xx2-xx1;
     ShDelta=yy2-yy1;
     if(LgDelta<0)
       {
        LgDelta=-LgDelta;
        LgStep=-1;
       }
     else
        LgStep=1;
     if(ShDelta<0)
       {
        ShDelta=-ShDelta;
        ShStep=-1;
       }
     else
        ShStep=1;
     if(ShDelta<LgDelta)
       {
        Cycle=LgDelta>>1;
        while(xx1!=xx2)
           {
            Plot(xx1,yy1,color);
            Cycle+=ShDelta;
            if(Cycle>LgDelta)
              {
               Cycle-=LgDelta;
               yy1+=ShStep;
              }
            xx1+=LgStep;
           }
        Plot(xx1,yy1,color);
       }
     else
       {
        Cycle=ShDelta>>1;
        Swap(&LgDelta,&ShDelta);
        Swap(&LgStep,&ShStep);
        while(yy1!=yy2)
           {
            Plot(xx1,yy1,color);
            Cycle+=ShDelta;
            if(Cycle>LgDelta)
              {
               Cycle-=LgDelta;
               xx1+=ShStep;
              }
            yy1+=LgStep;
           }
        Plot(xx1,yy1,color);
       }
    }


void ShowAxis(Byte xcolor,Byte ycolor)
    {
     Line(-200,0,200,0,xcolor);
     Line(190,7,200,0,xcolor);
     Line(190,-7,200,0,xcolor);/*x轴*/
     Line(0,-200,0,200,ycolor);
     Line(7,190,0,200,ycolor);
     Line(-7,190,0,200,ycolor);/*y轴*/
    }


void Title()
    {
     textcolor(YELLOW);
     textbackground(BLUE);
     clrscr();
    }

/*FOR 3D GRAPHICS
InitPer            -   observer location and distances
                   -   给三维空间的观察者坐标赋值 Per控制是否是透视图 true-是 false-不是
InitPlotting       -   rotation and tilt angles
                   -   初始化用于三维图形中的变量
MapCoordinates     -   maps 3D space onto the 2D screen
                   -   将三维点投影到观察平面
Plot3D             -   plot a cartesian system point
                   -   在二维屏幕上画给定三维坐标和颜色的点
CylPlot3D          -   plot a Cylindrical system point
                   -   在二维屏幕上画给定半径,与xy平面角度,z高度和颜色的点 以Cylindrical坐标系统给出
SphPlot3D          -   plot a spherical system point
                   -   在二维屏幕上画以球形坐标r半径,Theta xy平面半径线的角度,Phi xz平面半径线的角度
                   -   的点
VecLine3D          -   plots a line from 3D coordinates
                   -   画以向量参数1为起点,向量参数2为终点,color为颜色的3D直线
Line3D             -   画(x1,y1,z1)-(x2,y2,z2)的直线
Vec3D              -  画向量
Ball               -  画一个球体 (x,y,z)球心坐标,R半径,color颜色
*/

Boolean PerspectivePlot;
float   Mx,My,Mz,ds;  /*观察者坐标(Mx,My,Mz),距离(ds)赋值*/

void InitPer(Boolean Per,float x,float y,float z,float m)
    {
     PerspectivePlot=Per;
     Mx=x;
     My=y;
     Mz=z;
     ds=m;
    }

float Angl    ,Tilt;       /* 观察者的旋转角,俯视角*/
float CosA    ,SinA;
float CosB    ,SinB;
float CosACosB,SinASinB;
float CosASinB,SinACosB;

void InitPlotting(float Ang,float Tlt)
    {
     Angl    =Ang;
     Tilt    =Tlt;
     CosA    =CosD(Angl);
     SinA    =SinD(Angl);
     CosB    =CosD(Tilt);
     SinB    =SinD(Tilt);
     CosACosB=CosA*CosB;
     SinASinB=SinA*SinB;
     CosASinB=CosA*SinB;
     SinACosB=SinA*CosB;
    }
                  
void MapCoordinates(float x,float y,float z,int *Xp,int *Yp)
    {
     float Xt,Yt,Zt;

     Xt=(Mx+x*CosA-y*SinA);
     Yt=(My+x*SinASinB+y*CosASinB+z*CosB);
     if(PerspectivePlot)
       {
        Zt=Mz+x*SinACosB+y*CosACosB-z*SinB;
        *Xp=Round(ds*Xt/Zt);
        *Yp=Round(ds*Yt/Zt);
       }
     else
       {
        *Xp=Round(Xt);
        *Yp=Round(Yt);
       }
    }

void Plot3D(float x,float y,float z,Byte Color)
    {
     int Xp,Yp;
     MapCoordinates(x,y,z,&Xp,&Yp);
     Plot(Xp,Yp,Color);
    }

void CylPlot3D(float Rho,float Theta,float z,Byte Color)
    {
     float x,y;

     Theta=Radians(Theta);
     x=Rho*cos(Theta);
     y=Rho*sin(Theta);
     Plot3D(x,y,z,Color);
    }

void SphPlot3D(float r,float Theta,float Phi,Byte Color)
    {
     float x,y,z;

     Theta=Radians(Theta);
     Phi=Radians(Phi);
     x=r*sin(Theta)*cos(Phi);
     y=r*sin(Theta)*sin(Phi);
     z=r*cos(Theta);
     Plot3D(x,y,z,Color);
    }

void VecLine3D(TDA P1,TDA P2,Byte Color)/*向量画3D直线*/
    {
     int   Xp1,Yp1;
     int   Xp2,Yp2;
     float x1,y1,z1;
     float x2,y2,z2;

     UnVec(P1,&x1,&y1,&z1);
     UnVec(P2,&x2,&y2,&z2);
     MapCoordinates(x1,y1,z1,&Xp1,&Yp1);
     MapCoordinates(x2,y2,z2,&Xp2,&Yp2);
     Line(Xp1,Yp1,Xp2,Yp2,Color);
    }

void Line3D(float x1,float y1,float z1,float x2,float y2,float z2,int Color)
    {
     int   Xp1,Yp1;
     int   Xp2,Yp2;
     MapCoordinates(x1,y1,z1,&Xp1,&Yp1);
     MapCoordinates(x2,y2,z2,&Xp2,&Yp2);
     Line(Xp1,Yp1,Xp2,Yp2,Color);     
    }

void Vec3D(TDA P1,int Color)  /*画P1向量*/
    {
     int   Xp1,Yp1;
     float x1,y1,z1;
     UnVec(P1,&x1,&y1,&z1);
     MapCoordinates(x1,y1,z1,&Xp1,&Yp1);
     Line(0,0,Xp1,Yp1,Color);
    }

void Ball(int x,int y,int z,int R,Byte color)  /*画一个球体 (x,y,z)球心坐标,R半径,color颜色*/
    {
     int Theta,Phi;
     for(Theta=0;Theta<180;Theta+=20)
        {
         for(Phi=0;Phi<180;Phi++)
           {
            Plot3D(x+R*CosD(Phi)*CosD(Theta),y+R*CosD(Phi)*SinD(Theta),z+R*SinD(Phi),color);
            Plot3D(x+R*CosD(Phi)*CosD(Theta),y+R*CosD(Phi)*SinD(Theta),z-R*SinD(Phi),color);
           }
        }
     for(Phi=-80;Phi<90;Phi+=20)
        {
         for(Theta=0;Theta<180;Theta++)
           {
            Plot3D(x+R*CosD(Phi)*CosD(Theta),y+R*CosD(Phi)*SinD(Theta),z+R*SinD(Phi),color);
            Plot3D(x+R*CosD(Phi)*CosD(Theta),y-R*CosD(Phi)*SinD(Theta),z+R*SinD(Phi),color);
           }
        }
    Plot3D(x,y,z,color+2);
    }

/*
GetPixel3D-  gets 3D pixel
          -  从指定3D点返回颜色

COLORS:
     BLACK     0 黑色 DARKGRAY      8 深灰
     BLUE      1 兰色 LIGHTBLUE     9 深兰
     GREEN     2 绿色 LIGHTGREEN   10 淡绿
     CYAN      3 青色 LIGHTCYAN    11 淡青
     RED       4 红色 LIGHTRED     12 淡红
     MAGENTA   5 洋红 LIGHTMAGENTA 13 淡洋红
     BROWN     6 棕色 YELLOW       14 黄色
     LIGHTGRAY 7 淡灰 WHITE        15 白色

*/


int GetPixel3D(int x,int y,int z)
   {
    int xp,yp;
    MapCoordinates(x,y,z,&xp,&yp);
    return(GetPixel(xp,yp));
   }


/* Set up of Coordinate Axes and color Palette

ShowAxis3D   -  显示3D坐标轴 And Set Axis color
                  
ShowPalette  -  在屏幕上画出调色板
*/


void ShowAxis3D(Byte xcolor,Byte ycolor,Byte zcolor)
    {
     int x,y,z;
     
     Line3D(-200, 0,0,200,0,0,xcolor);
     Line3D(190,-7,0,200,0,0,xcolor);
     Line3D(190, 7,0,200,0,0,xcolor); /*x-Axis*/
     Line3D( 0,-200,0,0,200,0,ycolor);
     Line3D(-7,190,0,0,200,0,ycolor);
     Line3D( 7,190,0,0,200,0,ycolor); /*y-Axis*/
     Line3D(0 ,0,-200,0,0,200,zcolor);
     Line3D(0,-7,190,0,0,200,zcolor);
     Line3D(0, 7,190,0,0,200,zcolor); /*z-Axis*/     
          
    }

void ShowPalette(void)
    {
     int  y;
     Byte Color;
     for(Color=1;Color<MaxColor;Color++)
        {       
             for(y=0;y<15;y++)
                 Line(-300,y+15*Color,-290,y+15*Color,Color);
        }
    }


---------------------------------------------------------------------------------------------------
|---MYHEAD.H

#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include <math.h>
#include <graphics.h>
#include "math.inc"
#include "mygraph.inc"

---------------------------------------------------------------------------------------------------
|---readme.txt

/*  by   边明明,西安邮电学院。*/
/*这个是俺自己写的一个c语言图形库和数学库,在tc2.0下测试通过。请大家放心使用O_o!

  所有函数是相对于调整的坐标原点进行画图的,不是以屏幕原点坐标,这一点请大家注意!!!

  特点是所有作图函数加入了颜色设置,
  特别加入了3D作图,3D作图时要初始化观察者的坐标和距离(InitPer())。
  还要初始化观察者相对与x轴旋转角,相对与xy平面的俯视角(InitPoltting())。
  因为所有的3D作图函数都是相对于这个初始值进行作图的。
  

  注意:在包含这个库时还要包含进stdio.h,dos.h,conio.h,math.h,graphics.h,math.inc这些库。
        这里也可以一个include "myhead.h"。这个文件在压缩包里。

  您可以在这个基础上继续建立自己的库。您也可以进行任意修改。O_o!

  这里有几个例子:3Ddemo.c,3Ddemo2.c,3Ddemo3.c。




                                     bmmm906@sohu.com
                                     qq:53793208
                                     西安邮电学院南校区 电科0303班  75号信箱。

---------------------------------------------------------------------------------------------------

[ Last edited by zzz19760225 on 2017-12-6 at 15:57 ]



1<词>,2[句],3/段\,4{节},5(章)。
2017-12-6 15:42
查看资料  发短消息 网志   编辑帖子  回复  引用回复
zzz19760225
超级版主




积分 3673
发帖 2020
注册 2016-2-1
状态 离线
『第 67 楼』:  楼主文件再铺开

3ddemo.rar
|----3DDEMO.C
|----3DDEMO.exe
|----3DDEMO2.C
|----3DDEMO2.exe
|----3DDEMO3.C
|----3DDEMO3.exe
---------------------------------------------------------------------------------------------------
|----3DDEMO.C

#include "c:\tc\cexe\myhead.h"
#define LEFT   0x4b00
#define RIGHT  0x4d00
#define UP     0x4800
#define DOWN   0x5000
#define ESC    0x011b

void ShowXYM(void);
void PWM(void);


void main(void)
    {
     int Theta=240,Phi=12;
     int key;

      InitGraphics("c:\\tc\\tc2\\bgi");
      SetAxisMid();
     while(!(kbhit()))
     {
      InitPer(0,0,0,500,50);/*3D Init*/
      Theta%=360;
      Phi  %= 90;
      InitPlotting(Theta,Phi);

      ShowPalette();

      ShowXYM();
      ShowAxis3D(BLUE,GREEN,CYAN);


      PWM();
      key=bioskey(0);
      if(key==LEFT)  Theta+=5;
      if(key==RIGHT) Theta-=5;
      if(key==UP)    Phi  +=2;
      if(key==DOWN)  Phi  -=2;
      if(key==ESC)   ExitGraphics();
      cleardevice();
     }
    }

void ShowXYM(void)
    {
     int x,y;

     for(x=-300;x<=300;x+=40)
        Line3D(x,-300,0,x,300,0,5);
     for(y=-300;y<=300;y+=40)
        Line3D(-300,y,0,300,y,0,5);
    }

void PWM(void)
    {
     long x,y,z;
     for(x=-200;x<=200;x+=20)
     for(y=-200;y<=200;y++)
        {
         z=Round(sqrt(x*x+y*y)/2);
         Plot3D(x,y,z,2);
        }
     for(y=-200;y<=200;y+=20)
     for(x=-200;x<=200;x++)
        {
         z=Round(sqrt(x*x+y*y)/2);
         Plot3D(x,y,z,2);
        }
    }

---------------------------------------------------------------------------------------------------
|----3DDEMO2.C

#include "c:\tc\cexe\myhead.h"
#define LEFT   0x4b00
#define RIGHT  0x4d00
#define UP     0x4800
#define DOWN   0x5000
#define ESC    0x011b

void ShowXYM(Byte);
void PWM(Byte);
void Ball(int,int,int,int,Byte);

void main(void)
    {
     int Theta=240,Phi=12;
     int key;Byte color=0;

      InitGraphics("c:\\tc\\tc2\\bgi");
      SetAxisMid();
     while(!(kbhit()))
     {
      InitPer(0,0,0,500,50);/*3D Init*/
      Theta%=360;
      Phi  %= 90;
      InitPlotting(Theta,Phi);

      ShowPalette();

      ShowXYM(color+2);
      ShowAxis3D(BLUE,YELLOW,CYAN);


     /* PWM(color+4);   */

      Line3D(0,0,0,100,100,100,color+4);
      Ball(100,100,100,100,color+9);
      key=bioskey(0);
      if(key==LEFT)  Theta+=5;
      if(key==RIGHT) Theta-=5;
      if(key==UP)    Phi  +=2;
      if(key==DOWN)  Phi  -=2;
      if(key==ESC)   ExitGraphics();
      cleardevice();
     }
    }

void ShowXYM(Byte color)
    {
     int x,y;

     for(x=-300;x<=300;x+=40)
        Line3D(x,-300,0,x,300,0,color);
     for(y=-300;y<=300;y+=40)
        Line3D(-300,y,0,300,y,0,color);
    }

void PWM(Byte color)
    {
     long x,y,z;
     for(x=-200;x<=200;x+=20)
     for(y=-200;y<=200;y++)
        {
         z=Round(sqrt(x*x+y*y)/2);
         Plot3D(x,y,z,color);
        }
     for(y=-200;y<=200;y+=20)
     for(x=-200;x<=200;x++)
        {
         z=Round(sqrt(x*x+y*y)/2);
         Plot3D(x,y,z,color);
        }
    }
void Ball(int x,int y,int z,int R,Byte color)
    {
     int Theta,Phi;
     for(Theta=0;Theta<180;Theta+=20)
        {
         for(Phi=0;Phi<180;Phi++)
           {
            Plot3D(x+R*CosD(Phi)*CosD(Theta),y+R*CosD(Phi)*SinD(Theta),z+R*SinD(Phi),color);
            Plot3D(x+R*CosD(Phi)*CosD(Theta),y+R*CosD(Phi)*SinD(Theta),z-R*SinD(Phi),color);
           }
        }
     for(Phi=-80;Phi<90;Phi+=20)
        {
         for(Theta=0;Theta<180;Theta++)
           {
            Plot3D(x+R*CosD(Phi)*CosD(Theta),y+R*CosD(Phi)*SinD(Theta),z+R*SinD(Phi),color);
            Plot3D(x+R*CosD(Phi)*CosD(Theta),y-R*CosD(Phi)*SinD(Theta),z+R*SinD(Phi),color);
           }
        }
    Plot3D(x,y,z,color+2);
    }

---------------------------------------------------------------------------------------------------
|----3DDEMO3.C

#include "c:\tc\cexe\myhead.h"
#define LEFT   0x4b00
#define RIGHT  0x4d00
#define UP     0x4800
#define DOWN   0x5000
#define ESC    0x011b

void ShowXYM(Byte);

void Luo(int,int,int,int,Byte);

void main(void)
    {
     int Theta=240,Phi=12;
     int key;Byte color=0;

      InitGraphics("c:\\tc\\tc2\\bgi");
      SetAxisMid();
     while(!(kbhit()))
     {
      InitPer(0,0,0,500,500);/*3D Init*/
      Theta%=360;
      Phi  %= 90;
      InitPlotting(Theta,Phi);

      ShowPalette();

      ShowXYM(color+2);
      ShowAxis3D(BLUE,YELLOW,CYAN);


     /* PWM(color+4);   */

      Line3D(0,0,0,100,100,10,color+4);
      Luo(100,100,10,40,color+9);
      key=bioskey(0);
      if(key==LEFT)  Theta+=5;
      if(key==RIGHT) Theta-=5;
      if(key==UP)    Phi  +=2;
      if(key==DOWN)  Phi  -=2;
      if(key==ESC)   ExitGraphics();
      cleardevice();
     }
    }

void ShowXYM(Byte color)
    {
     int x,y;

     for(x=-300;x<=300;x+=40)
        Line3D(x,-300,0,x,300,0,color);
     for(y=-300;y<=300;y+=40)
        Line3D(-300,y,0,300,y,0,color);
    }

void Luo(int x,int y,int z,int r,Byte color)
    {
     int i;
     for(i=0;i<180;i++)
       {
        Plot3D(x+r*CosD(i),y+r*SinD(i),z,color);
        Plot3D(x+r*CosD(i),y-r*SinD(i),z,color);
       }
     for(i=0;i<=1800;i++)
        Plot3D(x+r*CosD(i),y+r*SinD(i),z+i/10,color);
     Plot3D(x+r*CosD(i),y+r*SinD(i),z,color);
    }

---------------------------------------------------------------------------------------------------

[ Last edited by zzz19760225 on 2017-12-6 at 15:58 ]



1<词>,2[句],3/段\,4{节},5(章)。
2017-12-6 15:45
查看资料  发短消息 网志   编辑帖子  回复  引用回复
black0592
新手上路





积分 2
发帖 1
注册 2018-1-29
状态 离线
『第 68 楼』:  

下载看看,谢谢^_^

2018-1-30 10:04
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
zhangxiajun
新手上路





积分 8
发帖 4
注册 2018-1-29
状态 离线
『第 69 楼』:  

好东西

2018-1-30 10:14
查看资料  发短消息 网志   编辑帖子  回复  引用回复
zhangxiajun
新手上路





积分 8
发帖 4
注册 2018-1-29
状态 离线
『第 70 楼』:  

下载下来好好研究研究

2018-2-24 16:31
查看资料  发短消息 网志   编辑帖子  回复  引用回复
forrest0111
新手上路





积分 12
发帖 6
注册 2018-3-15
状态 离线
『第 71 楼』:  

不知道对以后有没有帮助,先下载下来再说。

2018-3-19 08:19
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
lswd
初级用户





积分 50
发帖 24
注册 2010-2-9
状态 离线
『第 72 楼』:  

下载看看

2020-2-7 13:38
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
ZyDOS
新手上路





积分 2
发帖 1
注册 2020-10-6
状态 离线
『第 73 楼』:  

下载看看

2020-10-7 08:18
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
« [1] [2] [3] [4] [5] »
请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: