馬上注冊(cè),結(jié)交更多好友,享用更多功能,讓你輕松玩轉(zhuǎn)社區(qū)。
您需要 登錄 才可以下載或查看,沒(méi)有帳號(hào)?立即加入SketchUp吧!

x
轉(zhuǎn)自http://blog.csdn.net/article/details/38357541
里面還有更多內(nèi)容。
我們可以在Sketchup中用“弧”和“圓”工具去畫出相應(yīng)圖形,但是我們畫出來(lái)并不是真正意義上的圓或弧形,而是由一段段細(xì)小的直線片段組成的。用編碼實(shí)現(xiàn)時(shí),實(shí)體類有三個(gè)方法來(lái)生成類似于弧形的圖案,每一個(gè)方法返回的是一組邊對(duì)象集。這三個(gè)方法是add_curve, add_circle, 和 add_arc。這三個(gè)方法于畫多邊形的方法非常類似,即add_ngon。 1、畫曲線——add_curve [ruby] view plaincopy
- pt1 = [0, 1, 0]
- pt2 = [0.588, -0.809, 0]
- pt3 = [-0.951, 0.309, 0]
- pt4 = [0.951, 0.309, 0]
- pt5 = [-0.588, -0.809, 0]
- curve = Sketchup.active_model.entities.add_curve pt1, pt2, pt3,pt4, pt5, pt1
在這里,add_curve方法產(chǎn)生一個(gè)五條邊組成的邊集,這就是說(shuō),add_curve方法產(chǎn)生的還是直線,并不是圓滑的曲線。但是,當(dāng)我們把點(diǎn)數(shù)增加時(shí),這些由點(diǎn)生成的緊密的多段線將像一個(gè)圓曲線。
2、圓形--add_circle add_circle方法需要三個(gè)參數(shù),分別是原點(diǎn)坐標(biāo)、圓正向向量、和直徑,如下代碼所示。 [ruby] view plaincopy
- circle = Sketchup.active_model.entities.add_circle [1, 2, 3],[4, 5, 6], 7
(1,2,3)是原點(diǎn)坐標(biāo),(4.5.6)是圓的正向向量,7是圓的直徑,下圖紅色方框中顯示的就是生成的圓。在代碼運(yùn)行結(jié)果中返回的就是一系列邊的對(duì)象。
3、多邊形 畫多邊形的方法add_ngon與畫圓的方法很像,唯一的區(qū)別在于,在畫圓時(shí),系統(tǒng)默認(rèn)是的是由24條直線片段圍成圓,而多邊形是由你指定邊數(shù),下面看看代碼如何實(shí)現(xiàn)。
[ruby] view plaincopy
- ents = Sketchup.active_model.entities
- normal = [0, 0, 1]
- radius = 1
- # Polygon with 8 sides
- ents.add_ngon [0, 0, 0], normal, radius, 8
- # Circle with 8 sides
- ents.add_circle [3, 0, 0], normal, radius, 8
- # Polygon with 24 sides
- ents.add_ngon [6, 0, 0], normal, radius, 24
- # Circle with 24 sides
- ents.add_circle [9, 0, 0], normal, radius
代碼很容易理解,不做多解釋。
4、弧形 畫弧形相比畫圓,需要我們指定起點(diǎn)和止點(diǎn)的角度,如下一條命令:
[ruby] view plaincopy
- arc = Sketchup.active_model.entities.add_arc [0,0,0], [0,1,0],[0,0,1], 50, 0, 90.degrees
第一個(gè)參數(shù)(0,0,0)表示圓弧的原點(diǎn);
第二個(gè)參數(shù)(0,1,0)表示圓弧的起點(diǎn)。 The following command creates an arc centered at [0, 0, 0] that intercepts an angle from 0° to 90°. The angle is measured from the y-axis, so the vector at 0° is [0, 1, 0]. The arc has a radius of 5 and lies in the x-y plane, so its normal vector is [0, 0, 1]. The number of segments is left to its default value.
|