// @(#)root/g3d:\$Id\$
// Author: Nenad Buncic   19/09/95

/*************************************************************************
* Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
*                                                                       *
* For the licensing terms see \$ROOTSYS/LICENSE.                         *
* For the list of contributors see \$ROOTSYS/README/CREDITS.             *
*************************************************************************/

#include "TGTRA.h"
#include "TNode.h"
#include "TMath.h"

ClassImp(TGTRA)

//______________________________________________________________________________
// Begin_Html <P ALIGN=CENTER> <IMG SRC="gif/gtra.gif"> </P> End_Html
// GTRA is a general twisted trapezoid. The faces perpendicular to z are trapezia
// and their centres are not necessarily on a line parallel to the z axis as the
// TRAP; additionally, the faces may be twisted so that none of their edges are
// parallel. It is a TRAP shape, except that it is twisted in the x-y plane as a
// function of z. The parallel sides perpendicular to the z axis are rotated with
// respect to the x axis by an angle TWIST, which is one of the parameters. The
// shape is defined by the eight corners and is assumed to be constructed of
// straight lines joining points on the boundary of the trapezoidal face at z=-DZ
// to the corresponding points on the face at z=DZ. Divisions are not allowed.
// It has 15 parameters:
//
//     - name       name of the shape
//     - title      shape's title
//     - material  (see TMaterial)
//     - dZ         half-length along the z axis
//     - theta      polar angle of the line joining the centre of the face
//                  at -DZ to the centre of the one at +DZ
//     - phi        azimuthal angle of the line joining the centre of
//                  the face at -DZ to the centre of the one at +DZ
//     - twist      twist angle of the faces parallel to the x-y plane
//                  at z = +/- DZ around an axis parallel to z passing
//                  through their centre
//     - h1         half-length along y of the face at -DZ
//     - bl1        half-length along x of the side at -H1 in y of
//                  the face at -DZ in z
//     - tl1        half-length along x of the side at +H1 in y of the face
//                  at -DZ in z
//     - alpha1     angle with respect to the y axis from the centre of
//                  the side at -H1 in y to the centre of the side at
//                  +H1 in y of the face at -DZ in z
//     - h2         half-length along y of the face at +DZ
//     - bL2        half-length along x of the side at -H2 in y of the face at
//                  +DZ in z
//
//     - tl2        half-length along x of the side at +H2 in y of the face
//                  at +DZ in z
//
//     - alpha2     angle with respect to the y axis from the centre of the side
//                  at -H2 in y to the centre of the side at +H2 in y of the
//                  face at +DZ in z

//______________________________________________________________________________
TGTRA::TGTRA ()
{
// GTRA shape default constructor.

fTwist  = 0.;
fH1     = 0.;
fBl1    = 0.;
fTl1    = 0.;
fAlpha1 = 0.;
fH2     = 0.;
fBl2    = 0.;
fTl2    = 0.;
fAlpha2 = 0.;
}

//______________________________________________________________________________
TGTRA::TGTRA (const char *name, const char *title, const char *material, Float_t dz, Float_t theta,
Float_t phi, Float_t twist, Float_t h1, Float_t bl1, Float_t tl1, Float_t alpha1,
Float_t h2, Float_t bl2, Float_t tl2, Float_t alpha2)
: TBRIK (name, title, material, theta, phi, dz)
{
// GTRA shape normal constructor

fTwist  = twist;
fH1     = h1;
fBl1    = bl1;
fTl1    = tl1;
fAlpha1 = alpha1;
fH2     = h2;
fBl2    = bl2;
fTl2    = tl2;
fAlpha2 = alpha2;
}

//______________________________________________________________________________
TGTRA::~TGTRA ()
{
// GTRA shape default destructor
}

