NCF参数化建筑论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 28219|回复: 12
打印 上一主题 下一主题

[工作记录] 原创贝兹曲线程序——继续萌路线

[复制链接]
跳转到指定楼层
1m
发表于 2010-6-10 00:22:14 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
这里吧贝兹曲线的ruby代码发下 def BZ__BezierClassic.points(pts, numpts) curvepts = [] dt = 1.0 / numpts # evaluate the points on the curve for i in 0..numpts t = i * dt curvepts[i] = BZ__BezierClassic.evaluate(pts, t) end curvepts end def BZ__BezierClassic.evaluate(pts, t) degree = pts.length - 1 if degree < 1 return nil end t1 = 1.0 - t fact = 1.0 n_choose_i = 1 x = pts[0].x * t1 y = pts[0].y * t1 z = pts[0].z * t1 for i in 1...degree fact = fact*t n_choose_i = n_choose_i*(degree-i+1)/i fn = fact * n_choose_i x = (x + fn*pts[i].x) * t1 y = (y + fn*pts[i].y) * t1 z = (z + fn*pts[i].z) * t1 end x = x + fact*t*pts[degree].x y = y + fact*t*pts[degree].y z = z + fact*t*pts[degree].z Geom::Point3d.new(x, y, z) 这个算法还比较快~

评分

参与人数 2强度 +7 照度 +70 收起 理由
skywoolf + 5 + 50 原创内容
f(x) + 2 + 20

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享
2m
 楼主| 发表于 2010-6-10 00:24:03 | 显示全部楼层
也就是lagrange程序的升级版 觉得大家对程序视乎不感兴趣 所以嘛~没动力把程序再贴上来~

小黑屋|手机版|NCF参数化建筑论坛 ( 浙ICP备2020044100号-2 )    辽公网安备21021102000973号

GMT+8, 2024-5-2 18:59 , Processed in 0.062044 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表