source: sasview/src/sas/sascalc/simulation/geoshapespy/libgeoshapespy/sphere.cc @ eb8da5f

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.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since eb8da5f was d85c194, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 9 years ago

Remaining modules refactored

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[aa639ea]1/** \file Sphere.cc */
2#include <cmath>
3#include <cassert>
4#include "sphere.h"
5#include "myutil.h"
6
7Sphere::Sphere()
8{
9  r_ = 0;
10}
11
12Sphere::Sphere(double radius)
13{
14  r_ = radius;
15}
16
17Sphere::~Sphere()
18{
19}
20
21void Sphere::SetRadius(double r)
22{
23  r_ = r;
24}
25
26double Sphere::GetRadius()
27{
28  return r_;
29}
30
31double Sphere::GetMaxRadius()
32{
33  double maxr = r_;
34  return maxr;
35}
36
37ShapeType Sphere::GetShapeType() const
38{
39  return SPHERE;
40}
41
42double Sphere::GetVolume()
43{
44  double V = 4 * pi / 3 * triple(r_);
45  return V;
46}
47
48void Sphere::GetFormFactor(IQ * iq)
49{
50  /** number of I for output, equal to the number of rows of array IQ*/
51  int numI = iq->iq_data.dim1();
52  double qmin = iq->GetQmin();
53  double qmax = iq->GetQmax();
54
55  assert(numI > 0);
56  assert(qmin > 0);
57  assert(qmax > 0);
58  assert( qmax > qmin );
59 
60  double logMin = log10(qmin);
61  double z = logMin;
62  double logMax = log10(qmax);
63  double delta = (logMax - logMin) / (numI-1);
64
65  for(int i = 0; i < numI; ++i) {
66
67    /** temp for Q*/
68    double q = pow(z, 10);
69 
70    double bes = 3.0 * (sin(q*r_) - q*r_*cos(q*r_)) / triple(q) / triple(r_);
71
72    /** double f is the temp for I, should be equal to one when q is 0*/
73    double f = bes * bes;
74
75    /** IQ[i][0] is Q,Q starts from qmin (non zero),q=0 handle separately IQ[i][1] is IQ*/
76    iq->iq_data[i][0]= q;
77    iq->iq_data[i][1]= f;
78
79    z += delta;
80  } 
81}
82
83Point3D Sphere::GetAPoint(double sld)
84{
85  static int max_try = 100;
86  for (int i = 0; i < max_try; ++i) {
87    double x = (ran1()-0.5) * 2 * r_;
88    double y = (ran1()-0.5) * 2 * r_;   
89    double z = (ran1()-0.5) * 2 * r_;
90
91    Point3D apoint(x,y,z,sld);
92    if (apoint.distanceToPoint(Point3D(0,0,0)) <=r_ ) //dist to origin give sphere shape
93      return apoint;
94  }
95
96  std::cerr << "Max try "
97            << max_try
98            << " is reached while generating a point in sphere" << std::endl;
99  return Point3D(0, 0, 0);
100}
101
102bool Sphere::IsInside(const Point3D& point) const
103{
104  return point.distanceToPoint(Point3D(center_[0], center_[1], center_[2])) <= r_;
105  cout << "distance = " << point.distanceToPoint(Point3D(center_[0], center_[1], center_[2])) << endl;
106}
Note: See TracBrowser for help on using the repository browser.