1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
20 #include <GProp_PEquation.hxx>
21 #include <GProp_PGProps.hxx>
22 #include <GProp_PrincipalProps.hxx>
23 #include <Standard_NoSuchObject.hxx>
25 GProp_PEquation::GProp_PEquation(const TColgp_Array1OfPnt& Pnts,
26 const Standard_Real Tol)
29 GProp_PGProps Pmat(Pnts);
30 g = Pmat.CentreOfMass();
31 Standard_Real Xg,Yg,Zg;
33 GProp_PrincipalProps Pp = Pmat.PrincipalProperties();
34 gp_Vec V1 = Pp.FirstAxisOfInertia();
35 Standard_Real Xv1,Yv1,Zv1;
36 V1.Coord(Xv1,Yv1,Zv1);
37 gp_Vec V2 = Pp.SecondAxisOfInertia();
38 Standard_Real Xv2,Yv2,Zv2;
39 V2.Coord(Xv2,Yv2,Zv2);
40 gp_Vec V3 = Pp.ThirdAxisOfInertia();
41 Standard_Real Xv3,Yv3,Zv3;
42 V3.Coord(Xv3,Yv3,Zv3);
43 Standard_Real D,X,Y,Z;
44 Standard_Real Dmx1 = RealFirst();
45 Standard_Real Dmn1 = RealLast();
46 Standard_Real Dmx2 = RealFirst();
47 Standard_Real Dmn2 = RealLast();
48 Standard_Real Dmx3 = RealFirst();
49 Standard_Real Dmn3 = RealLast();
51 for (Standard_Integer i = Pnts.Lower(); i <= Pnts.Upper();i++){
53 D = (X-Xg)*Xv1 +(Y-Yg)*Yv1 + (Z-Zg)*Zv1;
54 if (D > Dmx1) Dmx1 = D;
55 if (D < Dmn1) Dmn1 = D;
56 D = (X-Xg)*Xv2 +(Y-Yg)*Yv2 + (Z-Zg)*Zv2;
57 if (D > Dmx2) Dmx2 = D;
58 if (D < Dmn2) Dmn2 = D;
59 D = (X-Xg)*Xv3 +(Y-Yg)*Yv3 + (Z-Zg)*Zv3;
60 if (D > Dmx3) Dmx3 = D;
61 if (D < Dmn3) Dmn3 = D;
63 Standard_Integer dimension= 3 ;
64 Standard_Integer It = 0;
65 if (Abs(Dmx1-Dmn1) <= Tol) {
66 dimension =dimension-1;
69 if (Abs(Dmx2-Dmn2) <= Tol) {
70 dimension =dimension-1;
73 if (Abs(Dmx3-Dmn3) <= Tol) {
74 dimension =dimension-1;
87 else if (It == 6) v1 = V2;
95 else if (It == 2) v1 =V2;
102 g.SetXYZ(g.XYZ() + Dmn1*V1.XYZ() + Dmn2*V2.XYZ() + Dmn3*V3.XYZ());
110 Standard_Boolean GProp_PEquation::IsPlanar() const {
112 if (type == GProp_Plane) return Standard_True;
113 else return Standard_False;
116 Standard_Boolean GProp_PEquation::IsLinear() const {
118 if (type == GProp_Line) return Standard_True;
119 else return Standard_False;
122 Standard_Boolean GProp_PEquation::IsPoint() const {
124 if (type == GProp_Point) return Standard_True;
125 else return Standard_False;
128 Standard_Boolean GProp_PEquation::IsSpace() const {
129 if (type == GProp_Space) return Standard_True;
130 else return Standard_False;
133 gp_Pln GProp_PEquation::Plane() const {
134 if (!IsPlanar()) throw Standard_NoSuchObject();
137 gp_Lin GProp_PEquation::Line() const {
138 if (!IsLinear()) throw Standard_NoSuchObject();
139 return gp_Lin(g,gp_Dir(v1));
142 gp_Pnt GProp_PEquation::Point() const {
143 if (!IsPoint()) throw Standard_NoSuchObject();
147 void GProp_PEquation::Box(gp_Pnt& P , gp_Vec& V1,
148 gp_Vec& V2 , gp_Vec& V3) const {
149 if (!IsSpace()) throw Standard_NoSuchObject();