7fd59977 |
1 | // File gp_Dir.lxx , JCV 01/10/90 |
2 | |
3 | #include <gp_Vec.hxx> |
4 | #include <gp_Trsf.hxx> |
5 | #include <Standard_ConstructionError.hxx> |
6 | #include <Standard_OutOfRange.hxx> |
7 | |
8 | inline gp_Dir::gp_Dir () : coord(1.,0.,0.) |
9 | { |
10 | } |
11 | |
12 | inline gp_Dir::gp_Dir (const gp_Vec& V) |
13 | { |
14 | const gp_XYZ& XYZ = V.XYZ(); |
15 | Standard_Real X = XYZ.X(); |
16 | Standard_Real Y = XYZ.Y(); |
17 | Standard_Real Z = XYZ.Z(); |
18 | Standard_Real D = sqrt(X * X + Y * Y + Z * Z); |
19 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
20 | coord.SetX(X / D); |
21 | coord.SetY(Y / D); |
22 | coord.SetZ(Z / D); |
23 | } |
24 | |
25 | inline gp_Dir::gp_Dir (const gp_XYZ& XYZ) |
26 | { |
27 | Standard_Real X = XYZ.X(); |
28 | Standard_Real Y = XYZ.Y(); |
29 | Standard_Real Z = XYZ.Z(); |
30 | Standard_Real D = sqrt(X * X + Y * Y + Z * Z); |
31 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
32 | coord.SetX(X / D); |
33 | coord.SetY(Y / D); |
34 | coord.SetZ(Z / D); |
35 | } |
36 | |
37 | inline gp_Dir::gp_Dir (const Standard_Real Xv, |
38 | const Standard_Real Yv, |
39 | const Standard_Real Zv) |
40 | { |
41 | Standard_Real D = sqrt (Xv * Xv + Yv * Yv + Zv * Zv); |
42 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
43 | coord.SetX(Xv / D); |
44 | coord.SetY(Yv / D); |
45 | coord.SetZ(Zv / D); |
46 | } |
47 | |
48 | inline void gp_Dir::SetCoord (const Standard_Integer Index, |
49 | const Standard_Real Xi) |
50 | { |
51 | Standard_Real X = coord.X(); |
52 | Standard_Real Y = coord.Y(); |
53 | Standard_Real Z = coord.Z(); |
54 | Standard_OutOfRange_Raise_if (Index < 1 || Index > 3, " "); |
55 | if (Index == 1) X = Xi; |
56 | else if (Index == 2) Y = Xi; |
57 | else Z = Xi; |
58 | Standard_Real D = sqrt (X * X + Y * Y + Z * Z); |
59 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
60 | coord.SetX(X / D); |
61 | coord.SetY(Y / D); |
62 | coord.SetZ(Z / D); |
63 | } |
64 | |
65 | inline void gp_Dir::SetCoord (const Standard_Real Xv, |
66 | const Standard_Real Yv, |
67 | const Standard_Real Zv) { |
68 | Standard_Real D = sqrt(Xv * Xv + Yv * Yv + Zv * Zv); |
69 | Standard_ConstructionError_Raise_if(D <= gp::Resolution(), ""); |
70 | coord.SetX(Xv / D); |
71 | coord.SetY(Yv / D); |
72 | coord.SetZ(Zv / D); |
73 | } |
74 | |
75 | inline void gp_Dir::SetX (const Standard_Real X) |
76 | { |
77 | Standard_Real Y = coord.Y(); |
78 | Standard_Real Z = coord.Z(); |
79 | Standard_Real D = sqrt (X * X + Y * Y + Z * Z); |
80 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
81 | coord.SetX(X / D); |
82 | coord.SetY(Y / D); |
83 | coord.SetZ(Z / D); |
84 | } |
85 | |
86 | inline void gp_Dir::SetY (const Standard_Real Y) |
87 | { |
88 | Standard_Real Z = coord.Z(); |
89 | Standard_Real X = coord.X(); |
90 | Standard_Real D = sqrt (X * X + Y * Y + Z * Z); |
91 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
92 | coord.SetX(X / D); |
93 | coord.SetY(Y / D); |
94 | coord.SetZ(Z / D); |
95 | } |
96 | |
97 | inline void gp_Dir::SetZ (const Standard_Real Z) |
98 | { |
99 | Standard_Real X = coord.X(); |
100 | Standard_Real Y = coord.Y(); |
101 | Standard_Real D = sqrt (X * X + Y * Y + Z * Z); |
102 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
103 | coord.SetX(X / D); |
104 | coord.SetY(Y / D); |
105 | coord.SetZ(Z / D); |
106 | } |
107 | |
108 | inline void gp_Dir::SetXYZ (const gp_XYZ& XYZ) |
109 | { |
110 | Standard_Real X = XYZ.X(); |
111 | Standard_Real Y = XYZ.Y(); |
112 | Standard_Real Z = XYZ.Z(); |
113 | Standard_Real D = sqrt(X * X + Y * Y + Z * Z); |
114 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
115 | coord.SetX(X / D); |
116 | coord.SetY(Y / D); |
117 | coord.SetZ(Z / D); |
118 | } |
119 | |
120 | inline Standard_Real gp_Dir::Coord (const Standard_Integer Index) const |
121 | { return coord.Coord (Index);} |
122 | |
123 | inline void gp_Dir::Coord (Standard_Real& Xv, |
124 | Standard_Real& Yv, |
125 | Standard_Real& Zv) const |
126 | { coord.Coord (Xv, Yv, Zv); } |
127 | |
128 | inline Standard_Real gp_Dir::X() const |
129 | { return coord.X() ; } |
130 | |
131 | inline Standard_Real gp_Dir::Y() const |
132 | { return coord.Y() ; } |
133 | |
134 | inline Standard_Real gp_Dir::Z() const |
135 | { return coord.Z() ; } |
136 | |
137 | inline const gp_XYZ& gp_Dir::XYZ () const |
138 | { return coord; } |
139 | |
140 | inline Standard_Boolean gp_Dir::IsEqual |
141 | (const gp_Dir& Other, |
142 | const Standard_Real AngularTolerance) const |
143 | { return Angle (Other) <= AngularTolerance; } |
144 | |
145 | inline Standard_Boolean gp_Dir::IsNormal |
146 | (const gp_Dir& Other, |
147 | const Standard_Real AngularTolerance) const |
148 | { |
c6541a0c |
149 | Standard_Real Ang = M_PI / 2.0 - Angle (Other); |
7fd59977 |
150 | if (Ang < 0) Ang = - Ang; |
151 | return Ang <= AngularTolerance; |
152 | } |
153 | |
154 | inline Standard_Boolean gp_Dir::IsOpposite |
155 | (const gp_Dir& Other, |
156 | const Standard_Real AngularTolerance) const |
c6541a0c |
157 | { return M_PI - Angle (Other) <= AngularTolerance; } |
7fd59977 |
158 | |
159 | inline Standard_Boolean gp_Dir::IsParallel |
160 | (const gp_Dir& Other, |
161 | const Standard_Real AngularTolerance) const |
162 | { |
163 | Standard_Real Ang = Angle (Other); |
c6541a0c |
164 | return Ang <= AngularTolerance || M_PI - Ang <= AngularTolerance; |
7fd59977 |
165 | } |
166 | |
167 | inline void gp_Dir::Cross (const gp_Dir& Right) |
168 | { |
169 | coord.Cross (Right.coord); |
170 | Standard_Real D = coord.Modulus (); |
171 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
172 | coord.Divide (D); |
173 | } |
174 | |
175 | inline gp_Dir gp_Dir::Crossed (const gp_Dir& Right) const |
176 | { |
177 | gp_Dir V = *this; |
178 | V.coord.Cross (Right.coord); |
179 | Standard_Real D = V.coord.Modulus(); |
180 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
181 | V.coord.Divide (D); |
182 | return V; |
183 | } |
184 | |
185 | inline void gp_Dir::CrossCross (const gp_Dir& V1, |
186 | const gp_Dir& V2) |
187 | { |
188 | coord.CrossCross (V1.coord, V2.coord); |
189 | Standard_Real D = coord.Modulus(); |
190 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
191 | coord.Divide(D); |
192 | } |
193 | |
194 | inline gp_Dir gp_Dir::CrossCrossed (const gp_Dir& V1, |
195 | const gp_Dir& V2) const |
196 | { |
197 | gp_Dir V = *this; |
198 | (V.coord).CrossCross (V1.coord, V2.coord); |
199 | Standard_Real D = V.coord.Modulus(); |
200 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
201 | V.coord.Divide(D); |
202 | return V; |
203 | } |
204 | |
205 | inline Standard_Real gp_Dir::Dot (const gp_Dir& Other) const |
206 | { return coord.Dot (Other.coord); } |
207 | |
208 | inline Standard_Real gp_Dir::DotCross (const gp_Dir& V1, |
209 | const gp_Dir& V2) const |
210 | { return coord.Dot (V1.coord.Crossed (V2.coord)); } |
211 | |
212 | inline void gp_Dir::Reverse () |
213 | { coord.Reverse(); } |
214 | |
215 | inline gp_Dir gp_Dir::Reversed () const { |
216 | gp_Dir V = *this; |
217 | V.coord.Reverse (); |
218 | return V; |
219 | } |
220 | |
221 | inline void gp_Dir::Rotate (const gp_Ax1& A1, const Standard_Real Ang) |
222 | { |
223 | gp_Trsf T; |
224 | T.SetRotation (A1, Ang); |
225 | coord.Multiply (T.HVectorialPart ()); |
226 | } |
227 | |
228 | inline gp_Dir gp_Dir::Rotated (const gp_Ax1& A1, |
229 | const Standard_Real Ang) const |
230 | { |
231 | gp_Dir V = *this; |
232 | V.Rotate (A1, Ang); |
233 | return V; |
234 | } |
235 | |
236 | inline gp_Dir gp_Dir::Transformed (const gp_Trsf& T) const |
237 | { |
238 | gp_Dir V = *this; |
239 | V.Transform (T); |
240 | return V; |
241 | } |
242 | |