|
- AcGePoint2d FymGeometry::GetMiddlePt(const AcGePoint2d& startPt, const AcGePoint2d& endPt)
- {
- double x = (startPt.x + endPt.x) * 0.5;
- double y = (startPt.y + endPt.y) * 0.5;
- return AcGePoint2d(x, y);
- }
-
- AcGePoint3d FymGeometry::GetMiddlePt(const AcGePoint3d& startPt, const AcGePoint3d& endPt)
- {
- double x = (startPt.x + endPt.x) * 0.5;
- double y = (startPt.y + endPt.y) * 0.5;
- double z = (startPt.z + endPt.z) * 0.5;
- return AcGePoint3d(x, y, z);
- }
-
- AcGePoint3d FymGeometry::Polar(const AcGePoint3d& basePoint, double angle, double length)
- {
- double x = basePoint.x + length * cos(angle);
- double y = basePoint.y + length * sin(angle);
- return AcGePoint3d(x,y,basePoint.z);
- }
-
- AcGePoint3d FymGeometry::RelativePoint(const AcGePoint3d& Pt, double x, double y)
- {
- AcGePoint3d ptReturn(Pt.x + x, Pt.y + y, Pt.z);
- return ptReturn;
- }
- //比较两个AcGePoint2d类型的点(即二维坐标点)是否相等,tol为公差
- bool CGePointUtil::IsEqual(const AcGePoint2d & firstPoint, const AcGePoint2d & secondPoint, double tol)
- {
- return (fabs(firstPoint.x - secondPoint.x) < tol&&
- fabs(firstPoint.y - secondPoint.y) < tol);
- }
- //比较两个AcGePoint3d类型的点(即三维坐标点)是否相等。
- bool CGePointUtil::IsEqual(const AcGePoint3d & firstPoint, const AcGePoint3d & secondPoint, double tol)
- {
- return (fabs(firstPoint.x - secondPoint.x) < tol&&
- fabs(firstPoint.y - secondPoint.y) < tol&&
- fabs(firstPoint.z - firstPoint.z) < tol);
- }
- //在给定的三维点数组points中查找一个特定的三维点point。如果找到了这个点,函数会返回这个点的索引值;如果没有找到,函数会返回-1。
- int CGePointUtil::FindPoint(const AcGePoint3dArray & points, const AcGePoint3d & point, double tol)
- {
- for (int i = 0; i < points.length(); i++)
- {
-
- if (IsEqual(points[i], point, tol)) {
- return i;
- }
-
- }
- return -1;
- }
- //在给定的二维点数组points中查找一个特定的二维点point。如果找到了这个点,函数会返回这个点的索引值;如果没有找到,函数会返回-1。
- int CGePointUtil::FindPoint(const AcGePoint2dArray & points, const AcGePoint2d & point, double tol)
- {
- for (int i = 0; i < points.length(); i++)
- {
-
- if (IsEqual(points[i], point, tol)) {
- return i;
- }
-
- }
- return -1;
- }
- // 过滤掉那些在给定的公差范围内的重复点。
- void CGePointUtil::FilterEqualPoints(AcGePoint3dArray & points, double tol)
- {
- for (int i = points.length() - 1; i > 0; i--) {
- // 遍历数组中的每个点,从最后一个开始
- for (int j = 0; j < i; j++) {
-
- if (MathUtil::IsEqual(points[i].x, points[j].x, tol) &&
- MathUtil::IsEqual(points[i].y, points[j].y, tol)) {
- //检查当前点(i)和另一个点(j)的x和y坐标是否在给定的公差范围内是否相等。
- points.removeAt(i); //移除当前点(i),删除重复的点
- break;
- }
-
- }
-
- }
-
- }
- //遍历一个包含三维点的数组,并删除所有与给定的二维点距离在给定的公差范围内的三维点
- void CGePointUtil::FilterEqualPoints(AcGePoint3dArray & points, const AcGePoint2d & pt, double tol)
- {
-
- AcGePoint3dArray tempPoints; //存储过滤后的非重复三维点
-
- for (int i = 0; i < points.length(); i++)
- {
- //距离大于给定的公差tol,那么它将这个三维点添加到临时数组tempPoints中
- if (CConvertUtil::ToPoint2d(points[i]).distanceTo(pt)>tol) {
-
- tempPoints.append(points[i]);
- }
- }
-
- points = tempPoints;
- //这样输入数组points现在就只包含那些距离给定的二维点pt大于给定公差的非重复三维点
- }
复制代码 |
|