[f2d6445] | 1 | /** \file SingleHelix.cc */ |
---|
| 2 | #include <cmath> |
---|
| 3 | #include <cassert> |
---|
| 4 | #include "single_helix.h" |
---|
| 5 | #include "myutil.h" |
---|
| 6 | |
---|
| 7 | SingleHelix::SingleHelix() |
---|
| 8 | { |
---|
| 9 | hr_ = 0; |
---|
| 10 | tr_ = 0; |
---|
| 11 | pitch_ = 0; |
---|
| 12 | turns_ = 0; |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | SingleHelix::SingleHelix(double helix_radius,double tube_radius,double pitch,double turns) |
---|
| 16 | { |
---|
| 17 | hr_ = helix_radius; |
---|
| 18 | tr_ = tube_radius; |
---|
| 19 | pitch_ = pitch; |
---|
| 20 | turns_ = turns; |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | SingleHelix::~SingleHelix() |
---|
| 24 | { |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | void SingleHelix::SetHelixRadius(double hr) |
---|
| 28 | { |
---|
| 29 | hr_ = hr; |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | void SingleHelix::SetTubeRadius(double tr) |
---|
| 33 | { |
---|
| 34 | tr_ = tr; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | void SingleHelix::SetPitch(double pitch) |
---|
| 38 | { |
---|
| 39 | pitch_ = pitch; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | void SingleHelix::SetTurns(double turns) |
---|
| 43 | { |
---|
| 44 | turns_ = turns; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | double SingleHelix::GetHelixRadius() |
---|
| 48 | { |
---|
| 49 | return hr_; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | double SingleHelix::GetTubeRadius() |
---|
| 53 | { |
---|
| 54 | return tr_; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | double SingleHelix::GetPitch() |
---|
| 58 | { |
---|
| 59 | return pitch_; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | double SingleHelix::GetTurns() |
---|
| 63 | { |
---|
| 64 | return turns_; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | double SingleHelix::GetMaxRadius() |
---|
| 68 | { |
---|
| 69 | // put helix into a cylinder |
---|
| 70 | double r_ = hr_ + tr_; |
---|
| 71 | double l_ = pitch_*turns_ + 2*tr_; |
---|
| 72 | double maxr = sqrt(4*r_*r_ + l_*l_)/2; |
---|
| 73 | return maxr; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | ShapeType SingleHelix::GetShapeType() const |
---|
| 77 | { |
---|
| 78 | return SINGLEHELIX; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | double SingleHelix::GetVolume() |
---|
| 82 | { |
---|
| 83 | double V = pi*square(tr_)*sqrt(square(2*pi*hr_)+square(turns_*pitch_)); |
---|
| 84 | return V; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | void SingleHelix::GetFormFactor(IQ * iq) |
---|
| 88 | { |
---|
| 89 | /** number of I for output, equal to the number of rows of array IQ*/ |
---|
| 90 | /** to be finished */ |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | Point3D SingleHelix::GetAPoint(double sld) |
---|
| 94 | { |
---|
| 95 | int max_try = 100; |
---|
| 96 | int i = 0; |
---|
| 97 | double point1 = 0, point2 = 0, point3 = 0; |
---|
| 98 | |
---|
| 99 | do{ |
---|
| 100 | i++; |
---|
| 101 | if (i > max_try) |
---|
| 102 | break; |
---|
| 103 | zr_ = tr_*sqrt(1+square((pitch_/(2*pi*hr_)))); |
---|
| 104 | point1 = (ran1()-0.5)*2*tr_; |
---|
| 105 | point2 = (ran1()-0.5)*2*zr_; |
---|
| 106 | point3 = (ran1()-0.5)*4*pi*turns_; |
---|
| 107 | } while (((square(point1/hr_)+square(point2/zr_))>1) || (point2+pitch_*point3/(2*pi)<0)); |
---|
| 108 | |
---|
| 109 | double x = (point1 + hr_)*cos(point3); |
---|
| 110 | double y = (point1 + hr_)*sin(point3); |
---|
| 111 | //"-pitch_*turns_/2" is just to corretly center the helix |
---|
| 112 | double z = point2 + pitch_*point3/(2*pi)-pitch_*turns_/2; |
---|
| 113 | |
---|
| 114 | Point3D apoint(x,y,z,sld); |
---|
| 115 | return apoint; |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | std::cerr << "Max try " |
---|
| 119 | << max_try |
---|
| 120 | << " is reached while generating a point in cylinder" << std::endl; |
---|
| 121 | |
---|
| 122 | return Point3D(0,0,0); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | bool SingleHelix::IsInside(const Point3D& point) const |
---|
| 126 | { |
---|
| 127 | double x = point.getX()-center_[0]; |
---|
| 128 | double y = point.getY()-center_[1]; |
---|
| 129 | double z = point.getZ()-center_[2]; |
---|
| 130 | |
---|
| 131 | double p3 = atan(y/x); |
---|
| 132 | double p2 = z-(pitch_*p3)/(2*pi); |
---|
| 133 | double p1 = x/cos(p3)-hr_; |
---|
| 134 | |
---|
| 135 | if ((square(p1/tr_)+square(p2/zr_))>1 || p2+pitch_*p3/(2*pi)) |
---|
| 136 | return false; |
---|
| 137 | else |
---|
| 138 | return true; |
---|
| 139 | } |
---|
| 140 | |
---|