OpenCASCADE Rational Bezier Curves

简介: OpenCASCADE Rational Bezier Curves eryar@163.com Abstract. Although polynomials offer many advantages, there exist a number of important curve and...
OpenCASCADE Rational Bezier Curves

eryar@163.com

Abstract. Although polynomials offer many advantages, there exist a number of important curve and surface types which cannot be represented precisely using polynomials, e.g., circles, ellipses, hyperbolas, cylinders, cones, spheres, etc. So we introduce the concepts of rational curves and homogeneous coordinates to solve the problem. To understand rational curves in a homogenous coordinate system is more straightforward. If you define irrational Bezier curves in 4D space and then project them back into 3D space, you obtain rational curves.

Key Words. OpenCASCADE, Rational Curves, Homogenous Coordinate, Geom_BezierCurve

1. Introduction

由于采用了Berstein基函数,Bezier曲线具有许多良好的性质。但是作为多项式曲线,在表示一些“基本”曲线时还是有所不足。例如半径为1的圆弧曲线,其参数方程可表示为:

wps_clip_image-13132

圆弧曲线并不是多项式曲线,所以Bezier曲线不可能精确表示像圆弧这样的简单曲线。经过参数变换t=tan(u/2),可以把上面的圆弧表示为:

wps_clip_image-3401

这说明可以用有理多项式来精确表示圆弧曲线。事实上,有很多重要的曲线、曲面类型,如圆、椭圆、双曲线、圆柱面、圆锥面、球面等,都无法用Bezier来精确表示。由经典数学可知,包括圆在内的所有二次曲线都可以用有理函数(即两个多项式相除)来表示,即如下形式的有理函数来表示:、

wps_clip_image-9943

本文主要从齐次坐标的表示法上来理解有理Bezier曲线的概念,及结合OpenCASCADE中的Bezier曲线来理解权因子的几何意义。


2. Homogeneous Coordinates

在《计算几何》、《计算机图形学》或《计算机辅助几何造型技术》等书中,都会给出有理曲线的齐次坐标(Homogeneous Coordinates)表示法,藉此来从几何上直观理解有理曲线的意义。刚开始接触齐次坐标的概念时,很不能理解,原来这是射影几何中的一些概念。对此概念陌生的读者可以参考丘维声的《解析几何》,其中对齐次坐标、交比等概念作了详细解释。

现在我们来说明齐次坐标与仿射坐标的关系。设点M是平面wps_clip_image-30986上的通常点,(x,y)是它对于标架[O1:e1,e2]的仿射坐标,则wps_clip_image-9613对于标架[O2:e1,e2,e3]的坐标就是(x,y,1),于是点M的齐次坐标(x1,x2,x3)与(x,y,1)成比例:

wps_clip_image-30625

其中λ≠0.从而得:

wps_clip_image-30653

因此,通常点的齐次坐标和仿射坐标可以互相确定。有时我们把通常点M的仿射坐标(x,y)称为它的非齐次坐标。

从四维Euclidean空间的齐次坐标到三维Euclidean空间的中心投影变换

wps_clip_image-23761

这里三维空间的点[X,Y,Z]称为四维空间点[X,Y,Z,ω]的透视像,就是四维空间点[X,Y,Z,ω]在ω=1超平面上的中心投影,其投影中心就是四维空间的坐标原点。因此四维空间点[X,Y,Z,ω]与三维空间点[X,Y,Z]被认为是同一点。事实上,对任意X,Y,Z,ω1,ω2,其中ω1≠ω2,有:

wps_clip_image-25607

由上可知:一个点的齐次坐标不是唯一的。

在CAGD中描述形状的空间曲线与曲面都要用到三维空间。但是人类思维能力的限制,我们无法用图形或模型来表达从四维空间到三维空间的投影变换关系。为了理解这种投影变换的几何关系,我们可以降低一维,考察从三维到二维空间的投影变换,如下图所示为三维空间的齐次坐标到二维空间的投影。

wps_clip_image-14079

Figure 2.1 A representation of Euclidean points to homogeneous form

关于中心投影、射影平面、齐次坐标、变比等概念,可参考丘维声的《解析几何》一书。


3. Bezier Curve Perspective Map

在理解射影变换(Perspective Map)及齐次坐标的概念后,可以构造有理Bezier曲线的几何模型。现假设给定控制点{Pi},权因子{ωi},我们构造带权控制点:

wps_clip_image-8316

然后在四维空间中定义非有理(即多项式)Bezier曲线:

wps_clip_image-10313

将带权控制点代入上式详细写出每一项得:

wps_clip_image-16840

以原点为中心,将四维的Bezier曲线投影到ω=1的三维超平面上,所得到的投影曲线为:

wps_clip_image-10635

消去λ即得到有理Beizer曲线:

