为了账号安全,请及时绑定邮箱和手机立即绑定

Sketchup 程序自动化(三)路径、平面拉升

标签:
Ruby

路径

个人理解,路径实质上是多条连续的线段进行组合起来具备某些特殊意义,最主要的作用还是为了让自定义的截面进行跟随形成一些我们想要的模型。

代码演示会更直接理解一点:

model = Sketchup.active_model
entities = model.entities
sel = model.selection

pt0 = Array.new()# 原点用数组(矩阵)表示orignPoint = Array.new(3,0)# 绘制简易曲线路径for i in 90..270
    pt = [orignPoint.x + i,orignPoint.y + 100 * Math::sin(i.degrees),orignPoint.z]
    pt0 << pt
end
curveline = entities.add_curve pt0

绘制面:

# 新建面的顶点数组facePointArr = [
    [0,0,10],
    [10,0,10],
    [10,10,10],
    [0,10,10]
]

test_face = entities.add_face facePointArr# 此时我们知道 entities 数组中就有了 5个实体 1曲线、1面、4线# 选中一个面# 提取出这个面的顶点sel.add test_face
verticesArr = sel[0].verticesfor item in verticesArr
    puts item.positionend

补充关于方向:

#  Sketchup 某些矩阵特定意义#  X 轴 :[1,0,0] [-1,0,0]#  Y 轴 :[0,1,0] [0,-1,0]#  Z 轴 :[0,0,1] [0,0,-1]#  某些函数(add_circle、add_nogn)需要指定某些面进行绘制,就要设置normal 参数#  XY面 设置 [0,0,1] [0,0,-1]#  XZ面 设置 [0,1,0] [0,-1,0]#  ZY面 设置 [1,0,0] [-1,0,0]# 我们在建立面时,并没有指定方向# 但我们发现:Z轴不为 0 是 [0,0,1] 为 0 时是 [0,0,-1]# 这个与存储与取出机制有关,实际应用中 正负影响不大puts test_face.normal# 面朝向反向reverseFace = test_face.reverse!# 面的面积 (这里的单位 10 * 10 平方英寸)puts reverseFace.area# 组成面的线对象数组puts reverseFace.edges

pt = [5,5,-10]# 对于 Face 与 点 关系的判断result = reverseFace.classify_point(pt)
puts result# 官方提供了一个枚举类型# 点在面里if result == Sketchup::Face::PointInside
  puts "#{pt.to_s} is inside the face"end# 点在端点上if result == Sketchup::Face::PointOnVertex
  puts "#{pt.to_s} is on a vertex"end# 点在边线上if result == Sketchup::Face::PointOnEdge
  puts "#{pt.to_s} is on an edge of the face"end# 点与面处于同一平面if result == Sketchup::Face::PointNotOnPlane
  puts "#{pt.to_s} is not on the same plane as the face"end

平面拉升

# pushpull 推的方向是按照图形的normal方向# face 没有对于向量进行定义,所以pushpull按照的是face的normal值的反向reverseFace.pushpull 10# 推一个圆柱体circle = entities.add_circle [0,0,40],[0,0,1],5circle_face = entities.add_face circle
circle_face.pushpull 20# followme 进行3D模型构建# 使用followme  对模型进行环切cut_face = entities.add_face Geom::Point3d.new(0,0,10),Geom::Point3d.new(2,2,10),Geom::Point3d.new(0,0,8)
cut_face.followme reverseFace.edges# followfacefollowFace = [
  Geom::Point3d.new(100,95,-5),
  Geom::Point3d.new(100,105,-5),
  Geom::Point3d.new(100,105,5),
  Geom::Point3d.new(100,95,5)
]

followFace = entities.add_face followFace# 跟随的界面一定是在路径的一端followFace.followme curveline



作者:ZhengRongXing
链接:https://www.jianshu.com/p/50c3e44ed0c4

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消