110 lines
3.9 KiB
C++
110 lines
3.9 KiB
C++
//-------------------------------------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
|
|
// = FileName : 内部全局函数实现文件
|
|
// = Version : ver2.0
|
|
// = Author : tg
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: 内部全局函数的定义
|
|
// = Maintainers:
|
|
//
|
|
//-------------------------------------------------------------------------------------------------------+
|
|
#ifndef _TCHSUBPRIVATEGLOBALFUNC_H_
|
|
#define _TCHSUBPRIVATEGLOBALFUNC_H_
|
|
|
|
namespace TchSubPrivate
|
|
{
|
|
int CompareEdge(const TPGeDscEdge&e0,const TPGeDscEdge&e1);
|
|
|
|
//由曲线集求平面域,最后曲线集将置空
|
|
//如果可能有顺时针的环路,则应选择检查洞
|
|
//曲线集中的每条曲线只能作为一个面域的边界,因此可能有多个环路时,关键曲线要排在前面,使关键曲线先被遍历!
|
|
//曲线集中的曲线应两两之间无重合,无交叉(非端点交点)!
|
|
//不支持开放域!
|
|
void CreateRegion2D(TGObjectList&curves,TGObjectList&res,bool bCheckHole);
|
|
//支持开放域,其余同上
|
|
void CreateRegion2DEx(TGObjectList&curves,TGObjectList&res,bool bCheckHole);
|
|
double GetAngle(const TPGeDscEdge&e0,const TPGeDscEdge&e1);
|
|
|
|
void InitCircle2D(const TGPoint&pt0,const TGPoint&pt1,double angle,TGPoint¢er,double&r);
|
|
void InitCircle2D(const TGPoint&pt0,const TGPoint&pt1,const TGPoint&pt2,TGPoint¢er,double&r);
|
|
|
|
int CircleInt(const TGPoint¢er1,double r1,const TGPoint¢er2,double r2,TGPoint&pt1,TGPoint&pt2);
|
|
int LineInt3D(const TGPoint&pt1,const TGVector3D&vt1,const TGPoint&pt2,const TGVector3D&vt2,double&pa1);
|
|
int LinePlaneInt3D(double A,double B,double C,double D,const TGPoint&pt0,const TGVector3D&vt,TGPoint&pt);
|
|
int LinePlaneInt3D(double A,double B,double C,double D,const TGPoint&pt0,const TGVector3D&vt,double&pa);
|
|
|
|
int PlaneInt(double A1,double B1,double C1,double D1,double A2,double B2,double C2,double D2,TGPoint&pt,TGVector3D&vt);
|
|
//求交
|
|
int LineInt2D(const TGPoint&pt1,const TGVector2D&vt1,const TGPoint&pt2,const TGVector2D&vt2,double&pa1);
|
|
int LineInt2D(const TGPoint&pt1,const TGVector2D&vt1,const TGPoint&pt2,const TGVector2D&vt2,double&pa1,double&pa2);
|
|
|
|
int LineCirInt2D(const TGPoint¢er,double r,const TGPoint&pt,const TGVector2D&vt,double&pa1,double&pa2);
|
|
int LineCirInt2D(const TGPoint¢er,double r,const TGPoint&pt,const TGVector2D&vt,TGPoint&pt1,TGPoint&pt2);
|
|
|
|
bool LB_IsOk(const double &dn,const double &nw,double &tl,double &tu);
|
|
|
|
inline AcGePoint3d GP3AP(const TGPoint&pt)
|
|
{
|
|
return AcGePoint3d(pt.x,pt.y,pt.z);
|
|
}
|
|
|
|
inline AcGePoint2d GP2AP(const TGPoint&pt)
|
|
{
|
|
return AcGePoint2d(pt.x,pt.y);
|
|
}
|
|
|
|
//直线起点,直线方向
|
|
inline void LinePa2D(const TGPoint &pt0,const TGVector2D&vt,const TGPoint& pt,double &pa)
|
|
{
|
|
if (fabs(vt.y) > fabs(vt.x))
|
|
{
|
|
pa = (pt.y - pt0.y) / vt.y;
|
|
}
|
|
else
|
|
{
|
|
pa = (pt.x - pt0.x) / vt.x;
|
|
}
|
|
}
|
|
|
|
inline double Distance2D(const TGPoint&pt0,const TGPoint&pt1)
|
|
{
|
|
double dx = pt0.x - pt1.x,dy = pt0.y - pt1.y;
|
|
return sqrt(dx * dx + dy * dy);
|
|
}
|
|
|
|
inline double Distance3D(const TGPoint&pt0,const TGPoint&pt1)
|
|
{
|
|
double dx = pt0.x - pt1.x, dy = pt0.y - pt1.y, dz = pt0.z - pt1.z;
|
|
return sqrt(dx * dx + dy * dy + dz * dz);
|
|
}
|
|
|
|
//直线起点,直线方向
|
|
inline void LinePt2D(const TGPoint &pt0,const TGVector2D&vt,double pa,TGPoint&pt)
|
|
{
|
|
pt.x = pt0.x + vt.x * pa;
|
|
pt.y = pt0.y + vt.y * pa;
|
|
pt.z = pt0.z;
|
|
}
|
|
|
|
inline double LineIntegration2D(const TGPoint&pt0,const TGVector2D&vt,double pa0,double pa1)
|
|
{
|
|
const double &x0 = pt0.x,&y0 = pt0.y,&a = vt.x,&b = vt.y;
|
|
if (EQUAL_ZERO(a)) //直线平行于Y轴
|
|
{
|
|
return 0;
|
|
}
|
|
double m = pa1 - pa0, n = pa1 + pa0;
|
|
return a * m * (y0 + b * n / 2);
|
|
}
|
|
|
|
//参数pa0,pa1为以圆心为原点的右手极坐标系的弧度分量
|
|
inline double CircleIntegration2D(const TGPoint¢er,double r,double pa0,double pa1)
|
|
{
|
|
double A = center.y * cos(pa0) - r * pa0 / 2 + r * sin(2 * pa0) / 4;
|
|
double B = center.y * cos(pa1) - r * pa1 / 2 + r * sin(2 * pa1) / 4;
|
|
|
|
return r * (B - A);
|
|
}
|
|
}
|
|
|
|
#endif |