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

This class represents a 3 dimensional shape with 6 pairwise parallel faces. More...

#include <Cuboid.h>

Inheritance diagram for inet::Cuboid:
inet::ShapeBase

Public Member Functions

 Cuboid (const Coord &size)
 
const CoordgetSize () const
 
void setSize (const Coord &size)
 
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...
 
virtual void computeVisibleFaces (std::vector< std::vector< Coord >> &faces, const RotationMatrix &rotation, const RotationMatrix &viewRotation) const
 
- Public Member Functions inherited from inet::ShapeBase
 ShapeBase ()
 
virtual ~ShapeBase ()
 

Protected Member Functions

bool isInsideX (const Coord &point) const
 
bool isInsideY (const Coord &point) const
 
bool isInsideZ (const Coord &point) const
 

Protected Attributes

Coord size
 

Detailed Description

This class represents a 3 dimensional shape with 6 pairwise parallel faces.

Constructor & Destructor Documentation

◆ Cuboid()

inet::Cuboid::Cuboid ( const Coord size)
16  :
17  size(size)
18 {
19 }

Member Function Documentation

◆ computeBoundingBoxSize()

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

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

Implements inet::ShapeBase.

33 { return size; }

◆ computeIntersection()

bool inet::Cuboid::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.

22 {
23  // NOTE: based on https://www.iquilezles.org/www/articles/intersectors/intersectors.htm
24  const auto p1 = lineSegment.getPoint1();
25  const auto p2 = lineSegment.getPoint2();
26  Coord direction = p1 == p2 ? Coord::ZERO : (p2 - p1).getNormalized();
27  Coord m = Coord::ONE.getDividedElementwise(direction);
28  m.clamp(-1E+100, 1E+100); // fix axis algined direction
29  Coord n = m.getMultipliedElementwise(p1);
30  Coord k = m.getAbs().getMultipliedElementwise(size / 2);
31  Coord t1 = -n - k;
32  Coord t2 = -n + k;
33  double tN = math::maxnan(math::maxnan(t1.x, t1.y), t1.z);
34  double tF = math::minnan(math::minnan(t2.x, t2.y), t2.z);
35  double l = lineSegment.length();
36  if (tN > tF || tF < 0.0 || tN > l) {
37  intersection1 = intersection2 = normal1 = normal2 = Coord::NIL;
38  return false;
39  }
40  else {
41  if (tN < 0) {
42  intersection1 = p1;
43  normal1 = Coord::NIL;
44  }
45  else {
46  intersection1 = p1 + direction * tN;
47  normal1 = -direction.getSign().getMultipliedElementwise(t1.getYzx().getStep(t1).getMultipliedElementwise(t1.getZxy().getStep(t1)));
48  }
49  if (l < tF) {
50  intersection2 = p2;
51  normal2 = Coord::NIL;
52  }
53  else {
54  intersection2 = p1 + direction * tF;
55  normal2 = -direction.getSign().getMultipliedElementwise(t2.getYzx().getStep(t2).getMultipliedElementwise(t2.getZxy().getStep(t2)));
56  }
57  return true;
58  }
59 }

Referenced by inet::visualizer::VisualizerBase::getContactPosition(), and inet::BvhTree::intersectWithLineSegment().

◆ computeVisibleFaces()

void inet::Cuboid::computeVisibleFaces ( std::vector< std::vector< Coord >> &  faces,
const RotationMatrix rotation,
const RotationMatrix viewRotation 
) const
virtual
62 {
63  // TODO specialize
64  std::vector<Coord> polygonPoints;
65  polygonPoints.push_back(Coord(-size.x / 2, -size.y / 2, -size.z / 2));
66  polygonPoints.push_back(Coord(-size.x / 2, size.y / 2, -size.z / 2));
67  polygonPoints.push_back(Coord(size.x / 2, size.y / 2, -size.z / 2));
68  polygonPoints.push_back(Coord(size.x / 2, -size.y / 2, -size.z / 2));
69  Polygon base(polygonPoints);
70  Prism prism(size.z, base);
71  prism.computeVisibleFaces(faces, rotation, viewRotation);
72 }

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

◆ getSize()

const Coord& inet::Cuboid::getSize ( ) const
inline

◆ isInsideX()

bool inet::Cuboid::isInsideX ( const Coord point) const
inlineprotected
25 { return -size.x / 2 <= point.x && point.x <= size.x / 2; }

◆ isInsideY()

bool inet::Cuboid::isInsideY ( const Coord point) const
inlineprotected
26 { return -size.y / 2 <= point.y && point.y <= size.y / 2; }

◆ isInsideZ()

bool inet::Cuboid::isInsideZ ( const Coord point) const
inlineprotected
27 { return -size.z / 2 <= point.z && point.z <= size.z / 2; }

◆ setSize()

void inet::Cuboid::setSize ( const Coord size)
inline
32 { this->size = size; }

Member Data Documentation

◆ size

Coord inet::Cuboid::size
protected

The documentation for this class was generated from the following files:
inet::Coord::getSign
Coord getSign() const
Definition: Coord.h:200
inet::Coord::ZERO
static const Coord ZERO
Definition: Coord.h:27
inet::Coord::getMultipliedElementwise
Coord getMultipliedElementwise(const Coord &a) const
Definition: Coord.h:244
inet::Coord::ONE
static const Coord ONE
Definition: Coord.h:28
inet::Cuboid::size
Coord size
Definition: Cuboid.h:22
inet::Coord::x
double x
Definition: Coord.h:36
inet::Coord::getDividedElementwise
Coord getDividedElementwise(const Coord &a) const
Definition: Coord.h:233
inet::math::maxnan
const T maxnan(const T &a, const T &b)
This function properly and symmetrically handles NaNs in contrast with std::max and std::fmax.
Definition: INETMath.h:234
inet::Coord::z
double z
Definition: Coord.h:38
inet::physicallayer::k
const double k
Definition: Qam1024Modulation.cc:14
inet::Coord::NIL
static const Coord NIL
Constant with all values set to 0.
Definition: Coord.h:26
inet::math::minnan
const T minnan(const T &a, const T &b)
This function properly and symmetrically handles NaNs in contrast with std::min and std::fmin.
Definition: INETMath.h:216
inet::units::values::m
value< double, units::m > m
Definition: Units.h:1233
inet::Coord::y
double y
Definition: Coord.h:37