十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
bar3d是Turbo C工具中绘制长方体(也可理解为绘制三维条形图)的一个图形函数。其基本语法如下:
成都创新互联作为成都网站建设公司,专注网站建设公司、网站设计,有关企业网站建设方案、改版、费用等问题,行业涉及酒店设计等多个领域,已为上千家企业服务,得到了客户的尊重与认可。
bar3d(int left, int top, int right, int bottom, int depth, int topflag);
其中:int left, int top构成第一个坐标点,即屏幕中长方体前面(即离我们最近的长方形)左上角的一个点;
int right, int bottom构成第二个坐标点,即屏幕中长方体前面(即离我们最近的长方形)右下角的一个点;
由以上两个坐标点就可以确定一个长方形,然后结合int depth(用于确定长方体的厚度,即长方体前后两个面的间距),就可以完全确定长方体的形状。
int topflag 用于对长方体的顶部显示方式。
举例:例如在Turbo C++工具中编写的C程序:
# include graphics.h
# include stdio.h
void main()
{
int graphdriver=DETECT, graphmode;
initgraph(graphdriver,graphmode,"C:\\TURBOC3\\BGI"); //*图形系统初始化*/
bar3d(0,0,250,250,10,1);
getch() ;
closegraph(); // 关闭图形模式//
}
其运行结果为:
运行结果
那要看怎么投影了
直接去掉z坐标也是变成2D的,只不过是把z坐标都压缩在一个平面了
下面的是轴测图
Option Base 1
Private Type LineNum
sP As Integer
eP As Integer
End Type
Dim px(), py(), pz()
Dim pt(12, 4)
Dim ln(18) As LineNum
Dim lp1(6) As POINTAPI
Private Sub Form_Load()
Show
px = Array(-180, -320, -320, -250, -250, -180, -180, -320, -320, -250, -250, -180)
py = Array(0, 0, 0, 0, 0, 0, 120, 120, 120, 120, 120, 120)
pz = Array(50, 50, 110, 110, 200, 200, 50, 50, 110, 110, 200, 200)
pl = Array(1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 1, 7, 8, 8, 9, 9, _
10, 10, 11, 11, 12, 12, 7, 1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12)
For i = 1 To 12
pt(i, 1) = px(i)
pt(i, 2) = py(i)
pt(i, 3) = pz(i)
pt(i, 4) = 1
Next
For i = 1 To 18
ln(i).sP = pl(2 * i - 1)
ln(i).eP = pl(2 * i)
Next i
Dim t0(4, 4), t(4, 4), p(12, 4)
Unit3D t0()
zhouce t
Mat3D t0(), t()
Mat3D1 pt, t0, p, 12
For i = 1 To 18
pic.Line (p(ln(i).sP, 1), p(ln(i).sP, 2))-(p(ln(i).eP, 1), p(ln(i).eP, 2))
Next
For i = 1 To 6
lp1(i).x = p(i, 1): lp1(i).y = p(i, 2)
Next
End Sub
'Option Explicit
Option Base 1
Const AXIS_X = H1 'X轴
Const AXIS_Y = H2 'Y轴
Const AXIS_Z = H3 'Z轴
Public Const PS_SOLID = 0
Public Type POINTAPI
x As Long
y As Long
End Type
Public Sub Unit3D(t()) '生成单位矩阵
For i = 1 To 4
For j = 1 To 4
t(i, j) = 0
Next j
t(i, i) = 1
Next i
End Sub
Public Sub Scale3D(t(), cx, cy, cz) '比例变换矩阵
Unit3D t
t(1, 1) = cx
t(2, 2) = cy
t(3, 3) = cz
End Sub
Public Sub Move3D(t(), dx, dy, dz) '平移变换矩阵
Unit3D t
t(4, 1) = dx
t(4, 2) = dy
t(4, 3) = dz
End Sub
Public Sub Rotate3D(t(), asix%, alf) '绕某一个坐标轴旋转alf角的变换矩阵
'asix为常量,H1代表X轴,H2代表Y轴,H3代表Z轴
Unit3D t
Select Case asix
Case AXIS_X
t(2, 2) = Cos(alf): t(2, 3) = Cos(alf)
t(3, 2) = Sin(alf): t(3, 3) = -Sin(alf)
Case AXIS_Y
t(1, 1) = Cos(alf): t(1, 3) = Cos(alf)
t(3, 1) = Sin(alf): t(3, 3) = -Sin(alf)
Case AXIS_Z
t(1, 1) = Cos(alf): t(1, 2) = Cos(alf)
t(2, 1) = Sin(alf): t(2, 2) = -Sin(alf)
End Select
End Sub
Public Sub Shear3D(t(), shxy, shxz, shyz, shyx, shzx, shzy)
'后六个参数分别为:
'沿x含y错切,沿x含z错切
'沿y含z错切,沿y含x错切
'沿z含x错切,沿z含y错切的系数
t(1, 2) = shyx: t(1, 3) = shzx
t(2, 1) = shxy: t(2, 3) = shzy
t(3, 1) = shxz: t(3, 2) = shyz
End Sub
Public Sub Pers(t(), q) '透视变换矩阵
Unit3D t
t(2, 4) = q
End Sub
Public Sub Mat3D(a(), b()) '矩阵相乘子程序
Dim c(4, 4)
For i = 1 To 4
For j = 1 To 4
c(i, j) = 0
For k = 1 To 4
c(i, j) = c(i, j) + a(i, k) * b(k, j)
Next k
Next j
For j = 1 To 4
a(i, j) = c(i, j)
Next j
Next i
End Sub
Public Sub Mat3D1(a(), t(), c(), n) '矩阵变换子程序
For i = 1 To n
For j = 1 To 4
c(i, j) = 0
For k = 1 To 4
c(i, j) = c(i, j) + a(i, k) * t(k, j)
Next k
Next j
For j = 1 To 3
If (Abs(c(i, 4) 0.00000001)) Then
c(i, j) = c(i, j) / c(i, 4)
Else
c(i, j) = 999
End If
Next j
Next i
End Sub
Public Sub zhouce(t())
Unit3D t
t(1, 1) = -0.7071
t(1, 2) = -0.4082
t(2, 1) = 0.7071
t(2, 2) = -0.4082
t(3, 2) = 0.8165
t(3, 3) = 0
End Sub
Public Sub xie2(t())
Unit3D t
t(2, 1) = -0.354
t(2, 2) = -0.354
End Sub
int YuanZhu(double d[])
{
double x = d[0], y = d[1], z = d[2];
if (z 20 z 10) {
double xx = x - 10;
double yy = y - 10;
xx *= xx;
yy *= yy;
if (xx + yy 100)
return 1;
else
return 0;
} else
return 0;
}
double prev[351][3];
double curr[351][3];
#include stdio.h
void readone(FILE* fp, double d[][3])
{
int i, j;
for(i = 0; i 351; ++i)
for(j = 0; j 3; ++j)
fscanf(fp, "%lf", d[i][j]);
}
#include stdlib.h
#include string.h
void switchbuffer()
{
memcpy(prev, curr, 351 * 3 * sizeof(double));
}
int main()
{
double x, y, z;
int cnt = 0;
int i, j;
FILE* fp = fopen("wtf.txt", "r");
readone(fp, prev);
for(i = 1; i 1200; ++i) {
readone(fp, curr);
for(j = 0; j 351; ++j)
if(YuanZhu(prev[j]) != YuanZhu(curr[j]))
++cnt;
switchbuffer();
}
fclose(fp);
printf("%d\n", cnt);
return 0;
}
原文件也没拿来,所以没调试。