wps_clip_image-16557 

4. The Effects of Weighting Factors

有理Bezier曲线除了具有类似于Bezier曲线的性质外,还增加了关于“权因子”(Weights)的调整性质。

4.1 可退化性

当权因子ωi=ω≠0时(i=0,1,...,n),有理Bezier曲线退化成Bezier曲线。因为ω相同,所以有理Bezier曲线公式中的ω可以消去,又根据Bernstein基函数的规范性即得。使用OpenCASCADE的Tcl脚本测试效果如下图所示:

wps_clip_image-3697

Figure 4.1 Degeneracy of Rational Bezier Curve

相应的Tcl脚本如下所示:

 

#
#    Copyright (c) 2014 eryar All Rights Reserved.
#
#        File    : degenerate.tcl
#        Author  : eryar@163.com
#        Date    : 2014-09-19 18:10
#        Version : 1.0v
#
#    Description : Demonstrate the degeneracy of Rational Bezier Curve.
#


pload ALL

#  Bezier Curve with Weighted Poles: 
# {P(1,0), w(1)}, {P(1,1), w(1)}, {P{0,1}, w(1)}

2dbeziercurve bc1  3   1   0   1   1   1   1   0   1   1

v2d
2dfit

#  Bezier Curve without weights:
2dbeziercurve bc2  3   1   0   1   1   0   1
mkedge e1 bc2 
0   1

vdisplay e1
vtop
vfit

上述Tcl脚本中先把权值相同的有理Bezier曲线显示在二维窗口中,再将不带权的Bezier曲线(控制节点与带权值相同),先生成Edge,再在三维窗口中显示出来。由图可知,当有理Bezier曲线的权值相同时,即退化为非有理的Bezier曲线。

4.2 当ω0≠0,ωn≠0时,对任意u∈[0,1],

wps_clip_image-12378

只需证明u∈[0,1]的情况,

wps_clip_image-6898

这说明只要ω0≠0,ωn≠0,有理Bezier曲线R(u)一定通过首末控制顶点P0和Pn。对u∈[0,1],当ωi越大,R(u)越趋向于Pi;反之,当ωi越小,R(u)越远离Pi。

可以看出ωi→∞的极限状态时,R(u)即过通过Pi。使用OpenCASCADE的Tcl脚本来验证得到如下图所示结果:

wps_clip_image-21596

Figure 4.2 Rational Bezier Curve with different Weights

相应的Tcl脚本如下所示:

 

#
#    Copyright (c) 2014 eryar All Rights Reserved.
#
#        File    : degenerate.tcl
#        Author  : eryar@163.com
#        Date    : 2014-09-19 18:10
#        Version : 1.0v
#
#    Description : Demonstrate the Rational Bezier Curve with different weights.
#


pload ALL

set w1 
0.1
set w2 
0.5
set w3 
1.0
set w4 
2.0
set w5 
5.0

set u 
0.5

#  4 Bezier Curve with defferent Weighted Poles: 
# {P(1,0), w(1)}, {P(1,1), w($w)}, {P{0,1}, w(1)}

2dbeziercurve bc1  3   1   0   1   1   1   $w1   0   1   1
2dbeziercurve bc2 
3   1   0   1   1   1   $w2   0   1   1
2dbeziercurve bc3 
3   1   0   1   1   1   $w3   0   1   1
2dbeziercurve bc4 
3   1   0   1   1   1   $w4   0   1   1
2dbeziercurve bc5 
3   1   0   1   1   1   $w5   0   1   1

#  mark weight factor.
2dcvalue bc1  $u  x1 y1
2dcvalue bc2 
$u  x2 y2
2dcvalue bc3 
$u  x3 y3
2dcvalue bc4 
$u  x4 y4
2dcvalue bc5 
$u  x5 y5

dtext x1 y1 w1
= $w1
dtext x2 y2 w2
= $w2
dtext x3 y3 w3
= $w3
dtext x4 y4 w4
= $w4
dtext x5 y5 w5
= $w5

v2d
2dfit

上述代码显示了一条三个控制顶点2次的有理Bezier曲线当控制顶点P(1,1)对应的权因子ω变化时的不同的情况。当ω增大时,导致曲线被拉向控制顶点;当ω减小时,导致曲线被推离控制顶点。当ω趋于无穷大时,此时曲线将退化为与控制顶点重合的一个点。

5. Bezier Geometry Curve

OpenCASCADE中的Bezier曲线Geom_BezierCurve本身就是有理Bezier曲线,且都是基于BSplCLib包实现的。即有理Beizer曲线也是NURBS曲线的特例。如下图所示:

wps_clip_image-15867

