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.
15 // JCV 07/12/90 Modifs suite a l'introduction des classes XYZ et Mat dans gp
20 #include <gp_Trsf.hxx>
23 #include <Standard_ConstructionError.hxx>
24 #include <Standard_DomainError.hxx>
25 #include <Standard_Dump.hxx>
26 #include <Standard_OutOfRange.hxx>
28 Standard_Real gp_Dir::Angle (const gp_Dir& Other) const
31 // Au dessus de 45 degres l'arccos donne la meilleur precision pour le
32 // calcul de l'angle. Sinon il vaut mieux utiliser l'arcsin.
33 // Les erreurs commises sont loin d'etre negligeables lorsque l'on est
34 // proche de zero ou de 90 degres.
35 // En 3d les valeurs angulaires sont toujours positives et comprises entre
37 Standard_Real Cosinus = coord.Dot (Other.coord);
38 if (Cosinus > -0.70710678118655 && Cosinus < 0.70710678118655)
39 return acos (Cosinus);
41 Standard_Real Sinus = (coord.Crossed (Other.coord)).Modulus ();
42 if(Cosinus < 0.0) return M_PI - asin (Sinus);
43 else return asin (Sinus);
47 Standard_Real gp_Dir::AngleWithRef (const gp_Dir& Other,
48 const gp_Dir& Vref) const
51 gp_XYZ XYZ = coord.Crossed (Other.coord);
52 Standard_Real Cosinus = coord.Dot(Other.coord);
53 Standard_Real Sinus = XYZ.Modulus ();
54 if (Cosinus > -0.70710678118655 && Cosinus < 0.70710678118655)
57 if(Cosinus < 0.0) Ang = M_PI - asin (Sinus);
58 else Ang = asin (Sinus);
60 if (XYZ.Dot (Vref.coord) >= 0.0) return Ang;
64 void gp_Dir::Mirror (const gp_Dir& V)
66 const gp_XYZ& XYZ = V.coord;
67 Standard_Real A = XYZ.X();
68 Standard_Real B = XYZ.Y();
69 Standard_Real C = XYZ.Z();
70 Standard_Real X = coord.X();
71 Standard_Real Y = coord.Y();
72 Standard_Real Z = coord.Z();
73 Standard_Real M1 = 2.0 * A * B;
74 Standard_Real M2 = 2.0 * A * C;
75 Standard_Real M3 = 2.0 * B * C;
76 Standard_Real XX = ((2.0 * A * A) - 1.0) * X + M1 * Y + M2 * Z;
77 Standard_Real YY = M1 * X + ((2.0 * B * B) - 1.0) * Y + M3 * Z;
78 Standard_Real ZZ = M2 * X + M3 * Y + ((2.0 * C * C) - 1.0) * Z;
79 coord.SetCoord(XX,YY,ZZ);
82 void gp_Dir::Mirror (const gp_Ax1& A1)
84 const gp_XYZ& XYZ = A1.Direction().coord;
85 Standard_Real A = XYZ.X();
86 Standard_Real B = XYZ.Y();
87 Standard_Real C = XYZ.Y();
88 Standard_Real X = coord.X();
89 Standard_Real Y = coord.Y();
90 Standard_Real Z = coord.Z();
91 Standard_Real M1 = 2.0 * A * B;
92 Standard_Real M2 = 2.0 * A * C;
93 Standard_Real M3 = 2.0 * B * C;
94 Standard_Real XX = ((2.0 * A * A) - 1.0) * X + M1 * Y + M2 * Z;
95 Standard_Real YY = M1 * X + ((2.0 * B * B) - 1.0) * Y + M3 * Z;
96 Standard_Real ZZ = M2 * X + M3 * Y + ((2.0 * C * C) - 1.0) * Z;
97 coord.SetCoord(XX,YY,ZZ);
100 void gp_Dir::Mirror (const gp_Ax2& A2)
102 const gp_Dir& Vz = A2.Direction();
107 void gp_Dir::Transform (const gp_Trsf& T)
109 if (T.Form() == gp_Identity || T.Form() == gp_Translation) { }
110 else if (T.Form() == gp_PntMirror) { coord.Reverse(); }
111 else if (T.Form() == gp_Scale) {
112 if (T.ScaleFactor() < 0.0) { coord.Reverse(); }
115 coord.Multiply (T.HVectorialPart());
116 Standard_Real D = coord.Modulus();
118 if (T.ScaleFactor() < 0.0) { coord.Reverse(); }
122 gp_Dir gp_Dir::Mirrored (const gp_Dir& V) const
129 gp_Dir gp_Dir::Mirrored (const gp_Ax1& A1) const
136 gp_Dir gp_Dir::Mirrored (const gp_Ax2& A2) const
143 void gp_Dir::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
145 OCCT_DUMP_VECTOR_CLASS (theOStream, "gp_Dir", 3, coord.X(), coord.Y(), coord.Z())
148 Standard_Boolean gp_Dir::InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos)
150 Standard_Integer aPos = theStreamPos;
152 OCCT_INIT_VECTOR_CLASS (Standard_Dump::Text (theSStream), "gp_Dir", aPos, 3, &coord.ChangeCoord (1), &coord.ChangeCoord (2), &coord.ChangeCoord (3))
155 return Standard_True;