bar3d是Turbo C工具中繪制長方體(也可理解為繪制三維條形圖)的一個圖形函數(shù)。其基本語法如下:
成都創(chuàng)新互聯(lián)作為成都網(wǎng)站建設公司,專注網(wǎng)站建設公司、網(wǎng)站設計,有關企業(yè)網(wǎng)站建設方案、改版、費用等問題,行業(yè)涉及酒店設計等多個領域,已為上千家企業(yè)服務,得到了客戶的尊重與認可。
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");? ?//*圖形系統(tǒng)初始化*/
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)
'后六個參數(shù)分別為:
'沿x含y錯切,沿x含z錯切
'沿y含z錯切,沿y含x錯切
'沿z含x錯切,沿z含y錯切的系數(shù)
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;
}
原文件也沒拿來,所以沒調(diào)試。