Function Set in OPEN CASCADE
Function Set in OPEN CASCADE
Abstract. The common math algorithms library provides a C++ implementation of the most frequently used mathematical algorithms. These include: algorithms to solve a set of linear algebraic equations, algorithms to find the minimum of a function of one or more independent variables, algorithms to find roots of one, or of a set of non-linear equations, algorithm to find the eigenvalues and eigenvectors of a square matrix. The solver for function set is used widely in extrema value evaluation, point project on to curve and surface, also used to solve the point inverse for geometry curve and surface. The paper focus on the function set concept and its solver in OPEN CASCADE.
Key Words. Function Set, Non-Linear Equation Solver, Equations Root,
1. Introduction
OPEN CASCADE的math包中提供了常见的数值计算的功能,如矩阵的加减乘除,转置及方阵的特征值和特征向量的计算,求解线性方程组;一元函数或多元函数的微分、积分及极值的计算;线性和非线性(Non-Linear Equations)方程组(Function Set)的计算等等。大部分功能和另一个开源科学计算库gsl类似,只是采用面向对象的方式,更便于使用。方程组(Function Set)的相关计算与多元函数(MultiVarFunction)一样地在OPEN CASCADE库广泛地应用,如一些极值计算算法,拟合算法、点在曲线曲面上投影的相关问题等等,都会涉及到方程组求解的计算。如下类图所示。
下面的类图为方程组类Math_FunctionSet的类图,由类图可知,从其派生的类数量很多,由此可见其在OPEN CASCADE中的重要性。本文主要对其用法进行说明,理解其用法后,便于对其他相关算法的理解。
在理解math包中大部分算法后,也是掌握了一个数学计算工具,以后遇到相关的问题,可以尽量地用数学的方式进行解决,提高数学的应用水平。
![]()
Figure 1.1 math_FunctionSet class diagram in OPENCASCADE
2. Function Set
很多科学理论和工程技术问题都最终转化成非线性方程或方程组的求解,如对理论数据或实验观察的数据进行拟合用到的最小二乘法,就是一个典型的非线性方程组求解的问题。而在几何中的应用就更广泛了,像计算直线与平面的交点问题,点到自由曲线曲面的投影问题等等。鉴于方程组的广泛应用,OPEN CASCADE的数学包中提供了一个抽象类math_FunctionSet来与之对应,方便方程组在程序中的计算。
![]()
对于普通的方程组,主要设置了三个抽象函数:
v NbVariables():方程组中变量的个数;
v NbEquations():方程组中方程的个数;
v Value():计算指定变量的方程组的值;
带微分的方程组类比普通方程组多两个抽象函数:
v Derivatives():计算指定变量的方程组的微分值;
v Values():计算指定变量的方程组的值和微分值;
因为都是抽象类,所以不能直接使用。下面结合《计算方法》书中的题目,来说明方程组在OPENCASCADE中的计算方法。下面的题目来自《计算方法》第二版P213页例17:设有非线性方程组:
![]()
从几何上看其解就是圆和曲线的交点。下面给出OPENCASCADE中的计算代码:
/*
* Copyright (c) 2016 Shing Liu All Rights Reserved.
*
* File : main.cpp
* Author : Shing Liu(eryar@163.com)
* Date : 2016-01-12 21:00
* Version : OpenCASCADE6.9.0
*
* Description : test function set.
*/
#define WNT
#include <math_FunctionSetRoot.hxx>
#include <math_FunctionSetWithDerivatives.hxx> #pragma comment(lib, "TKernel.lib")
#pragma comment(lib, "TKMath.lib") /**
* @brief test function for a circle and a curve:
*
* F1(x1,x2) = (x1)^2 + (x2)^2 -4
* F2(x1,x2) = e^(x1) + x2 - 1
*
* The derivatives of the function set are:
* Dx1f1(x1,x2) = 2.0 * x1
* Dx2f1(x1,x2) = 2.0 * x2
* Dx1f2(x1,x2) = e^(x1)
* Dx2f2(x1,x2) = 1.0
*/
class test_FunctionSet: public math_FunctionSetWithDerivatives
{
public:
virtual Standard_Integer NbVariables() const
{
return ;
} virtual Standard_Integer NbEquations() const
{
return ;
} virtual Standard_Boolean Value(const math_Vector& X, math_Vector& F)
{
F() = X() * X() + X() * X() - 4.0;
F() = exp(X()) + X() - 1.0; return Standard_True;
} virtual Standard_Boolean Derivatives(const math_Vector& X, math_Matrix& D)
{
D(,) = 2.0 * X();
D(,) = 2.0 * X();
D(,) = exp(X());
D(,) = 1.0; return Standard_True;
} virtual Standard_Boolean Values(const math_Vector& X, math_Vector& F, math_Matrix& D)
{
Value(X, F);
Derivatives(X, D); return Standard_True;
}
}; void testFunctionSet(void)
{
test_FunctionSet aTestFunctionSet; math_FunctionSetRoot aSolver(aTestFunctionSet);
math_Vector aStartPoint(, , 0.0); // initial guess point(-2.0, 0.0)
aStartPoint() = -2.0;
aStartPoint() = 0.0;
aSolver.Perform(aTestFunctionSet, aStartPoint);
std::cout << aSolver << std::endl; // initial guess point(0.0, -2.0)
aStartPoint() = 0.0;
aStartPoint() = -2.0;
aSolver.Perform(aTestFunctionSet, aStartPoint);
std::cout << aSolver << std::endl;
} int main(int argc, char* argv[])
{
testFunctionSet();
return ;
}
计算结果如下图所示:
![]()
Figure 2.1 Evaluate result
3. Application
在曲线和曲面的极值计算、曲面和曲面的极值计算及点和曲面的极值计算中都用到了求解方程组的算法,如下类图所示:
![]()
Figure 3.1 Extrema algorithms implemented by Function Set
其中点和曲面极值的计算也适用于曲面上点的参数的反求。与曲线上点的参数反求类似,曲线上点的参数反求是计算非线性方程的根;曲面上点的参数反求则扩展到了非线性方程组。问题求解的关键还是建立数学模型,如点到曲线上的投影由下图可知:
![]()
Figure 3.2 Point project on curve
构造的函数为:
![]()
上式表示曲线上过参数u的切线与曲线上参数u的点到指定点的向量的数量积,当f(u)=0时数量积为0,即为点垂直于曲线上过参数u的切线,对此非线性方程求解,即得到了点到曲线的投影。同理,点到曲面的投影也可以建立类似的方程组:
![]()
其中曲面对参数u,v的偏导数表示在曲面在u,v方向上的切线,两个函数意义和一个方程的意义类似,即点到曲面上某一点的向量与切线的数量积。当向量与两个切线方向的数量积为0的时候,即此向量与这两个切线都垂直,就是点到曲面的投影。这也是OPEN CASCADE中计算点与曲面极值的实现原是,其类为Extrema_FuncExtPS,为了使用类math_FunctionSetRoot对方程组进行求解,Extrema_FuncExtPS也是由类math_FunctionSetWithDerivatives派生,类定义代码如下:
//! Functional for search of extremum of the distance between point P and
//! surface S, starting from approximate solution (u0, v0).
//!
//! The class inherits math_FunctionSetWithDerivatives and thus is intended
//! for use in math_FunctionSetRoot algorithm .
//!
//! Denoting derivatives of the surface S(u,v) by u and v, respectively, as
//! Su and Sv, the two functions to be nullified are:
//!
//! F1(u,v) = (S - P) * Su
//! F2(u,v) = (S - P) * Sv
//!
//! The derivatives of the functional are:
//!
//! Duf1(u,v) = Su^2 + (S-P) * Suu;
//! Dvf1(u,v) = Su * Sv + (S-P) * Suv
//! Duf2(u,v) = Sv * Su + (S-P) * Suv = Dvf1
//! Dvf2(u,v) = Sv^2 + (S-P) * Svv
//!
//! Here * denotes scalar product, and ^2 is square power.
class Extrema_FuncExtPS : public math_FunctionSetWithDerivatives
{
public: DEFINE_STANDARD_ALLOC Standard_EXPORT Extrema_FuncExtPS(); Standard_EXPORT Extrema_FuncExtPS(const gp_Pnt& P, const Adaptor3d_Surface& S); //! sets the field mysurf of the function.
Standard_EXPORT void Initialize (const Adaptor3d_Surface& S); //! sets the field mysurf of the function.
Standard_EXPORT void SetPoint (const gp_Pnt& P); Standard_EXPORT Standard_Integer NbVariables() const Standard_OVERRIDE; Standard_EXPORT Standard_Integer NbEquations() const Standard_OVERRIDE; //! Calculate Fi(U,V).
Standard_EXPORT Standard_Boolean Value (const math_Vector& UV, math_Vector& F) Standard_OVERRIDE; //! Calculate Fi'(U,V).
Standard_EXPORT Standard_Boolean Derivatives (const math_Vector& UV, math_Matrix& DF) Standard_OVERRIDE; //! Calculate Fi(U,V) and Fi'(U,V).
Standard_EXPORT Standard_Boolean Values (const math_Vector& UV, math_Vector& F, math_Matrix& DF) Standard_OVERRIDE; //! Save the found extremum.
Standard_EXPORT virtual Standard_Integer GetStateNumber() Standard_OVERRIDE; //! Return the number of found extrema.
Standard_EXPORT Standard_Integer NbExt() const; //! Return the value of the Nth distance.
Standard_EXPORT Standard_Real SquareDistance (const Standard_Integer N) const; //! Returns the Nth extremum.
Standard_EXPORT const Extrema_POnSurf& Point (const Standard_Integer N) const; protected: private:
gp_Pnt myP;
Adaptor3d_SurfacePtr myS;
Standard_Real myU;
Standard_Real myV;
gp_Pnt myPs;
TColStd_SequenceOfReal mySqDist;
Extrema_SequenceOfPOnSurf myPoint;
Standard_Boolean myPinit;
Standard_Boolean mySinit;
};
根据其注释可知,建立的方程组和上述方程组相同,并且还计算了方程组的一阶偏导数如下:
![]()
通过类math_FunctionSetRoot对上述方程组进行求解,即可得到点到曲面的极值。
4. Conclusion
线性和非线性方程组的求解在几何中也有大量的应用。线性方程组可以利用矩阵的概念进行求解,如Gauss消元法。而非线性方程组的求解也是有相关的算法,如Newton法等,具体理论可参考《计算方法》等相关书籍。掌握这些数学工具之后,关键是将几何问题抽象成数学问题,然后利用这些数学工具来解决实际问题。从而可以将《高等数学》、《线性代数》等理论知识,通过《计算方法》在计算机中的实现,来用理论指导实践,通过实践加深理论的理解。也让枯燥的理论更生动、有趣。
与OPEN CASCADE数学包中其他概念如一元函数,多元函数等概念一样,非线性方程组及其求解也是一个重要概念。理解这些类的原理之后,便于对其他几何造型算法的实现原理进行理解。
5. References
1. 赵罡, 穆国旺, 王拉柱译. 非均匀有理B样条. 清华大学出版社. 1995
2. 易大义, 陈道琦. 数值分析引论. 浙江大学出版社. 1998
3. 易大义,沈云宝,李有法. 计算方法. 浙江大学出版社. 2002
4. 蒋尔雄,赵风光,苏仰锋. 数值逼近. 复旦大学出版社. 2012
5. 王仁宏,李崇君,朱春钢. 计算几何教程. 科学出版社. 2008
6. 同济大学数学教研室. 高等数学. 高等教育出版社. 1996
7. 同济大学应用数学系. 线性代数. 高等教育出版社. 2003
PDF Version: Function Set in OPEN CASCADE
Function Set in OPEN CASCADE的更多相关文章
- Apply Newton Method to Find Extrema in OPEN CASCADE
Apply Newton Method to Find Extrema in OPEN CASCADE eryar@163.com Abstract. In calculus, Newton’s me ...
- JS制作的简单的三级及联
前台: <form id="form1" runat="server"> <div> 省 <select id="Pro ...
- PLSQL面向对象
```sql --定义可被SQL语句调用的子程序 create or replace function getempdept( p_empno emp.empno%type )return ...
- PL/SQL详细介绍,设置oracle相关
1. 实现参照完整性 指若两个表之间具有主从关系(即主外键关系),当删除主表数据时,必须确保相关的从表数据已经被删除. 当修改主表的主键列数据时,必须确保相关从表数据已经被修改.为了实现级 ...
- jsTree checkbox plugin使用笔记
引入css文件 <link rel="stylesheet" type="text/css" href="js/assets/global/pl ...
- 通过百度echarts实现数据图表展示功能
现在我们在工作中,在开发中都会或多或少的用到图表统计数据显示给用户.通过图表可以很直观的,直接的将数据呈现出来.这里我就介绍说一下利用百度开源的echarts图表技术实现的具体功能. 1.对于不太理解 ...
- OPEN CASCADE Multiple Variable Function
OPEN CASCADE Multiple Variable Function eryar@163.com Abstract. Multiple variable function with grad ...
- OpenCascade B-Spline Basis Function
OpenCascade B-Spline Basis Function eryar@163.com Abstract. B-splines are quite a bit more flexible ...
- Open Cascade Data Exchange STL
Open Cascade Data Exchange STL eryar@163.com 摘要Abstract:介绍了三维数据交换格式STL的组成,以及Open Cascade中对STL的读写.并将O ...
随机推荐
- vmware里面的名词 vSphere、vCenter Server、ESXI、vSphere Client
vmware里面的名词 vSphere.vCenter Server.ESXI.vSphere Client vSphere.vCenter Server.ESXI.vSphere Client VS ...
- SSH实战 · 唯唯乐购项目(下)
后台模块 一:后台用户模块 引入后台管理页面 创建adminuser表: CREATE TABLE `adminuser` ( `uid` int(11) NOT NULL AUTO_INCREM ...
- angular2系列教程(十)两种启动方法、两个路由服务、引用类型和单例模式的妙用
今天我们要讲的是ng2的路由系统. 例子
- Linux 常用命令(持续补充)
常用命令: command &:将进程放在后台执行 ctrl + z:暂停当前进程 并放入后台 jobs:查看当前后台任务 bg( %id):将任务转为后台执行 fg( %id):将任务调回前 ...
- DDD 领域驱动设计-两个实体的碰撞火花
上一篇:<DDD 领域驱动设计-领域模型中的用户设计?> 开源地址:https://github.com/yuezhongxin/CNBlogs.Apply.Sample(代码已更新) 在 ...
- 挑子学习笔记:特征选择——基于假设检验的Filter方法
转载请标明出处: http://www.cnblogs.com/tiaozistudy/p/hypothesis_testing_based_feature_selection.html Filter ...
- 一款开源免费的.NET文档操作组件DocX(.NET组件介绍之一)
在目前的软件项目中,都会较多的使用到对文档的操作,用于记录和统计相关业务信息.由于系统自身提供了对文档的相关操作,所以在一定程度上极大的简化了软件使用者的工作量. 在.NET项目中如果用户提出了相关文 ...
- 自己来实现一个简易的OCR
来做个简易的字符识别 ,既然是简易的 那么我们就不能用任何的第三方库 .啥谷歌的 tesseract-ocr, opencv 之类的 那些玩意是叼 至少图像处理 机器视觉这类课题对我这种高中没毕业的人 ...
- equals变量在前面或者在后面有什么区别吗?这是一个坑点
我就不废话那么多,直接上代码: package sf.com.mainTest; public class Test { public static void main(String[] args) ...
- Android Studio切换为eclipse的快捷键之后还是有区别的部分快捷键
Android Studio Eclipse 把代码提示换成了Class Name Completion, 快捷键是Ctrl+Alt+Space(空格键). 代码提示快捷键Alt+/, ...