|
leafmaple
新手上路

积分 4
发帖 2
注册 2010-11-18
状态 离线
|
|
2010-12-21 08:18 |
|
|
svols
新手上路

积分 2
发帖 1
注册 2010-12-29
状态 离线
|
|
2010-12-30 18:56 |
|
|
angussx
新手上路

积分 2
发帖 1
注册 2010-11-28
状态 离线
|
|
2011-1-24 12:13 |
|
|
qingwashaoye
中级用户
  
积分 271
发帖 74
注册 2004-11-17
状态 离线
|
『第 64 楼』:
使用 LLM 解释/回答一下
顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶
顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶 顶顶
顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶 顶顶
顶顶顶顶顶顶顶顶顶顶 顶顶 顶顶顶顶顶顶顶
顶顶顶顶顶顶 顶顶 顶顶顶 顶顶顶顶顶顶顶顶
顶 顶顶顶顶顶顶顶 顶顶顶顶顶顶顶顶顶
顶 顶顶顶顶顶顶顶顶 顶顶顶顶
顶顶 顶顶顶顶顶顶顶顶 顶顶
顶顶顶 顶顶顶 顶顶顶顶顶顶 顶顶顶顶顶 顶顶
顶顶顶顶顶顶顶顶 顶顶顶顶顶顶 顶顶顶 顶顶顶顶 顶顶顶
顶顶顶顶顶顶顶顶 顶顶顶顶顶 顶顶顶 顶顶顶 顶顶顶
顶顶顶顶顶顶顶顶 顶顶顶顶顶 顶顶顶 顶顶顶 顶顶顶
顶顶顶顶顶顶顶顶 顶顶顶顶顶 顶顶 顶顶顶 顶顶顶
顶顶顶顶顶顶顶顶 顶顶顶顶顶 顶顶 顶顶顶 顶顶顶
顶顶顶顶顶顶顶顶 顶顶顶顶顶 顶顶 顶顶顶 顶顶顶
顶顶顶顶顶顶顶顶 顶顶顶顶顶 顶顶 顶顶顶 顶顶顶
顶顶顶顶顶顶顶顶 顶顶顶顶顶 顶顶顶 顶顶顶顶 顶顶顶
顶顶顶顶顶顶顶顶 顶顶顶顶顶 顶顶顶 顶顶顶顶 顶顶顶
顶顶顶 顶顶顶顶顶顶 顶顶 顶顶顶顶 顶顶顶
顶顶顶顶 顶顶顶顶顶顶顶顶顶 顶顶 顶顶顶 顶顶顶
顶顶顶顶顶顶 顶顶顶顶顶顶顶顶 顶顶 顶顶顶顶顶
顶顶顶顶顶顶顶顶 顶顶顶顶顶顶顶 顶顶顶 顶顶
顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶 顶顶顶顶顶 顶
顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶 顶顶顶顶顶顶顶顶 顶
顶顶顶顶顶顶顶顶顶顶顶顶顶 顶顶顶顶顶顶顶顶顶顶 顶
顶顶顶顶顶顶顶顶顶顶顶顶 顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶 顶顶
顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶
Top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top
Top top top top top top top top top top top top top top top top top top top top Top top
Top top top top top top top top top top top top top top top Top top
Top top top top top top top top top top Top top Top top top top top top top
Top top top top top top Top top Top top top Top top top top top top top
Top Top top top top top top top Top top top top top top top top
Top Top top top top top top top top Top top top top
Top top Top top top top top top top Top top
Top top top Top top top Top top top top top top Top top top top top Top top
Top top top top top top top top Top top top top top top Top top top Top top top top Top top top
Top top top top top top top top Top top top top top Top top top Top top top Top top top
Top top top top top top top top Top top top top top Top top top Top top top Top top top
Top top top top top top top top Top top top top top Top top Top top top Top top top
Top top top top top top top top Top top top top top Top top Top top top Top top top
Top top top top top top top top Top top top top top Top top Top top top Top top top
Top top top top top top top top Top top top top top Top top Top top top Top top top
Top top top top top top top top Top top top top top Top top top Top top top top Top top top
Top top top top top top top top Top top top top top Top top top Top top top top Top top top
Top top top Top top top top top top Top top Top top top top Top top top
Top top top top Top top top top top top top top Top top Top top top Top top top
Top top top top top top Top top top top top top top Top top Top top top top top
Top top top top top top top top Top top top top top top Top top top Top top
Top top top top top top top top top top top top top top top Top top top top top Top
Top top top top top top top top top top top top top top top Top top top top top top top Top
Top top top top top top top top top top top top top Top top top top top top top top top Top
Top top top top top top top top top top top top Top top top top top top top top top top top top top Top top
Top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top
|
|
2017-2-1 01:08 |
|
|
fsyzwuli
新手上路