当构造函数只有控制顶点时,将会构造一个非有理的Beizer曲线。当构造函数将控制顶点对应的权因子也设置进来时,将会构造一个有理Bezier曲线。当构造有理Beizer曲线时,若控制顶点的所有权值都相同,则认为是非有理Bezier曲线,即退化性质的体现。

6. Conclusion

综上所述,由齐次坐标表示法来理解有理Bezier曲线的概念还是比较直观的,进而可以去理解NURBS曲线曲面的概念。

有理Beizer曲线与非有理Bezier曲线的区别就是权因子。若控制点对应的权因子都相同时,有理Beizer曲线退化为非有理Bezier曲线。且权因子的值越大,则曲线越接近对应的控制顶点。权因子对曲线还有很多重要性质,读者可以参考其他相关书籍。

OpenCASCADE中的Beizer曲线是基于BSplCLib包实现的,即是NURBS曲线的特例。所以可以表示有理有非有理的Bezier曲线。

7. References

1. 数学手册编写组. 数学手册. 高等教育出版社. 1979

2. 丘维声. 解析几何. 北京大学出版社. 1996

3. 苏步青,刘鼎元. 计算几何. 上海科学技术出版社. 1981

4. 苏步青,华宣积. 应用几何教程. 复旦大学出版社. 2012

5. 莫蓉,常智勇. 计算机辅助几何造型技术. 科学出版社. 2009

6. 王仁宏,李崇君,朱春钢. 计算几何教程. 科学出版社. 2008

7. 赵罡,穆国旺,王拉柱译. 非均匀有理B样条. 清华大学出版社. 2010

8. 朱心雄等. 自由曲线曲面造型技术. 科学出版社. 2000

9. 孙家广. 计算机图形学. 清华大学出版社. 2000

10. 孙家广. 计算机辅助几何造型技术. 清华大学出版社. 2000

11. 王国瑾,汪国昭,郑建民. 计算机辅助几何设计. CHEP & Springer-Verlag. 2001

12. Les Piegl, Wayne Tiller. The NURBS Book. Springer-Verlag. 1997

13. Kelly Dempski. Focus on Curves and Surfaces. Premier Press. 2003

14. OpenCASCADE. Test Harness User’s Guide 6.7.1. 2014

15. OpenCASCADE. ModelingData User’s Guide 6.7.1. 2014

 

PDF Version and Tcl Scripts: OpenCASCADE Rational Bezier Curves

目录
相关文章
|
算法
Convert BSpline Curve to Arc Spline in OpenCASCADE
Convert BSpline Curve to Arc Spline in OpenCASCADE eryar@163.com Abstract. The paper based on OpenCASCADE algorithms to approximate the NURBS curve to arc spline.
1477 0
|
C++ 算法
OpenCASCADE BRep Projection
OpenCASCADE BRep Projection eryar@163.com 一网友发邮件问我下图所示的效果如何在OpenCASCADE中实现,我的想法是先构造出螺旋线,再将螺旋线投影到面上。
1673 0
|
算法
OpenCASCADE Interpolation - Lagrange
OpenCASCADE Interpolation - Lagrange eryar@163.com Abstract. Power basis polynomial is the most simple polynomial function.
1330 0
|
XML Java Shell
OpenCASCADE BRepTools
OpenCASCADE BRepTools eryar@163.com Abstract. OpenCASCADE BRepTools provides utilities for BRep data structure.
1454 0
|
图形学
OpenCASCADE Coordinate Transforms
OpenCASCADE Coordinate Transforms eryar@163.com Abstract. The purpose of the OpenGL graphics processing pipeline is to convert 3D descriptions of objects into a 2D image that can be displayed.
1487 0
|
算法 数据可视化 Shell
OpenCASCADE Linear Extrusion Surface
OpenCASCADE Linear Extrusion Surface eryar@163.com Abstract. OpenCASCADE linear extrusion surface is a generalized cylinder.
1265 0
|
存储 算法 BI
OpenCASCADE Conic to BSpline Curves-Circle
OpenCASCADE Conic to BSpline Curves-Circle eryar@163.com Abstract. The conic sections and circles play a fundamental role in CAD/CAM applications.
1438 0
|
算法
OpenCASCADE Conic to BSpline Curves-Hyperbola
OpenCASCADE Conic to BSpline Curves-Hyperbola eryar@163.com Abstract. Rational Bezier Curve can represent conic curves such as circle, ellipse, hyperbola, .
1090 0
|
C语言 Windows 开发工具
OpenCASCADE Conic to BSpline Curves-Parabola
OpenCASCADE Conic to BSpline Curves-Parabola eryar@163.com Abstract. Rational Bezier Curve can represent conic curves such as circle, ellipse, hyperbola, .
1007 0
OpenCASCADE Gauss Integration
OpenCASCADE Gauss Integration eryar@163.com Abstract. Numerical integration is the approximate computation of an integral using numerical techniques.
1280 0