Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ArrowModel.cc
Go to the documentation of this file.
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$
28//
29//
30// John Allison 15th July 2012
31// Model that knows how to draw an arrow.
32
33#include "G4ArrowModel.hh"
34
36#include "G4VGraphicsScene.hh"
37#include "G4VisAttributes.hh"
38#include "G4Tubs.hh"
39#include "G4Polycone.hh"
40#include "G4Polyhedron.hh"
41#include "G4Vector3D.hh"
42#include "G4Point3D.hh"
43#include "G4Transform3D.hh"
44
46
48(G4double x1, G4double y1, G4double z1,
49 G4double x2, G4double y2, G4double z2,
50 G4double width, const G4Colour& colour,
51 const G4String& description)
52{
53 fType = "G4ArrowModel";
55 fGlobalDescription = fType + ": " + description;
57 (std::min(x1,x2),
58 std::max(x1,x2),
59 std::min(y1,y2),
60 std::max(y1,y2),
61 std::min(z1,z2),
62 std::max(z1,z2));
63
64 // Make a cylinder slightly shorter than the arrow length so that it
65 // doesn't stick out of the head.
66 const G4double shaftLength = std::sqrt
67 (std::pow(x2-x1,2)+std::pow(y2-y1,2)+std::pow(z2-z1,2));
68 G4double shaftRadius = width/2.;
69 // Limit the radius
70 if (shaftRadius > shaftLength/100.) shaftRadius = shaftLength/100.;
71 const G4double halfShaftLength = shaftLength/2.;
72 const G4double halfReduction = 4.*shaftRadius;
73 const G4double halfLength = halfShaftLength-halfReduction;
74 G4Tubs shaft("shaft",0.,shaftRadius,halfLength,0.,twopi);
75 fpShaftPolyhedron = shaft.CreatePolyhedron();
76 // Move it a little so that the tail is at z = -halfShaftLength.
77 fpShaftPolyhedron->Transform(G4Translate3D(0,0,-halfReduction));
78
79 // Locate the head at +halfShaftLength.
80 const G4int numRZ = 3;
81 G4double r[] = {0,4,0};
82 G4double z[] = {0,-6,-4};
83 for (G4int i = 0; i < numRZ; i++) {
84 r[i] *= 2.*shaftRadius;
85 z[i] = halfShaftLength + z[i] * 2.*shaftRadius;
86 }
87 G4Polycone head("head",0,twopi,numRZ,r,z);
88 fpHeadPolyhedron = head.CreatePolyhedron();
89
90 // Transform to position
91 const G4Vector3D arrowDirection = G4Vector3D(x2-x1,y2-y1,z2-z1).unit();
92 const G4double theta = arrowDirection.theta();
93 const G4double phi = arrowDirection.phi();
94 const G4Point3D arrowCentre(0.5*(x1+x2),0.5*(y1+y2),0.5*(z1+z2));
95 const G4Transform3D tr =
96 G4Translate3D(arrowCentre) * G4RotateZ3D(phi) * G4RotateY3D(theta);
97 fpShaftPolyhedron->Transform(tr);
98 fpHeadPolyhedron->Transform(tr);
99
101 va.SetColour(colour);
102 va.SetForceSolid(true);
103 fpShaftPolyhedron->SetVisAttributes(va);
104 fpHeadPolyhedron->SetVisAttributes(va);
105}
106
108{
109 sceneHandler.BeginPrimitives();
110 sceneHandler.AddPrimitive(*fpShaftPolyhedron);
111 sceneHandler.AddPrimitive(*fpHeadPolyhedron);
112 sceneHandler.EndPrimitives();
113}
HepGeom::RotateZ3D G4RotateZ3D
HepGeom::Translate3D G4Translate3D
HepGeom::RotateY3D G4RotateY3D
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
HepGeom::Vector3D< G4double > G4Vector3D
Definition: G4Vector3D.hh:35
G4ArrowModel(G4double x1, G4double y1, G4double z1, G4double x2, G4double y2, G4double z2, G4double width, const G4Colour &colour, const G4String &description="")
Definition: G4ArrowModel.cc:48
virtual ~G4ArrowModel()
Definition: G4ArrowModel.cc:45
virtual void DescribeYourselfTo(G4VGraphicsScene &)
G4Polyhedron * CreatePolyhedron() const
Definition: G4Polycone.cc:891
Definition: G4Tubs.hh:77
G4Polyhedron * CreatePolyhedron() const
Definition: G4Tubs.cc:1923
virtual void BeginPrimitives(const G4Transform3D &objectTransformation=G4Transform3D())=0
virtual void AddPrimitive(const G4Polyline &)=0
virtual void EndPrimitives()=0
G4VisExtent fExtent
Definition: G4VModel.hh:111
G4String fGlobalDescription
Definition: G4VModel.hh:110
G4String fType
Definition: G4VModel.hh:108
G4String fGlobalTag
Definition: G4VModel.hh:109
void SetColour(const G4Colour &)
void SetForceSolid(G4bool)
void SetVisAttributes(const G4VisAttributes *)
Definition: G4Visible.cc:80
BasicVector3D< T > unit() const
HepPolyhedron & Transform(const G4Transform3D &t)