INET Framework for OMNeT++/OMNEST
inet::Sphere Class Reference

This class represents a 3 dimensional sphere shape. More...

#include <Sphere.h>

Inheritance diagram for inet::Sphere:
inet::ShapeBase

Public Member Functions

 Sphere (double radius)
 
const double getRadius () const
 
void setRadius (double radius)
 
virtual Coord computeBoundingBoxSize () const override
 Computes the 3 dimensional size of the shapes's bounding box. More...
 
virtual bool computeIntersection (const LineSegment &lineSegment, Coord &intersection1, Coord &intersection2, Coord &normal1, Coord &normal2) const override
 Computes the intersection with the given line segment in the shape's coordinate system. More...
 
- Public Member Functions inherited from inet::ShapeBase
 ShapeBase ()
 
virtual ~ShapeBase ()
 

Protected Attributes

double radius
 

Detailed Description

This class represents a 3 dimensional sphere shape.

Constructor & Destructor Documentation

inet::Sphere::Sphere ( double  radius)
23  :
24  radius(radius)
25 {
26 }
double radius
Definition: Sphere.h:31

Member Function Documentation

virtual Coord inet::Sphere::computeBoundingBoxSize ( ) const
inlineoverridevirtual

Computes the 3 dimensional size of the shapes's bounding box.

Implements inet::ShapeBase.

39 { return Coord(radius * 2, radius * 2, radius * 2); }
double radius
Definition: Sphere.h:31
bool inet::Sphere::computeIntersection ( const LineSegment lineSegment,
Coord intersection1,
Coord intersection2,
Coord normal1,
Coord normal2 
) const
overridevirtual

Computes the intersection with the given line segment in the shape's coordinate system.

Implements inet::ShapeBase.

29 {
30  // NOTE: based on http://paulbourke.net/geometry/circlesphere/
31  Coord point1 = lineSegment.getPoint1();
32  Coord point2 = lineSegment.getPoint2();
33  double a, b, c;
34  double bb4ac;
35  Coord dp = point2 - point1;
36  a = dp * dp;
37  b = 2 * (dp.x * point1.x + dp.y * point1.y + dp.z * point1.z);
38  c = point1 * point1 - radius * radius;
39  bb4ac = b * b - 4 * a * c;
40  if (bb4ac >= 0) {
41  double alpha1 = (-b + sqrt(bb4ac)) / (2 * a);
42  double alpha2 = (-b - sqrt(bb4ac)) / (2 * a);
43  bool inside1 = false;
44  if (alpha1 < 0)
45  alpha1 = 0;
46  else if (alpha1 > 1)
47  alpha1 = 1;
48  else
49  inside1 = true;
50  bool inside2 = false;
51  if (alpha2 < 0)
52  alpha2 = 0;
53  else if (alpha2 > 1)
54  alpha2 = 1;
55  else
56  inside2 = true;
57  if (alpha1 == alpha2)
58  return false;
59  else {
60  intersection1 = point1 * (1 - alpha1) + point2 * alpha1;
61  intersection2 = point1 * (1 - alpha2) + point2 * alpha2;
62  if (inside1)
63  normal1 = intersection1 / intersection1.length();
64  if (inside2)
65  normal2 = intersection2 / intersection2.length();
66  return true;
67  }
68  }
69  else
70  return false;
71 }
value< Value, pow< Unit, 1, 2 > > sqrt(const value< Value, Unit > &a)
Definition: Units.h:247
const value< double, compose< units::m, pow< units::s,-1 > > > c(299792458)
double radius
Definition: Sphere.h:31
value< double, units::m > b
Definition: Units.h:1054
const double inet::Sphere::getRadius ( ) const
inline

Referenced by inet::visualizer::PhysicalEnvironmentCanvasVisualizer::refreshDisplay().

36 { return radius; }
double radius
Definition: Sphere.h:31
void inet::Sphere::setRadius ( double  radius)
inline
37 { this->radius = radius; }
double radius
Definition: Sphere.h:31

Member Data Documentation

double inet::Sphere::radius
protected

Referenced by computeIntersection().


The documentation for this class was generated from the following files: