三维坐标如何转换成二维的?一个三维的点(x,y,z)如何转换成一个二维的点坐标(x,y)?不要理论,直接说转换函数表达式.
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/27 06:33:59
三维坐标如何转换成二维的?一个三维的点(x,y,z)如何转换成一个二维的点坐标(x,y)?不要理论,直接说转换函数表达式.
三维坐标如何转换成二维的?
一个三维的点(x,y,z)如何转换成一个二维的点坐标(x,y)?不要理论,直接说转换函数表达式.
三维坐标如何转换成二维的?一个三维的点(x,y,z)如何转换成一个二维的点坐标(x,y)?不要理论,直接说转换函数表达式.
那要看怎么投影了
直接去掉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