[aa639ea] | 1 | /** \file Ellipsoid.cc */ |
---|
| 2 | #include <cmath> |
---|
| 3 | #include <cassert> |
---|
| 4 | #include <algorithm> |
---|
| 5 | //MS library does not define min max in algorithm |
---|
| 6 | //#include "minmax.h" |
---|
| 7 | #include "ellipsoid.h" |
---|
| 8 | #include "myutil.h" |
---|
| 9 | |
---|
| 10 | using namespace std; |
---|
| 11 | |
---|
| 12 | Ellipsoid::Ellipsoid() |
---|
| 13 | { |
---|
| 14 | rx_ = 0; |
---|
| 15 | ry_ = 0; |
---|
| 16 | rz_ = 0; |
---|
| 17 | } |
---|
| 18 | |
---|
| 19 | Ellipsoid::Ellipsoid(double rx, double ry, double rz) |
---|
| 20 | { |
---|
| 21 | rx_ = rx; |
---|
| 22 | ry_ = ry; |
---|
| 23 | rz_ = rz; |
---|
| 24 | xedge_plus_ = Point3D(rx,0,0); |
---|
| 25 | xedge_minus_ = Point3D(-rx,0,0); |
---|
| 26 | yedge_plus_ = Point3D(0,ry,0); |
---|
| 27 | yedge_minus_ = Point3D(0,-ry,0); |
---|
| 28 | zedge_plus_ = Point3D(0,0,rz); |
---|
| 29 | zedge_minus_ = Point3D(0,0,-rz); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | Ellipsoid::~Ellipsoid() |
---|
| 33 | { |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | void Ellipsoid::SetRadii(double rx, double ry, double rz) |
---|
| 37 | { |
---|
| 38 | rx_ = rx; |
---|
| 39 | ry_ = ry; |
---|
| 40 | rz_ = rz; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | double Ellipsoid::GetRadiusX() |
---|
| 44 | { |
---|
| 45 | return rx_; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | double Ellipsoid::GetRadiusY() |
---|
| 49 | { |
---|
| 50 | return ry_; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | double Ellipsoid::GetRadiusZ() |
---|
| 54 | { |
---|
| 55 | return rz_; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | double Ellipsoid::GetMaxRadius() |
---|
| 59 | { |
---|
| 60 | double maxr = max(max(rx_,ry_),max(ry_,rz_)); |
---|
| 61 | return maxr; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | ShapeType Ellipsoid::GetShapeType() const |
---|
| 65 | { |
---|
| 66 | return ELLIPSOID; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | double Ellipsoid::GetVolume() |
---|
| 70 | { |
---|
| 71 | double V = (4./3.)*pi*rx_*ry_*rz_; |
---|
| 72 | return V; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | void Ellipsoid::GetFormFactor(IQ * iq) |
---|
| 76 | { |
---|
| 77 | /** number of I for output, equal to the number of rows of array IQ*/ |
---|
| 78 | /** to be finished */ |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | Point3D Ellipsoid::GetAPoint(double sld) |
---|
| 82 | { |
---|
| 83 | static int max_try = 100; |
---|
| 84 | for (int i = 0; i < max_try; ++i) { |
---|
| 85 | double x = (ran1()-0.5) * 2 * rx_; |
---|
| 86 | double y = (ran1()-0.5) * 2 * ry_; |
---|
| 87 | double z = (ran1()-0.5) * 2 * rz_; |
---|
| 88 | |
---|
| 89 | if ((square(x/rx_) + square(y/ry_) + square(z/rz_)) <= 1){ |
---|
| 90 | Point3D apoint(x,y,z,sld); |
---|
| 91 | return apoint; |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | std::cerr << "Max try " |
---|
| 96 | << max_try |
---|
| 97 | << " is reached while generating a point in ellipsoid" << std::endl; |
---|
| 98 | return Point3D(0, 0, 0); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | bool Ellipsoid::IsInside(const Point3D& point) const |
---|
| 102 | { |
---|
| 103 | //x, y, z axis are internal axis |
---|
| 104 | bool isOutsideX = false; |
---|
| 105 | Point3D pointOnX = point.getInterPoint(GetXaxisPlusEdge(),GetXaxisMinusEdge(),&isOutsideX); |
---|
| 106 | bool isOutsideY = false; |
---|
| 107 | Point3D pointOnY = point.getInterPoint(GetYaxisPlusEdge(),GetYaxisMinusEdge(),&isOutsideY); |
---|
| 108 | bool isOutsideZ = false; |
---|
| 109 | Point3D pointOnZ = point.getInterPoint(GetZaxisPlusEdge(),GetZaxisMinusEdge(),&isOutsideZ); |
---|
| 110 | |
---|
| 111 | if (isOutsideX || isOutsideY || isOutsideZ){ |
---|
| 112 | //one is outside axis is true -> the point is not inside |
---|
| 113 | return false; |
---|
| 114 | } |
---|
| 115 | else{ |
---|
| 116 | Point3D pcenter = GetCenterP(); |
---|
| 117 | double distX = pointOnX.distanceToPoint(pcenter); |
---|
| 118 | double distY = pointOnY.distanceToPoint(pcenter); |
---|
| 119 | double distZ = pointOnZ.distanceToPoint(pcenter); |
---|
| 120 | return ((square(distX/rx_)+square(distY/ry_)+square(distZ/rz_)) <= 1); |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | Point3D Ellipsoid::GetXaxisPlusEdge() const |
---|
| 126 | { |
---|
| 127 | Point3D new_edge(xedge_plus_); |
---|
| 128 | new_edge.Transform(GetOrientation(),GetCenter()); |
---|
| 129 | return new_edge; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | Point3D Ellipsoid::GetXaxisMinusEdge() const |
---|
| 133 | { |
---|
| 134 | Point3D new_edge(xedge_minus_); |
---|
| 135 | new_edge.Transform(GetOrientation(),GetCenter()); |
---|
| 136 | return new_edge; |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | Point3D Ellipsoid::GetYaxisPlusEdge() const |
---|
| 140 | { |
---|
| 141 | Point3D new_edge(yedge_plus_); |
---|
| 142 | new_edge.Transform(GetOrientation(),GetCenter()); |
---|
| 143 | return new_edge; |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | Point3D Ellipsoid::GetYaxisMinusEdge() const |
---|
| 147 | { |
---|
| 148 | Point3D new_edge(yedge_minus_); |
---|
| 149 | new_edge.Transform(GetOrientation(),GetCenter()); |
---|
| 150 | return new_edge; |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | Point3D Ellipsoid::GetZaxisPlusEdge() const |
---|
| 154 | { |
---|
| 155 | Point3D new_edge(zedge_plus_); |
---|
| 156 | new_edge.Transform(GetOrientation(),GetCenter()); |
---|
| 157 | return new_edge; |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | Point3D Ellipsoid::GetZaxisMinusEdge() const |
---|
| 161 | { |
---|
| 162 | Point3D new_edge(zedge_minus_); |
---|
| 163 | new_edge.Transform(GetOrientation(),GetCenter()); |
---|
| 164 | return new_edge; |
---|
| 165 | } |
---|