| // Created on: 1992-09-02 | |
| // Created by: Remi GILET | |
| // Copyright (c) 1992-1999 Matra Datavision | |
| // Copyright (c) 1999-2014 OPEN CASCADE SAS | |
| // | |
| // This file is part of Open CASCADE Technology software library. | |
| // | |
| // This library is free software; you can redistribute it and/or modify it under | |
| // the terms of the GNU Lesser General Public License version 2.1 as published | |
| // by the Free Software Foundation, with special exception defined in the file | |
| // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
| // distribution for complete text of the license and disclaimer of any warranty. | |
| // | |
| // Alternatively, this file may be used under the terms of Open CASCADE | |
| // commercial license or contractual agreement. | |
| #include <ElCLib.hxx> | |
| #include <gce_MakeCirc2d.hxx> | |
| #include <gp.hxx> | |
| #include <gp_Ax2d.hxx> | |
| #include <gp_Ax22d.hxx> | |
| #include <gp_Circ2d.hxx> | |
| #include <gp_Lin2d.hxx> | |
| #include <gp_Pnt2d.hxx> | |
| #include <IntAna2d_AnaIntersection.hxx> | |
| #include <IntAna2d_IntPoint.hxx> | |
| #include <StdFail_NotDone.hxx> | |
| //================================================================================================= | |
| gce_MakeCirc2d::gce_MakeCirc2d(const gp_Pnt2d& P1, const gp_Pnt2d& P2, const gp_Pnt2d& P3) | |
| { | |
| gp_Dir2d dirx(gp_Dir2d::D::X); | |
| // Three cases: | |
| // 1) All three points are coincident: result is a circle centered at P1 with zero radius. | |
| // 2) Two of the three points are coincident: create the perpendicular bisector of the two | |
| // distinct points and the line through them. The center is their intersection. | |
| // 3) All three points are distinct: create the perpendicular bisector of P1P2 and | |
| // the perpendicular bisector of P1P3. The center is their intersection and | |
| // the radius is the distance from that center to any of the three points. | |
| double dist1 = P1.Distance(P2); | |
| double dist2 = P1.Distance(P3); | |
| double dist3 = P2.Distance(P3); | |
| if ((dist1 < gp::Resolution()) && (dist2 < gp::Resolution()) && (dist3 < gp::Resolution())) | |
| { | |
| TheCirc2d = gp_Circ2d(gp_Ax2d(P1, dirx), 0.0); | |
| TheError = gce_Done; | |
| } | |
| else | |
| { | |
| gp_Lin2d L1; | |
| gp_Lin2d L2; | |
| double x1, y1, x2, y2, x3, y3; | |
| P1.Coord(x1, y1); | |
| P2.Coord(x2, y2); | |
| P3.Coord(x3, y3); | |
| if (dist1 > gp::Resolution()) | |
| { | |
| L1 = | |
| gp_Lin2d(gp_Pnt2d((P1.XY() + P2.XY()) / 2.0), gp_Dir2d(P1.Y() - P2.Y(), P2.X() - P1.X())); | |
| } | |
| if (dist2 > gp::Resolution()) | |
| { | |
| L2 = | |
| gp_Lin2d(gp_Pnt2d((P1.XY() + P3.XY()) / 2.0), gp_Dir2d(P1.Y() - P3.Y(), P3.X() - P1.X())); | |
| } | |
| if (dist2 <= gp::Resolution()) | |
| { | |
| L2 = gp_Lin2d(P1, gp_Dir2d(P1.Y() - P2.Y(), P2.X() - P1.X())); | |
| } | |
| else if (dist1 <= gp::Resolution()) | |
| { | |
| L1 = gp_Lin2d(P1, gp_Dir2d(P1.Y() - P3.Y(), P3.X() - P1.X())); | |
| } | |
| else if (dist3 <= gp::Resolution()) | |
| { | |
| L2 = gp_Lin2d(P1, gp_Dir2d(P1.Y() - P2.Y(), P2.X() - P1.X())); | |
| } | |
| IntAna2d_AnaIntersection Intp(L1, L2); | |
| if (Intp.IsDone()) | |
| { | |
| if (!Intp.IsEmpty()) | |
| { | |
| gp_Pnt2d pInt(Intp.Point(1).Value()); | |
| dist1 = P1.Distance(pInt); | |
| dist2 = P2.Distance(pInt); | |
| dist3 = P3.Distance(pInt); | |
| double xc, yc; | |
| pInt.Coord(xc, yc); | |
| gp_Dir2d d1(x1 - xc, y1 - yc); | |
| gp_Dir2d d2(xc - x3, yc - y3); | |
| TheCirc2d = gp_Circ2d(gp_Ax22d(pInt, d1, d2), (dist1 + dist2 + dist3) / 3.); | |
| double Alpha1 = ElCLib::Parameter(TheCirc2d, P1); | |
| double Alpha2 = ElCLib::Parameter(TheCirc2d, P2); | |
| double Alpha3 = ElCLib::Parameter(TheCirc2d, P3); | |
| if ((Alpha1 > Alpha2) || (Alpha2 > Alpha3)) | |
| { | |
| TheCirc2d.Reverse(); | |
| } | |
| TheError = gce_Done; | |
| } | |
| } | |
| else | |
| { | |
| TheError = gce_IntersectionError; | |
| } | |
| } | |
| } | |
| //================================================================================================= | |
| gce_MakeCirc2d::gce_MakeCirc2d(const gp_Ax2d& XAxis, const double Radius, const bool Sense) | |
| { | |
| if (Radius >= 0.) | |
| { | |
| TheCirc2d = gp_Circ2d(XAxis, Radius, Sense); | |
| TheError = gce_Done; | |
| } | |
| else | |
| { | |
| TheError = gce_NegativeRadius; | |
| } | |
| } | |
| //================================================================================================= | |
| gce_MakeCirc2d::gce_MakeCirc2d(const gp_Ax22d& Axis, const double Radius) | |
| { | |
| if (Radius >= 0.) | |
| { | |
| TheCirc2d = gp_Circ2d(Axis, Radius); | |
| TheError = gce_Done; | |
| } | |
| else | |
| { | |
| TheError = gce_NegativeRadius; | |
| } | |
| } | |
| //================================================================================================= | |
| gce_MakeCirc2d::gce_MakeCirc2d(const gp_Pnt2d& Center, const double Radius, const bool Sense) | |
| { | |
| if (Radius >= 0.) | |
| { | |
| TheCirc2d = gp_Circ2d(gp_Ax2d(Center, gp_Dir2d(gp_Dir2d::D::X)), Radius, Sense); | |
| TheError = gce_Done; | |
| } | |
| else | |
| { | |
| TheError = gce_NegativeRadius; | |
| } | |
| } | |
| //================================================================================================= | |
| gce_MakeCirc2d::gce_MakeCirc2d(const gp_Pnt2d& Center, const gp_Pnt2d& Point, const bool Sense) | |
| { | |
| TheCirc2d = gp_Circ2d(gp_Ax2d(Center, gp_Dir2d(gp_Dir2d::D::X)), Point.Distance(Center), Sense); | |
| TheError = gce_Done; | |
| } | |
| //================================================================================================= | |
| gce_MakeCirc2d::gce_MakeCirc2d(const gp_Circ2d& Circ, const gp_Pnt2d& Point) | |
| { | |
| TheCirc2d = gp_Circ2d(Circ.Axis(), Point.Distance(Circ.Location())); | |
| TheError = gce_Done; | |
| } | |
| //================================================================================================= | |
| gce_MakeCirc2d::gce_MakeCirc2d(const gp_Circ2d& Circ, const double Dist1) | |
| { | |
| TheCirc2d = gp_Circ2d(Circ.Axis(), std::abs(Circ.Radius() + Dist1)); | |
| TheError = gce_Done; | |
| } | |
| //================================================================================================= | |
| const gp_Circ2d& gce_MakeCirc2d::Value() const | |
| { | |
| StdFail_NotDone_Raise_if(TheError != gce_Done, "gce_MakeCirc2d::Value() - no result"); | |
| return TheCirc2d; | |
| } |