source: sasview/src/sas/sascalc/simulation/geoshapespy/libgeoshapespy/ellipsoid.cc @ dd5bf63

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since dd5bf63 was d85c194, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 9 years ago

Remaining modules refactored

  • Property mode set to 100644
File size: 3.5 KB
Line 
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
10using namespace std;
11
12Ellipsoid::Ellipsoid()
13{
14  rx_ = 0;
15  ry_ = 0;
16  rz_ = 0;
17}
18
19Ellipsoid::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
32Ellipsoid::~Ellipsoid()
33{
34}
35
36void Ellipsoid::SetRadii(double rx, double ry, double rz)
37{
38  rx_ = rx;
39  ry_ = ry;
40  rz_ = rz;
41}
42
43double Ellipsoid::GetRadiusX()
44{
45  return rx_;
46}
47
48double Ellipsoid::GetRadiusY()
49{
50  return ry_;
51}
52
53double Ellipsoid::GetRadiusZ()
54{
55  return rz_;
56}
57
58double Ellipsoid::GetMaxRadius()
59{
60  double maxr = max(max(rx_,ry_),max(ry_,rz_));
61  return maxr;
62}
63
64ShapeType Ellipsoid::GetShapeType() const
65{
66  return ELLIPSOID;
67}
68
69double Ellipsoid::GetVolume()
70{
71  double V = (4./3.)*pi*rx_*ry_*rz_;
72  return V;
73}
74
75void 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
81Point3D 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
101bool 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
125Point3D Ellipsoid::GetXaxisPlusEdge() const
126{
127  Point3D new_edge(xedge_plus_);
128  new_edge.Transform(GetOrientation(),GetCenter());
129  return new_edge;
130}
131
132Point3D Ellipsoid::GetXaxisMinusEdge() const
133{
134  Point3D new_edge(xedge_minus_);
135  new_edge.Transform(GetOrientation(),GetCenter());
136  return new_edge;
137}
138
139Point3D Ellipsoid::GetYaxisPlusEdge() const
140{
141  Point3D new_edge(yedge_plus_);
142  new_edge.Transform(GetOrientation(),GetCenter());
143  return new_edge;
144}
145
146Point3D Ellipsoid::GetYaxisMinusEdge() const
147{
148  Point3D new_edge(yedge_minus_);
149  new_edge.Transform(GetOrientation(),GetCenter());
150  return new_edge;
151}
152
153Point3D Ellipsoid::GetZaxisPlusEdge() const
154{
155  Point3D new_edge(zedge_plus_);
156  new_edge.Transform(GetOrientation(),GetCenter());
157  return new_edge;
158}
159
160Point3D Ellipsoid::GetZaxisMinusEdge() const
161{
162  Point3D new_edge(zedge_minus_);
163  new_edge.Transform(GetOrientation(),GetCenter());
164  return new_edge;
165}
Note: See TracBrowser for help on using the repository browser.