在cad中,一般的麵片都是3d face。3d face是由四個頂點形成,在實際運用中為了能更好的顯示,一般將這四個點中的兩個點重合,形成三角形。在cad中,一般認為,如果繪製面的時候是按逆時針方向,則為正面,反之為反面。具體來說就是,如果3d face地四個頂點是按照逆時針方向的順序排列,則該面為正面;按照順時針方向順序排列為反面。
正反面非常重要,如在3dmax中,如果需要以地形的表面為基礎高程,則地物將會在地形表面上,如果是反面,則地形向下,即在地下,看不見!所以在匯入地形前,需要進行一些相應的前處理工作。下面的程式**就是如何實現正反面判斷、如何轉換正反面的:
public class 更正cad中麵片法線方向
public sub 啟動cad()
on error resume next
if err.number then
err.clear()
end if
end sub
private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click
call 啟動cad()
dim sset as autocad.acadselectionset
sset.selectonscreen()
dim ent as object
dim count as integer
for each ent in sset
if ent.objectname = "acdbface" then
dim ss as autocad.acad3dface
ss = ent
dim i as integer
dim point01(2), point02(2), point03(2), point04(2), newarraypoints(3, 2) as double
for i = 0 to 2
point01(i) = ss.coordinate(0)(i)
point02(i) = ss.coordinate(1)(i)
point03(i) = ss.coordinate(2)(i)
point04(i) = ss.coordinate(3)(i)
next
if is3points(point01, point02, point03, point04, newarraypoints) then
ss.delete()
dim p01(2), p02(2), p03(2) as double
dim j as integer
for j = 0 to 2
p01(j) = newarraypoints(0, j)
p02(j) = newarraypoints(1, j)
p03(j) = newarraypoints(2, j)
next
count = count + 1
end if
end if
next
msgbox("共有" & count.tostring() & "個反面")
end sub
private function isnotup(byval vector01() as double, byval vector02() as double) as boolean '檢驗兩個向量的向量積是否向上
dim zresult as double
zresult = vector01(0) * vector02(1) - vector01(1) * vector02(0)
if zresult >= 0 then
return true
end if
return false
end function
private sub dovector3(byval point01() as double, byval point02() as double, byval point03() as double, byref vector01() as double, byref vector02() as double) '根據三個點得到兩個向量
vector01(0) = point02(0) - point01(0)
vector01(1) = point02(1) - point01(1)
vector01(2) = point02(2) - point01(2)
vector02(0) = point03(0) - point02(0)
vector02(1) = point03(1) - point02(1)
vector02(2) = point03(2) - point02(2)
end sub
private function is3points(byval point01() as double, byval point02() as double, byval point03() as double, byval point04() as double, byref newarraypoints(,) as double) as boolean
is3points = false
dim i, j as integer
dim allpoints(3, 2) as double
for i = 0 to 2
allpoints(0, i) = point01(i)
next
for i = 0 to 2
allpoints(1, i) = point02(i)
next
for i = 0 to 2
allpoints(2, i) = point03(i)
next
for i = 0 to 2
allpoints(3, i) = point04(i)
next
for i = 0 to 3
for j = 0 to 3
if j = i then continue for
if allpoints(i, 0) = allpoints(j, 0) and allpoints(i, 1) = allpoints(j, 1) and allpoints(i, 2) = allpoints(j, 2) then
is3points = true
goto handle01
end if
next
next
handle01:
if j < 3 then
dim k as integer
for k = 0 to 2 - j
for i = 0 to 2
allpoints(j + k, i) = allpoints(j + k + 1, i)
next
next
end if
dim vector01(2), vector02(2) as double
dim p01(2), p02(2), p03(2) as double
for i = 0 to 2
p01(i) = allpoints(0, i)
p02(i) = allpoints(1, i)
p03(i) = allpoints(2, i)
next
dovector3(p01, p02, p03, vector01, vector02)
if (isnotup(vector01, vector02)) then
is3points = false
end if
dim s as string
for i = 0 to 3
s = s + allpoints(i, 0).tostring() + "," + allpoints(i, 1).tostring() + "," + allpoints(i, 2).tostring() + chr(13)
next
s = s + vector01(0).tostring() + "," + vector01(1).tostring() + "," + vector01(2).tostring() + chr(13)
s = s + vector02(0).tostring() + "," + vector02(1).tostring() + "," + vector02(2).tostring() + chr(13)
richtextbox1.text = s
for i = 0 to 3
for j = 0 to 2
newarraypoints(i, j) = allpoints(i, j)
next
next
end function
end class
這個程式的核心就是如何判斷正反面,在此我設計的是兩個向量相乘,即求向量積,判斷k方向的係數的正負,從而判斷面的方向.正數對應的是正面,負數對應的是負面.
列印正反面怎麼設定
列印正反面的設定方法 1 在word文件點選左上角 檔案 2 找到 列印 選項,點選 列印 3 在列印視窗中,點選下拉列表找到 雙面列印 4 在列印設定頁面上點選 列印所有頁 將選項設定為 僅列印奇數 偶數頁 即可。本教程操作環境 windows10系統,microsoft office word2...
注釋的反面教材
都說好注釋應該寫why而不是how,這裡給個只寫how的廢話注釋作為反面教材。mingdu.zhengatgmaildotcom void spiritradiosetmodulation modulationselect xmodulation 上面這段 裡的注釋是不是都是廢話呢。典型的為了寫注釋...
datagrid的正反雙向排序
在asp.net中利用datagrid控制項按列進行排序很是方便。可是我們只能單項排序!如果我們需要正反排序那麼就需要加入一些 控制一下。首先我們需要將datagird控制項的屬性設定為 allowsorting true 且需要排序列需要制定排序表示式 eg sortexpression kmdm...