//______________________________________________________________________________
void TGTRA::SetPoints (Double_t *points) const
{
// Create GTRA points

Double_t x, y, dx, dy, dx1, dx2, dz, theta, phi, alpha1, alpha2, twist;
const Float_t pi = Float_t (TMath::Pi());

alpha1 = fAlpha1    * pi/180.0;
alpha2 = fAlpha2    * pi/180.0;
theta  = TBRIK::fDx * pi/180.0;
phi    = TBRIK::fDy * pi/180.0;
twist  = fTwist     * pi/180.0;

dx  = 2*fDz*TMath::Sin(theta)*TMath::Cos(phi);
dy  = 2*fDz*TMath::Sin(theta)*TMath::Sin(phi);
dz  = TBRIK::fDz;

dx1 = 2*fH1*TMath::Tan(alpha1);
dx2 = 2*fH2*TMath::Tan(alpha2);

if (points) {
points[ 0] = -fBl1;        points[ 1] = -fH1;    points[ 2] = -dz;
points[ 9] =  fBl1;        points[10] = -fH1;    points[11] = -dz;
points[ 6] =  fTl1+dx1;    points[ 7] =  fH1;    points[ 8] = -dz;
points[ 3] = -fTl1+dx1;    points[4]  =  fH1;    points[5] = -dz;
points[12] = -fBl2+dx;     points[13] = -fH2+dy; points[14] = dz;
points[21] =  fBl2+dx;     points[22] = -fH2+dy; points[23] = dz;
points[18] =  fTl2+dx+dx2; points[19] =  fH2+dy; points[20] = dz;
points[15] = -fTl2+dx+dx2; points[16] =  fH2+dy; points[17] = dz;
for (Int_t i = 12; i < 24; i+=3) {
x = points[i];
y = points[i+1];
points[i]     = x*TMath::Cos(twist) + y*TMath::Sin(twist);
points[i+1]  = -x*TMath::Sin(twist) + y*TMath::Cos(twist);
}
}
}
TGTRA.cxx:1
TGTRA.cxx:2
TGTRA.cxx:3
TGTRA.cxx:4
TGTRA.cxx:5
TGTRA.cxx:6
TGTRA.cxx:7
TGTRA.cxx:8
TGTRA.cxx:9
TGTRA.cxx:10
TGTRA.cxx:11
TGTRA.cxx:12
TGTRA.cxx:13
TGTRA.cxx:14
TGTRA.cxx:15
TGTRA.cxx:16
TGTRA.cxx:17
TGTRA.cxx:18
TGTRA.cxx:19
TGTRA.cxx:20
TGTRA.cxx:21
TGTRA.cxx:22
TGTRA.cxx:23
TGTRA.cxx:24
TGTRA.cxx:25
TGTRA.cxx:26
TGTRA.cxx:27
TGTRA.cxx:28
TGTRA.cxx:29
TGTRA.cxx:30
TGTRA.cxx:31
TGTRA.cxx:32
TGTRA.cxx:33
TGTRA.cxx:34
TGTRA.cxx:35
TGTRA.cxx:36
TGTRA.cxx:37
TGTRA.cxx:38
TGTRA.cxx:39
TGTRA.cxx:40
TGTRA.cxx:41
TGTRA.cxx:42
TGTRA.cxx:43
TGTRA.cxx:44
TGTRA.cxx:45
TGTRA.cxx:46
TGTRA.cxx:47
TGTRA.cxx:48
TGTRA.cxx:49
TGTRA.cxx:50
TGTRA.cxx:51
TGTRA.cxx:52
TGTRA.cxx:53
TGTRA.cxx:54
TGTRA.cxx:55
TGTRA.cxx:56
TGTRA.cxx:57
TGTRA.cxx:58
TGTRA.cxx:59
TGTRA.cxx:60
TGTRA.cxx:61
TGTRA.cxx:62
TGTRA.cxx:63
TGTRA.cxx:64
TGTRA.cxx:65
TGTRA.cxx:66
TGTRA.cxx:67
TGTRA.cxx:68
TGTRA.cxx:69
TGTRA.cxx:70
TGTRA.cxx:71
TGTRA.cxx:72
TGTRA.cxx:73
TGTRA.cxx:74
TGTRA.cxx:75
TGTRA.cxx:76
TGTRA.cxx:77
TGTRA.cxx:78
TGTRA.cxx:79
TGTRA.cxx:80
TGTRA.cxx:81
TGTRA.cxx:82
TGTRA.cxx:83
TGTRA.cxx:84
TGTRA.cxx:85
TGTRA.cxx:86
TGTRA.cxx:87
TGTRA.cxx:88
TGTRA.cxx:89
TGTRA.cxx:90
TGTRA.cxx:91
TGTRA.cxx:92
TGTRA.cxx:93
TGTRA.cxx:94
TGTRA.cxx:95
TGTRA.cxx:96
TGTRA.cxx:97
TGTRA.cxx:98
TGTRA.cxx:99
TGTRA.cxx:100
TGTRA.cxx:101
TGTRA.cxx:102
TGTRA.cxx:103
TGTRA.cxx:104
TGTRA.cxx:105
TGTRA.cxx:106
TGTRA.cxx:107
TGTRA.cxx:108
TGTRA.cxx:109
TGTRA.cxx:110
TGTRA.cxx:111
TGTRA.cxx:112
TGTRA.cxx:113
TGTRA.cxx:114
TGTRA.cxx:115
TGTRA.cxx:116
TGTRA.cxx:117
TGTRA.cxx:118
TGTRA.cxx:119
TGTRA.cxx:120
TGTRA.cxx:121
TGTRA.cxx:122
TGTRA.cxx:123
TGTRA.cxx:124
TGTRA.cxx:125
TGTRA.cxx:126
TGTRA.cxx:127
TGTRA.cxx:128
TGTRA.cxx:129
TGTRA.cxx:130
TGTRA.cxx:131
TGTRA.cxx:132
TGTRA.cxx:133
TGTRA.cxx:134
TGTRA.cxx:135
TGTRA.cxx:136
TGTRA.cxx:137
TGTRA.cxx:138
TGTRA.cxx:139
TGTRA.cxx:140
TGTRA.cxx:141
TGTRA.cxx:142
TGTRA.cxx:143
TGTRA.cxx:144
TGTRA.cxx:145
TGTRA.cxx:146