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)
28 GProp_PGProps Pmat(Pnts);
29 g = Pmat.CentreOfMass();
30 Standard_Real Xg,Yg,Zg;
32 GProp_PrincipalProps Pp = Pmat.PrincipalProperties();
33 gp_Vec V1 = Pp.FirstAxisOfInertia();
34 Standard_Real Xv1,Yv1,Zv1;
35 V1.Coord(Xv1,Yv1,Zv1);
36 gp_Vec V2 = Pp.SecondAxisOfInertia();
37 Standard_Real Xv2,Yv2,Zv2;
38 V2.Coord(Xv2,Yv2,Zv2);
39 gp_Vec V3 = Pp.ThirdAxisOfInertia();
40 Standard_Real Xv3,Yv3,Zv3;
41 V3.Coord(Xv3,Yv3,Zv3);
42 Standard_Real D,X,Y,Z;
43 Standard_Real Dmx1 = RealFirst();
44 Standard_Real Dmn1 = RealLast();
45 Standard_Real Dmx2 = RealFirst();
46 Standard_Real Dmn2 = RealLast();
47 Standard_Real Dmx3 = RealFirst();
48 Standard_Real Dmn3 = RealLast();
50 for (Standard_Integer i = Pnts.Lower(); i <= Pnts.Upper();i++){
52 D = (X-Xg)*Xv1 +(Y-Yg)*Yv1 + (Z-Zg)*Zv1;
53 if (D > Dmx1) Dmx1 = D;
54 if (D < Dmn1) Dmn1 = D;
55 D = (X-Xg)*Xv2 +(Y-Yg)*Yv2 + (Z-Zg)*Zv2;
56 if (D > Dmx2) Dmx2 = D;
57 if (D < Dmn2) Dmn2 = D;
58 D = (X-Xg)*Xv3 +(Y-Yg)*Yv3 + (Z-Zg)*Zv3;
59 if (D > Dmx3) Dmx3 = D;
60 if (D < Dmn3) Dmn3 = D;
62 Standard_Integer dimension= 3 ;
63 Standard_Integer It = 0;
64 if (Abs(Dmx1-Dmn1) <= Tol) {
65 dimension =dimension-1;
68 if (Abs(Dmx2-Dmn2) <= Tol) {
69 dimension =dimension-1;
72 if (Abs(Dmx3-Dmn3) <= Tol) {
73 dimension =dimension-1;
86 else if (It == 6) v1 = V2;
94 else if (It == 2) v1 =V2;
101 g.SetXYZ(g.XYZ() + Dmn1*V1.XYZ() + Dmn2*V2.XYZ() + Dmn3*V3.XYZ());
109 Standard_Boolean GProp_PEquation::IsPlanar() const {
111 if (type == GProp_Plane) return Standard_True;
112 else return Standard_False;
115 Standard_Boolean GProp_PEquation::IsLinear() const {
117 if (type == GProp_Line) return Standard_True;
118 else return Standard_False;
121 Standard_Boolean GProp_PEquation::IsPoint() const {
123 if (type == GProp_Point) return Standard_True;
124 else return Standard_False;
127 Standard_Boolean GProp_PEquation::IsSpace() const {
128 if (type == GProp_Space) return Standard_True;
129 else return Standard_False;
132 gp_Pln GProp_PEquation::Plane() const {
133 if (!IsPlanar()) throw Standard_NoSuchObject();
136 gp_Lin GProp_PEquation::Line() const {
137 if (!IsLinear()) throw Standard_NoSuchObject();
138 return gp_Lin(g,gp_Dir(v1));
141 gp_Pnt GProp_PEquation::Point() const {
142 if (!IsPoint()) throw Standard_NoSuchObject();
146 void GProp_PEquation::Box(gp_Pnt& P , gp_Vec& V1,
147 gp_Vec& V2 , gp_Vec& V3) const {
148 if (!IsSpace()) throw Standard_NoSuchObject();