积分 16
发帖 8
注册 2017-11-23
状态 离线
|
『第 65 楼』:
使用 LLM 解释/回答一下
资料这么齐全!强啊!!!
The materials are so complete! Great!!!
|
|
2017-12-6 08:53 |
|
|
zzz19760225
超级版主
        
积分 3673
发帖 2020
注册 2016-2-1
状态 离线
|
『第 66 楼』:
楼主文件铺开
使用 LLM 解释/回答一下
数学与图形库
|
|---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;
typedef int TDIA;
typedef float FDA;
typedef float Matx4x4;
void Vec(float r,float s,float t,TDA a)
{
a=r;a=s;a=t;
}
void VecInt(int r,int s,int t,TDIA a)
{
a=r;a=s;a=t;
}
void UnVec(TDA a,float *r,float *s,float *t)
{
*r=a;*s=a;*t=a;
}
void UnVecInt(TDIA a,int *r,int *s,int *t)
{
*r=a;*s=a;*t=a;
}
float VecDot(TDA a,TDA b)
{
return(a*b+a*b+a*b);
}
void VecCross(TDA a,TDA b,TDA c)
{
c=a*b-a*b;
c=a*b-a*b;
c=a*b-a*b;
}
float VecLen(TDA a)
{
return(sqrt(SqrFP(a)+SqrFP(a)+SqrFP(a)));
}
void VecNormalize(TDA a)
{
float dist,invdist;
dist=VecLen(a);
if(!(dist==0.0))
{
invdist=1.0/dist;
a*=invdist;
a*=invdist;
a*=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=0;
for(mrow=0;mrow<4;mrow++)
b+=a*Matrix;
}
}
void VecSub(TDA a,TDA b,TDA c)
{
c=a-b;
c=a-b;
c=a-b;
}
void VecSubInt(TDIA a,TDIA b,TDIA c)
{
c=a-b;
c=a-b;
c=a-b;
}
void VecAdd(TDA a,TDA b,TDA c)
{
c=a+b;
c=a+b;
c=a+b;
}
void VecAdd3(TDA a,TDA b,TDA c,TDA d)
{
d=a+b+c;
d=a+b+c;
d=a+b+c;
}
void VecCopy(TDA a,TDA b)
{
b=a;
b=a;
b=a;
}
void VecLinComb(float r,TDA a,float s,TDA b,TDA c)
{
c=r*a+s*b;
c=r*a+s*b;
c=r*a+s*b;
}
void VecScalMult(float r,TDA a,TDA b)
{
b=r*a;
b=r*a;
b=r*a;
}
void VecScalMultI(float r,TDIA a,TDA b)
{
b=r*a;
b=r*a;
b=r*a;
}
void VecScalMultInt(float r,TDA a,TDIA b)
{
b=Round(r*a);
b=Round(r*a);
b=Round(r*a);
}
void VecAddScalMult(float r,TDA a,TDA b,TDA c)
{
c=r*a+b;
c=r*a+b;
c=r*a+b;
}
void VecNull(TDA a)
{
a=0.0;
a=0.0;
a=0.0;
}
void VecNullInt(TDIA a)
{
a=0;
a=0;
a=0;
}
void VecElemMult(float r, TDA a,TDA b,TDA c)
{
c=r*a*b;
c=r*a*b;
c=r*a*b;
}
/*
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 =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=-tx;
a=-ty;
a=-tz;
}
void Scale3D(float sx,float sy,float sz,Matx4x4 a)
{
ZeroMatrix(a);
a=sx;
a=sy;
a=sz;
a=1.0;
}
void Rotate3D(int m,float theta, Matx4x4 a)
{
int m1,m2;
float c,s;
ZeroMatrix(a);
a=1.0;
a=1.0;
m1=(m%3)+1;
m2=(m1%3);
m1=-1;
c=CosD(theta);
s=SinD(theta);
a=c;
a=s;
a=c;
a=-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*b;
c=ab;
}
}
}
void MatCopy(Matx4x4 a,Matx4x4 b)
{
int i,j;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
b=a;
}
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=m*a+m*a+m*a+m;
b=m*a+m*a+m*a+m;
b=m*a+m*a+m*a+m;
}
---------------------------------------------------------------------------------------------------
|---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 ]
Mathematics and Graphics Library
|
|---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 Bian Ming, Xi'an University of Posts and Telecommunications.*/
/*This is a C language math library written by myself, tested and passed under TC2.0. Please use it with confidence O_o!
Specifically added 3D vector operations TDA for drawing vectors in the graphics library.
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);
}
}
/*3D vector operations
vec - Make Vector three parameters to generate a real vector
VecInt - Make Integer Vector three parameters to generate an integer vector
UnVec - Get Components of Vector pass real vector x,y,z axes to three numbers
UnVecInt - Get Components of Integer Vector pass integer vector x,y,z axes to three numbers
VecDot - Vector Dot Product dot product of two vectors
VecCross - Vector Cross Product vector cross product
VecLen - Vector length vector length
VecNormalize - Vector Normalize normalize vector, zero-length vector cannot be normalized
VecMatxMult - Vector Matrix Multiple multiply a 4×4 matrix with a vector
VecSub - Vector Subtraction assign the difference of two vectors to another vector
VecSubInt - Vector Subtraction Integer assign the difference of integer vectors
VecAdd - Vector Addition assign the sum of two vectors to another vector
VecAdd3 - Vector Addition assign the sum of three vectors to another vector
VecCopy - Vector Copy vector copy
VecLinComb - Vector Linear Combination C=R*A+S*B
VecScalMult - Vector Scalar Multiple real vector multiplied by real number
VecScalMultI - Vector Scalar Multiple integer vector multiplied by real number
VecScalMultInt- Vector Scalar Multiple and Rounding integer vector multiplied by integer and rounded
VecAddScalMult- Vector Add scalar Multiple C=R*A+B
VecNull - Vector Null set real vector to zero
VecNullInt - Vector Null Integer set integer vector to zero
VecElemMult - Vector Element Mulitiple C=R*A*B
*/
typedef float TDA;
typedef int TDIA;
typedef float FDA;
typedef float Matx4x4;
void Vec(float r,float s,float t,TDA a)
{
a=r;a=s;a=t;
}
void VecInt(int r,int s,int t,TDIA a)
{
a=r;a=s;a=t;
}
void UnVec(TDA a,float *r,float *s,float *t)
{
*r=a;*s=a;*t=a;
}
void UnVecInt(TDIA a,int *r,int *s,int *t)
{
*r=a;*s=a;*t=a;
}
float VecDot(TDA a,TDA b)
{
return(a*b+a*b+a*b);
}
void VecCross(TDA a,TDA b,TDA c)
{
c=a*b-a*b;
c=a*b-a*b;
c=a*b-a*b;
}
float VecLen(TDA a)
{
return(sqrt(SqrFP(a)+SqrFP(a)+SqrFP(a)));
}
void VecNormalize(TDA a)
{
float dist,invdist;
dist=VecLen(a);
if(!(dist==0.0))
{
invdist=1.0/dist;
a*=invdist;
a*=invdist;
a*=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=0;
for(mrow=0;mrow<4;mrow++)
b+=a*Matrix;
}
}
void VecSub(TDA a,TDA b,TDA c)
{
c=a-b;
c=a-b;
c=a-b;
}
void VecSubInt(TDIA a,TDIA b,TDIA c)
{
c=a-b;
c=a-b;
c=a-b;
}
void VecAdd(TDA a,TDA b,TDA c)
{
c=a+b;
c=a+b;
c=a+b;
}
void VecAdd3(TDA a,TDA b,TDA c,TDA d)
{
d=a+b+c;
d=a+b+c;
d=a+b+c;
}
void VecCopy(TDA a,TDA b)
{
b=a;
b=a;
b=a;
}
void VecLinComb(float r,TDA a,float s,TDA b,TDA c)
{
c=r*a+s*b;
c=r*a+s*b;
c=r*a+s*b;
}
void VecScalMult(float r,TDA a,TDA b)
{
b=r*a;
b=r*a;
b=r*a;
}
void VecScalMultI(float r,TDIA a,TDA b)
{
b=r*a;
b=r*a;
b=r*a;
}
void VecScalMultInt(float r,TDA a,TDIA b)
{
b=Round(r*a);
b=Round(r*a);
b=Round(r*a);
}
void VecAddScalMult(float r,TDA a,TDA b,TDA c)
{
c=r*a+b;
c=r*a+b;
c=r*a+b;
}
void VecNull(TDA a)
{
a=0.0;
a=0.0;
a=0.0;
}
void VecNullInt(TDIA a)
{
a=0;
a=0;
a=0;
}
void VecElemMult(float r, TDA a,TDA b,TDA c)
{
c=r*a*b;
c=r*a*b;
c=r*a*b;
}
/*
ZeroMatrix - zeros the elements of a 4x4 matrix
Translate3D - make translation matrix generate a new matrix by linearly transforming a vector to a new position in space
Scale3D - make Scaling matrix transform a vector into a matrix
Rotate3D - make rotation matrix generate a matrix by rotating a vector
ZeroAllMatricies - zeros all matricies used in tranformation
Multiply3DMatricies - multiply 2 4x4 matricies multiply two 4x4 matrices
PrepareMatrix - prepare the transformation matrix (Tm=S*R*T) generate a complete affine transformation matrix
PrepareInvMatrix - prepare the inverse transformation matrix
Transform - multiply a vertex by the transformation matrix multiply a vector by the transformation matrix to generate a new vector
*/
void ZeroMatrix(Matx4x4 a)
{
int i,j;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
a =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=-tx;
a=-ty;
a=-tz;
}
void Scale3D(float sx,float sy,float sz,Matx4x4 a)
{
ZeroMatrix(a);
a=sx;
a=sy;
a=sz;
a=1.0;
}
void Rotate3D(int m,float theta, Matx4x4 a)
{
int m1,m2;
float c,s;
ZeroMatrix(a);
a=1.0;
a=1.0;
m1=(m%3)+1;
m2=(m1%3);
m1=-1;
c=CosD(theta);
s=SinD(theta);
a=c;
a=s;
a=c;
a=-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*b;
c=ab;
}
}
}
void MatCopy(Matx4x4 a,Matx4x4 b)
{
int i,j;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
b=a;
}
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=m*a+m*a+m*a+m;
b=m*a+m*a+m*a+m;
b=m*a+m*a+m*a+m;
}
---------------------------------------------------------------------------------------------------
|---MYGRAPH.INC
/*MYGraph.Inc BY BIANMING 2005-11-27
InitGraphics - initialize graphics
- Screen initialization, specify the graphics driver path gpath
ExitGraphics - sound and wait for key press before exiting grapgics
- Call after generating graphics
SetAxisZP - Set the graphic origin coordinates, default is (0,439) as the origin
SetAxisMid - Set the graphic origin coordinates to the center of the screen
Plot - place pixel to screen
CylPlot - polar coordinate drawing point method
GetPixel - gets pixel
- return color from specified point
Circle - circle draw routine
- draw a circle with given center, radius, and color
Line - line draw routine
- draw a line from given point to another point with given color
ShowAxis - display 2D axes ,set X-Axis color,set Y-Axis color.
Title - set up text screen colors
- prepare the screen for text output
*/
int CentreX ,CentreY; /* Origin coordinates*/
int MaxX; /*getmaxx*/
int MaxY; /*getmaxy*/
int MaxXres;
int MaxYres;
int MaxColor; /*Maximum number of colors*/
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) /* Set the graphic origin coordinates, default is (0, 439) as the origin*/
{
CentreX=x;
CentreY=y;
}
void SetAxisMid(void) /*Set the graphic origin coordinates to the center of the screen*/
{
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-axis*/
Line(0,-200,0,200,ycolor);
Line(7,190,0,200,ycolor);
Line(-7,190,0,200,ycolor);/*y-axis*/
}
void Title()
{
textcolor(YELLOW);
textbackground(BLUE);
clrscr();
}
/*FOR 3D GRAPHICS
InitPer - observer location and distances
- assign observer coordinates in 3D space Per controls whether it is perspective view true-yes false-no
InitPlotting - rotation and tilt angles
- initialize variables for 3D graphics
MapCoordinates - maps 3D space onto the 2D screen
- project 3D points onto the view plane
Plot3D - plot a cartesian system point
- plot a point with given 3D coordinates and color on the 2D screen
CylPlot3D - plot a Cylindrical system point
- plot a point with given radius, angle with xy plane, z height, and color on the 2D screen given in Cylindrical coordinate system
SphPlot3D - plot a spherical system point
- plot a point with spherical coordinates r radius, Theta angle of radius line in xy plane, Phi angle of radius line in xz plane
VecLine3D - plots a line from 3D coordinates
- draw a 3D line from 3D coordinates parameter 1 as the start point and parameter 2 as the end point with color as the color
Line3D - draw a line from (x1,y1,z1)-(x2,y2,z2)
Vec3D - draw vector
Ball - draw a sphere (x,y,z) center coordinates, R radius, color
*/
Boolean PerspectivePlot;
float Mx,My,Mz,ds; /*Observer coordinates (Mx,My,Mz), distance (ds) assignment*/
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; /* Observer's rotation angle, elevation angle*/
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)/*draw 3D line with vector*/
{
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) /*draw vector 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) /*draw a sphere (x,y,z) center coordinates, R radius, 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
- return color from specified 3D point
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 Bian Ming, Xi'an University of Posts and Telecommunications.*/
/*This is a C language graphics library and math library written by myself, tested and passed under TC2.0. Please use it with confidence O_o!
All drawing functions draw relative to the adjusted coordinate origin, not the screen origin. Please note this! ! !
The feature is that all drawing functions have color settings added,
Specifically added 3D drawing. When doing 3D drawing, you need to initialize the observer's coordinates and distance (InitPer()).
Also need to initialize the observer's rotation angle relative to the x-axis and the elevation angle relative to the xy plane (InitPoltting()).
Because all 3D drawing functions are drawn relative to this initial value.
Note: When including this library, you also need to include stdio.h, dos.h, conio.h, math.h, graphics.h, math.inc these libraries.
Here you can also have an include "myhead.h". This file is in the compressed package.
You can continue to build your own library on this basis. You can also make any modifications. O_o!
Here are a few examples: 3Ddemo.c, 3Ddemo2.c, 3Ddemo3.c.
bmmm906@sohu.com
qq:53793208
Xi'an University of Posts and Telecommunications South Campus, Class 0303, Electronic Science, Mailbox 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 楼』:
楼主文件再铺开
使用 LLM 解释/回答一下
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 ]
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
状态 离线
|
|
2018-1-30 10:04 |
|
|
zhangxiajun
新手上路

积分 8
发帖 4
注册 2018-1-29
状态 离线
|
|
2018-1-30 10:14 |
|
|
zhangxiajun
新手上路

积分 8
发帖 4
注册 2018-1-29
状态 离线
|
『第 70 楼』:
使用 LLM 解释/回答一下
下载下来好好研究研究
Download it and study it carefully
|
|
2018-2-24 16:31 |
|
|
forrest0111
新手上路

积分 12
发帖 6
注册 2018-3-15
状态 离线
|
『第 71 楼』:
使用 LLM 解释/回答一下
不知道对以后有没有帮助,先下载下来再说。
I don't know if it will help in the future, so I'll just download it first.
|
|
2018-3-19 08:19 |
|
|
lswd
初级用户
 
积分 52
发帖 25
注册 2010-2-9
状态 离线
|
|
2020-2-7 13:38 |
|
|
ZyDOS
新手上路

积分 2
发帖 1
注册 2020-10-6
状态 离线
|
|
2020-10-7 08:18 |
|
|