source: sasview/src/sas/sascalc/simulation/geoshapespy/libgeoshapespy/cylinder.cc @ 7b4676a

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

Remaining modules refactored

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/** \file Cylinder.cc */
2#include <cmath>
3#include <cassert>
4#include "cylinder.h"
5#include "myutil.h"
6
7Cylinder::Cylinder()
8{
9  r_ = 0;
10}
11
12Cylinder::Cylinder(double radius,double length)
13{
14  r_ = radius;
15  l_ = length;
16  topcenter_ = Point3D(0,length/2,0);
17  botcenter_ = Point3D(0,-length/2,0);
18}
19
20Cylinder::~Cylinder()
21{
22}
23
24void Cylinder::SetRadius(double r)
25{
26  r_ = r;
27}
28
29void Cylinder::SetLength(double l)
30{
31  l_ = l;
32}
33
34double Cylinder::GetRadius()
35{
36  return r_;
37}
38
39double Cylinder::GetLength()
40{
41  return l_;
42}
43
44double Cylinder::GetMaxRadius()
45{
46  double maxr = sqrt(4*r_*r_ + l_*l_)/2;
47  return maxr;
48}
49
50ShapeType Cylinder::GetShapeType() const
51{
52  return CYLINDER;
53}
54
55double Cylinder::GetVolume()
56{
57  double V = pi * square(r_) * l_;
58  return V;
59}
60
61void Cylinder::GetFormFactor(IQ * iq)
62{
63  /** number of I for output, equal to the number of rows of array IQ*/
64  /** to be finished */
65}
66
67Point3D Cylinder::GetAPoint(double sld)
68{
69  /** cylinder long axis is along Y to match vtk actor */
70  static int max_try = 100;
71  for (int i = 0; i < max_try; ++i) {
72    double x = (ran1()-0.5) * 2 * r_;
73    double z = (ran1()-0.5) * 2 * r_;   
74    double y = (ran1()-0.5) * l_;
75
76    Point3D apoint(x,y,z,sld);
77    //check the cross section on xy plane within a sphere at (0,)
78    if (apoint.distanceToPoint(Point3D(0,y,0)) <= r_ ) 
79      return apoint;
80  }
81
82  std::cerr << "Max try "
83            << max_try
84            << " is reached while generating a point in cylinder" << std::endl;
85  return Point3D(0, 0, 0);
86}
87
88bool Cylinder::IsInside(const Point3D& point) const
89{
90  bool isOutside = false;
91  double distToLine = point.distanceToLine(GetTopCenter(),GetBotCenter(),&isOutside);
92
93  return (distToLine <= r_ && !isOutside);
94}
95
96Point3D Cylinder::GetTopCenter() const
97{
98  Point3D new_center(topcenter_);
99  new_center.Transform(GetOrientation(),GetCenter());
100  return new_center;
101}
102
103Point3D Cylinder::GetBotCenter() const
104{
105  Point3D new_center(botcenter_);
106  new_center.Transform(GetOrientation(),GetCenter());
107  return new_center;
108}
Note: See TracBrowser for help on using the repository browser.