🌓
搜索
 找回密码
 立即注册

四、Sketchup用ruby进行二次开发--Edge Arrays: Curves, Circles, Arcs和 P

作者 2022-10-6 06:51:37 54594
我们可以在Sketchup中用“弧”和“圆”工具去画出相应图形,但是我们画出来并不是真正意义上的圆或弧形,而是由一段段细小的直线片段组成的。用编码实现时,实体类有三个方法来生成类似于弧形的图案,每一个方法返回的是一组边对象集。这三个方法是add_curve, add_circle, 和 add_arc。这三个方法于画多边形的方法非常类似,即add_ngon。
1、画曲线——add_curve

  1. pt1 = [0, 1, 0]
  2. pt2 = [0.588, -0.809, 0]
  3. pt3 = [-0.951, 0.309, 0]
  4. pt4 = [0.951, 0.309, 0]
  5. pt5 = [-0.588, -0.809, 0]
  6. curve = Sketchup.active_model.entities.add_curve pt1, pt2, pt3,pt4, pt5, pt1
复制代码

在这里,add_curve方法产生一个五条边组成的边集,这就是说,add_curve方法产生的还是直线,并不是圆滑的曲线。但是,当我们把点数增加时,这些由点生成的紧密的多段线将像一个圆曲线。

2、圆形--add_circle
add_circle方法需要三个参数,分别是原点坐标、圆正向向量、和直径,如下代码所示。

  1. circle = Sketchup.active_model.entities.add_circle [1, 2, 3],[4, 5, 6], 7
复制代码

(1,2,3)是原点坐标,(4.5.6)是圆的正向向量,7是圆的直径,下图红色方框中显示的就是生成的圆。在代码运行结果中返回的就是一系列边的对象。


3、多边形
画多边形的方法add_ngon与画圆的方法很像,唯一的区别在于,在画圆时,系统默认是的是由24条直线片段围成圆,而多边形是由你指定边数,下面看看代码如何实现。

  1. ents = Sketchup.active_model.entities
  2. normal = [0, 0, 1]
  3. radius = 1
  4. # Polygon with 8 sides
  5. ents.add_ngon [0, 0, 0], normal, radius, 8
  6. # Circle with 8 sides
  7. ents.add_circle [3, 0, 0], normal, radius, 8
  8. # Polygon with 24 sides
  9. ents.add_ngon [6, 0, 0], normal, radius, 24
  10. # Circle with 24 sides
  11. ents.add_circle [9, 0, 0], normal, radius
复制代码
代码很容易理解,不做多解释。
4、弧形
画弧形相比画圆,需要我们指定起点和止点的角度,如下一条命令:

  1. arc = Sketchup.active_model.entities.add_arc [0,0,0], [0,1,0],[0,0,1], 50, 0, 90.degrees
复制代码

第一个参数(0,0,0)表示圆弧的原点;
第二个参数(0,1,0)表示圆弧的起点。
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.
181743wzofkkj7rk4g7leg.jpeg






来源:SketchUpBBS
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

扫一扫

3 回复

不错
phiend
2022-10-6 06:24:07
不错不错,楼主您辛苦了。。。
路过,支持一下啦
高级模式
游客
返回顶部