source: trunk/source/geometry/solids/BREPS/test/G4FPlaneTest.cc@ 1337

Last change on this file since 1337 was 1316, checked in by garnier, 15 years ago

update geant4-09-04-beta-cand-01 interfaces-V09-03-09 vis-V09-03-08

File size: 9.2 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//////////////////////////////////////////////////////////////////////////
27// $Id: G4FPlaneTest.cc,v 1.8 2007/05/18 10:31:11 gcosmo Exp $
28// GEANT4 tag $Name: geant4-09-04-beta-cand-01 $
29//////////////////////////////////////////////////////////////////////////
30//
31//
32// Test the G4FPlane class
33// Created by L. Broglia, 22 October 1998
34
35#include "G4FPlane.hh"
36#include "G4Surface.hh"
37#include "G4Axis2Placement3D.hh"
38#include "G4GeometryTolerance.hh"
39
40
41int main()
42{
43
44/////////////////////////////////////////////////////////////
45//
46// I want to compare the 2 different creator.
47// I utilized a piece of the G4BREPSolidPolyhedra.cc file
48
49 G4cout<<"\n\n//////////////////////////////////////////////////////";
50
51 G4Vector3D Dir ;
52 G4Vector3D Ax ;
53 G4Point3D Porg ;
54 G4Point3DVector PointList(4);
55
56 G4Point3D LocalOrigin(0.0, 0.0, 0.0);
57 G4Vector3D TmpAxis(1, 0, 0);
58 G4Vector3D Axis(0, 0, 1);
59
60 double RMIN0 = 2;
61 double RMIN1 = 1;
62 double Length = 2;
63 double PartAngle = pi/2;
64
65 PointList[0] = LocalOrigin + (RMIN0 * TmpAxis);
66 PointList[1] = LocalOrigin + (Length*Axis) + (RMIN1 * TmpAxis);
67
68 TmpAxis.rotateZ(PartAngle);
69
70 PointList[2] = LocalOrigin + (Length*Axis) + (RMIN1 * TmpAxis);
71 PointList[3] = LocalOrigin + (RMIN0 * TmpAxis);
72
73 // Messages output
74 for(int i=0; i<4; i++)
75 G4cout<<"\n Pt"<<i<<" :"
76 <<" x= "<<PointList[i].x()
77 <<" y= "<<PointList[i].y()
78 <<" z= "<<PointList[i].z();
79
80
81 G4FPlane SurfaceVec1( &PointList );
82
83 G4FPlane SurfaceVec2
84 ( PointList[0] - PointList[1] ,
85 (PointList[3] - PointList[0]).cross(PointList[0] - PointList[1]) ,
86 PointList[0] );
87
88 G4Axis2Placement3D Pplace1 = SurfaceVec1.GetPplace();
89 G4Axis2Placement3D Pplace2 = SurfaceVec2.GetPplace();
90
91 G4Vector3D Dir1 = Pplace1.GetRefDirection() ;
92 G4Vector3D Ax1 = Pplace1.GetAxis() ;
93 G4Point3D Porg1 = Pplace1.GetLocation() ;
94
95 G4Vector3D Dir2 = Pplace2.GetRefDirection() ;
96 G4Vector3D Ax2 = Pplace2.GetAxis() ;
97 G4Point3D Porg2 = Pplace2.GetLocation() ;
98
99 // Messages output
100 G4cout<<"\n\n Dir1 : x= "<<Dir1.x()<<" y= "<<Dir1.y()<<" z= "<<Dir1.z();
101 G4cout<<"\n Dir2 : x= "<<Dir2.x()<<" y= "<<Dir2.y()<<" z= "<<Dir2.z();
102
103 G4cout<<"\n\n Ax1 : x= "<<Ax1.x()<<" y= "<<Ax1.y()<<" z= "<<Ax1.z();
104 G4cout<<"\n Ax2 : x= "<<Ax2.x()<<" y= "<<Ax2.y()<<" z= "<<Ax2.z();
105
106 G4cout<<"\n\n Porg1 : x= "<<Porg1.x()<<" y= "<<Porg1.y()<<" z= "<<Porg1.z();
107 G4cout<<"\n Porg2 : x= "<<Porg2.x()<<" y= "<<Porg2.y()<<" z= "<<Porg2.z();
108
109 G4cout<<"\n\n coordinate axis 1 : PX= "<<Pplace1.GetPX()
110 <<" PY= "<<Pplace1.GetPY()
111 <<" PZ= "<<Pplace1.GetPZ() ;
112
113 G4cout<<"\n coordinate axis 2 : PX= "<<Pplace2.GetPX()
114 <<" PY= "<<Pplace2.GetPY()
115 <<" PZ= "<<Pplace2.GetPZ() ;
116
117
118 G4Plane Plane1 = SurfaceVec1.GetPplane();
119 G4Plane Plane2 = SurfaceVec2.GetPplane();
120
121 G4cout<<"\n\n Plane1 : a= "<<Plane1.a
122 <<" b= "<<Plane1.b
123 <<" c= "<<Plane1.c
124 <<" d= "<<Plane1.d ;
125
126 G4cout<<"\n Plane2 : a= "<<Plane2.a
127 <<" b= "<<Plane2.b
128 <<" c= "<<Plane2.c
129 <<" d= "<<Plane2.d ;
130
131 G4Ray* Normal1 = SurfaceVec1.Norm();
132 G4Ray* Normal2 = SurfaceVec2.Norm();
133
134 G4Point3D start1 = (*Normal1).GetStart();
135 G4Point3D start2 = (*Normal2).GetStart();
136 G4Vector3D dir1 = (*Normal1).GetDir();
137 G4Vector3D dir2 = (*Normal2).GetDir();
138
139 G4cout<<"\n\n Normal 1" ;
140 G4cout<<"\n Start : x= "<<start1.x()<<" y= "<<start1.y()<<" z= "<<start1.z();
141 G4cout<<"\n Dir : x= "<<dir1.x()<<" y= "<<dir1.y()<<" z= "<<dir1.z();
142
143 G4cout<<"\n\n Normal 2" ;
144 G4cout<<"\n Start : x= "<<start2.x()<<" y= "<<start2.y()<<" z= "<<start2.z();
145 G4cout<<"\n Dir : x= "<<dir2.x()<<" y= "<<dir2.y()<<" z= "<<dir2.z();
146
147 // Now, I test the function ClosestDistanceToPoint
148 G4Point3D Pout(2, 2, 4);
149 G4double dist1 = SurfaceVec1.ClosestDistanceToPoint(Pout);
150 G4double dist2 = SurfaceVec2.ClosestDistanceToPoint(Pout);
151
152 G4cout<<"\n\n Distance 1 ="<<dist1;
153 G4cout<<"\n Distance 2 ="<<dist2;
154
155
156
157//////////////////////////////////////////////////////////////////////
158//
159// This test show that the creation of the plane not depend on the
160// points in the plane
161//
162
163 G4cout<<"\n\n//////////////////////////////////////////////////////";
164
165 G4Point3D P0 = PointList[0];
166 G4Point3D P1 = PointList[1];
167 G4Point3D P2 = PointList[2];
168 G4Point3D P3 = PointList[3];
169
170 PointList[0] = P0;
171 PointList[1] = P1;
172 PointList[2] = P2;
173 PointList[3] = P3;
174 G4FPlane SurfaceA( &PointList );
175
176 PointList[0] = P1;
177 PointList[1] = P2;
178 PointList[2] = P3;
179 PointList[3] = P0;
180 G4FPlane SurfaceB( &PointList );
181
182 PointList[0] = P2;
183 PointList[1] = P3;
184 PointList[2] = P0;
185 PointList[3] = P1;
186 G4FPlane SurfaceC( &PointList );
187
188 PointList[0] = P3;
189 PointList[1] = P0;
190 PointList[2] = P1;
191 PointList[3] = P2;
192 G4FPlane SurfaceD( &PointList );
193
194 G4Plane plan1 = SurfaceA.GetPplane();
195 G4Plane plan2 = SurfaceB.GetPplane();
196 G4Plane plan3 = SurfaceC.GetPplane();
197 G4Plane plan4 = SurfaceD.GetPplane();
198
199 G4cout<<"\n\n Plan1 : a= "<<plan1.a
200 <<" b= "<<plan1.b
201 <<" c= "<<plan1.c
202 <<" d= "<<plan1.d ;
203 G4cout<<"\n Plan2 : a= "<<plan2.a
204 <<" b= "<<plan2.b
205 <<" c= "<<plan2.c
206 <<" d= "<<plan2.d ;
207 G4cout<<"\n Plan3 : a= "<<plan3.a
208 <<" b= "<<plan3.b
209 <<" c= "<<plan3.c
210 <<" d= "<<plan3.d ;
211 G4cout<<"\n Plan4 : a= "<<plan4.a
212 <<" b= "<<plan4.b
213 <<" c= "<<plan4.c
214 <<" d= "<<plan4.d ;
215
216 G4double d1 = SurfaceA.ClosestDistanceToPoint(Pout);
217 G4double d2 = SurfaceB.ClosestDistanceToPoint(Pout);
218 G4double d3 = SurfaceC.ClosestDistanceToPoint(Pout);
219 G4double d4 = SurfaceD.ClosestDistanceToPoint(Pout);
220
221 G4cout<<"\n\n Distance 1 ="<<d1;
222 G4cout<<"\n Distance 2 ="<<d2;
223 G4cout<<"\n Distance 3 ="<<d3;
224 G4cout<<"\n Distance 4 ="<<d4;
225
226
227
228//////////////////////////////////////////////////////////////////////
229//
230// Test for the function EvaluateIntersection
231//
232//
233
234 G4cout<<"\n\n//////////////////////////////////////////////////////";
235
236 G4Point3D Pdep1 (0, 0, 2);
237 G4Vector3D DirRay(1 ,1, 0);
238 G4Ray Rayref(Pdep1, DirRay);
239
240 G4cout<<"\n\nPdep of the ray :"
241 <<"\n x="<<Rayref.GetStart().x()
242 <<"\n y="<<Rayref.GetStart().y()
243 <<"\n z="<<Rayref.GetStart().z();
244
245 G4cout<<"\n\nDirection of the ray :"
246 <<"\n x="<<Rayref.GetDir().x()
247 <<"\n y="<<Rayref.GetDir().y()
248 <<"\n z="<<Rayref.GetDir().z();
249
250 int intersec = SurfaceVec1.Intersect(Rayref);
251 G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
252
253 if(intersec)
254 {
255 G4cout<<"\n\nIntersection founded at point :"
256 <<"\n x="<<SurfaceVec1.GetHitPoint().x()
257 <<"\n y="<<SurfaceVec1.GetHitPoint().y()
258 <<"\n z="<<SurfaceVec1.GetHitPoint().z();
259
260 if ( ( SurfaceVec1.GetHitPoint().x()*SurfaceVec1.GetPplane().a +
261 SurfaceVec1.GetHitPoint().y()*SurfaceVec1.GetPplane().b +
262 SurfaceVec1.GetHitPoint().z()*SurfaceVec1.GetPplane().c <
263 SurfaceVec1.GetPplane().d + kCarTolerance ) &&
264 ( SurfaceVec1.GetHitPoint().x()*SurfaceVec1.GetPplane().a +
265 SurfaceVec1.GetHitPoint().y()*SurfaceVec1.GetPplane().b +
266 SurfaceVec1.GetHitPoint().z()*SurfaceVec1.GetPplane().c >
267 SurfaceVec1.GetPplane().d - kCarTolerance ) )
268 G4cout<<"\n\nPlain contain the hit point";
269 else
270 G4cout<<"\n\nPlain do not contain the hit point";
271
272 G4cout<<"\n\nSquared distance from the Pdep to the hit point :"
273 <<"\n distance="<<SurfaceVec1.GetDistance();
274 }
275 else
276 G4cout<<"\n\nNo Intersection"
277 <<"\n distance="<<SurfaceVec1.GetDistance()<<G4endl;
278
279 G4cout<<G4endl;
280 return EXIT_SUCCESS;
281}
Note: See TracBrowser for help on using the repository browser.