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)
 
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

◆ Sphere()

inet::Sphere::Sphere ( double  radius)
14  :
15  radius(radius)
16 {
17 }

Member Function Documentation

◆ computeBoundingBoxSize()

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

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

Implements inet::ShapeBase.

29 { return Coord(radius * 2, radius * 2, radius * 2); }

◆ computeIntersection()

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.

20 {
21  // NOTE: based on http://paulbourke.net/geometry/circlesphere/
22  Coord point1 = lineSegment.getPoint1();
23  Coord point2 = lineSegment.getPoint2();
24  double a, b, c;
25  double bb4ac;
26  Coord dp = point2 - point1;
27  a = dp * dp;
28  b = 2 * (dp.x * point1.x + dp.y * point1.y + dp.z * point1.z);
29  c = point1 * point1 - radius * radius;
30  bb4ac = b * b - 4 * a * c;
31  if (bb4ac >= 0) {
32  double alpha1 = (-b + sqrt(bb4ac)) / (2 * a);
33  double alpha2 = (-b - sqrt(bb4ac)) / (2 * a);
34  bool inside1 = false;
35  if (alpha1 < 0)
36  alpha1 = 0;
37  else if (alpha1 > 1)
38  alpha1 = 1;
39  else
40  inside1 = true;
41  bool inside2 = false;
42  if (alpha2 < 0)
43  alpha2 = 0;
44  else if (alpha2 > 1)
45  alpha2 = 1;
46  else
47  inside2 = true;
48  if (alpha1 == alpha2)
49  return false;
50  else {
51  intersection1 = point1 * (1 - alpha1) + point2 * alpha1;
52  intersection2 = point1 * (1 - alpha2) + point2 * alpha2;
53  if (inside1)
54  normal1 = intersection1 / intersection1.length();
55  if (inside2)
56  normal2 = intersection2 / intersection2.length();
57  return true;
58  }
59  }
60  else
61  return false;
62 }

◆ getRadius()

◆ setRadius()

void inet::Sphere::setRadius ( double  radius)
inline
27 { this->radius = radius; }

Member Data Documentation

◆ radius

double inet::Sphere::radius
protected

Referenced by computeIntersection().


The documentation for this class was generated from the following files:
inet::units::constants::c
const value< double, compose< units::m, pow< units::s, -1 > > > c(299792458)
inet::units::sqrt
value< Value, pow< Unit, 1, 2 > > sqrt(const value< Value, Unit > &a)
Definition: Units.h:272
inet::Sphere::radius
double radius
Definition: Sphere.h:21
inet::units::values::b
value< int64_t, units::b > b
Definition: Units.h:1241