eryar

PipeCAD - Plant Piping Design Software.
RvmTranslator - Translate AVEVA RVM to OBJ, glTF, etc.
posts - 603, comments - 590, trackbacks - 0, articles - 0

OpenCASCADE Ring Type Spring Modeling

Posted on 2016-03-05 00:51 eryar 阅读(2136) 评论(0)  编辑 收藏 引用 所属分类: 2.OpenCASCADE

OpenCASCADE Ring Type Spring Modeling

eryar@163.com

Abstract. The general method to directly create an edge is to give a 3D curve as the support(geometric domain) of the edge. The curve maybe defined as a 2D curve in the parametric space of a surface: PCurve. When you understand the pcurve, you can modeling some interesting shapes, such as bottle neck thread, helix spring, ring type spring. Etc. The paper is focus on the Ring Type Spring Modeling in OpenCASCADE Draw Test Harness by Tcl script.

Key Words. Spring, Helix, Tcl/Tk, 环形弹簧

1. Introduction

在上网的时候不经意看到了ZWCAD论坛上的这么一个帖子:环形弹簧三维建模练习:http://www.zwcad.com/community/forum.php?mod=viewthread&tid=2302

wps_clip_image-2001

Figure 1.1 Ring Type Spring

从上图可见,这个图形还是很有趣的,论坛中给出了在ZW中造型的一种方法,即先创建一个螺旋圆环,再用圆形陈列来得到这个环形弹簧。

如何在OpenCASCADE中来造型呢?我想的方法是利用扫掠,关键就是扫掠的路径环形螺放线的构造出来。因为原来使用过pcurve来生成过一个普通的弹簧,所以在想能不能在这个基础上进行扩展,来对这种环形弹簧来造型。

2.PCurve 

根据pcurve的定义:The curve may be defined as a 2d curve in the parametric space of a surface. 可以看出pcurve的两个特点:

v pcurve是一条二维曲线;

v 与曲面相关;

即pcurve就是曲面参数空间中一条二维曲线,pcurve上的点就是曲面参数空间中的点,其映射过程为:pcurve根据一个参数x计算得到一个二维点(u,v),将这个二维点(u,v)作为曲面的参数计算出曲面上的点S(u,v),即为pcurve对应到曲面上的曲线。因为是环形的,所以我联想到了Torus曲面,如下图所示:

wps_clip_image-2987

Figure 2.1 Torus in OpenCASCADE Draw Test Harness

在Draw Test Harness中生成一个圆环面还是很简单的,只需要以下几条命令:

pload ALL 

torus t 
1 0.3 

mkface f t 

vdisplay f 

根据利用圆柱面来对普通弹簧造型的方法“Make Helix Curve in OpenCASCADE”

http://www.cppblog.com/eryar/archive/2015/07/09/211212.html ,是否可以利用圆环面来生成圆环弹簧呢?实践是检验真理的唯一标准,随便尝试,反正失败了也没有什么损失。要利用pcurve就要找出曲面及其参数空间的一条二维曲线,现在初步确定了曲面为torus面,下面再来寻找pcurve。根据《OpenCASCADE BRep Format》中对于Torus的参数表示方程为:

wps_clip_image-16710

wps_clip_image-3246

由参数方程可知,torus面的参数空间为0到2PI的一个正方形区域,如下图所示:

wps_clip_image-5822

Figure 2.2 PCurve of Torus Face

当u=0或v=0时,曲面的参数方程为:

wps_clip_image-24802

wps_clip_image-493wps_clip_image-14106

Figure 2.3 Torus curves when u=0 and v=0

对应到参数空间分别为u轴上的直线和v轴上的直线。当u取几个固定值,v在参数空间任意变化时,即可以得到圆环面上几个圆形曲线。当u,v参数连续变化时,先用最简单的一次曲线直线来尝试下,Tcl脚本如下所示:

 

# 
# make helix torus in OpenCASCADE. 
# Shing Liu(eryar@163.com) 
# 2016-02-20 21:00 


pload MODELING VISUALIZATION 

# use torus surface. 
torus aTorus 10 2 

set aSlope 
0.05 
line aLine2d 
0 0 $aSlope 1 
trim aSegment aLine2d 
0 2*pi 

# make edge by the pcurve. 
mkedge aHelixEdge aSegment aTorus 0 2*pi/$aSlope 

# there is no curve 3d in the pcurve edge. 
# so need this to approximate one. 

mkedgecurve aHelixEdge 0.01 

# display the edge. 
vdisplay  aHelixEdge 

生成结果如下图所示:

wps_clip_image-19095

Figure 2.4 Torus Curve made by pcurve

其中螺距的调整可以通过调整pcurve的斜率来实现。

wps_clip_image-17217

Figure 2.5 Torus Spring

由图可见,pcurve使用直线效果比较理想。曲线生成之后,只需要将一个轮廓沿着曲线扫掠即可。

3.Modeling in Draw Test Harness

将上述放在一起来实现一个环形弹簧的造型,为了便于测试,主要是在Draw Test Harness中使用Tcl脚本来测试效果。使用Tcl脚本来测试效果有很多好处,主要就是不需要编写C++代码,也不用编译,可以实时检验结果。而且OpenCASCADE的Tcl脚本也可以很方便地翻译成C++代码。所以学习一下Tcl脚本还是有很多好处的,如Tcl具有跨平台的特性,通过使用脚本,可以对参数化有更进一步的理解等。言归正传,下面给出环形弹簧造型的Tcl脚本:

 

#
# make helix torus(Ring Type Spring) in OpenCASCADE.
# Shing Liu(eryar@163.com)
# 2016-02-20 21:00
#


pload MODELING VISUALIZATION

# use torus surface.
torus aTorus 10 2

set aSlope 
0.05
line aLine2d 
0 0 $aSlope 1
trim aSegment aLine2d 
0 2*pi

# make edge by the pcurve.
mkedge aHelixEdge aSegment aTorus 0 2*pi/$aSlope

# there is no curve 3d in the pcurve edge.
# so need this to approximate one.

mkedgecurve aHelixEdge 0.01

wire aHelixWire aHelixEdge

# make the profile.
circle aProfile 12 0 0 1 1 1 0.3
mkedge aProfile aProfile
wire aProfile aProfile
mkplane aProfile aProfile

# display the profile.
vdisplay aProfile aHelixEdge

# loft the circle along the helix curve.
pipe aSpring aHelixWire aProfile

# display the result.
vdisplay aSpring
#vsetmaterial aSpring steel
vsetgradientbg 180 200 255 180 180 180 2
vsetdispmode 
1
vzbufftrihedron

set ray tracing
if { ! [catch {vrenderparams -raytrace -shadows -reflections -fsaa -rayDepth 5}] } {
  vtextureenv on 
1
}

生成结果如下图所示:

wps_clip_image-6995

下图是使用Ray Tracing后显示的效果,感觉不错:

wps_clip_image-31391

wps_clip_image-23847

4. Conclusion

综上所述,理解了pcurve后可以对一些规则的有趣的曲线进行造型。另外学会在Draw Test Harness中使用Tcl脚本来尝试自己的想法,将会感觉到脚本的便利性。其实在OpenCASCADE的官网上也是提倡使用Tcl脚本来报告bug。

5. References

1. OpenCASCADE BRep Format

2. Shing Liu. Make Helix Curve in OpenCASCADE. 

http://www.cppblog.com/eryar/archive/2015/07/09/211212.html

3. ZW3D community topic:

http://www.zwcad.com/community/forum.php?mod=viewthread&tid=2302

 


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理