Class for storing host positions. More...
#include <Coord.h>
Public Member Functions | |
| Coord (bool use2D=false) | |
| Initialize a 3d (default) or 2d coordinate with the origin. | |
| Coord (double x, double y, double z) | |
| Initializes 3D coordinate. | |
| Coord (double x, double y) | |
| Initializes 2D coordinate. | |
| Coord (const Coord &pos) | |
| Initializes coordinate from other coordinate. | |
| Coord (const Coord *pos) | |
| Initializes coordinate from other coordinate. | |
| std::string | info () const |
| Returns a string with the value of the coordinate. | |
| Coord | operator*= (double f) |
| Multiplies this coordinate vector by a real number. | |
| Coord | operator/= (double f) |
| Divides this coordinate vector by a real number. | |
| Coord | operator+= (const Coord &a) |
| Adds coordinate vector 'a' to this. | |
| Coord | operator= (const Coord &a) |
| Assigns a this. | |
| Coord | operator-= (const Coord &a) |
| Subtracts coordinate vector 'a' from this. | |
| double | distance (const Coord &a) const |
| Returns the distance to Coord 'a'. | |
| double | sqrdist (const Coord &a) const |
| Returns distance^2 to Coord 'a' (omits square root). | |
| double | sqrTorusDist (const Coord &b, const Coord &playgroundSize) const |
| Returns the squared distance on a torus of this to Coord 'b' (omits square root). | |
| double | squareLength () const |
| Returns the square of the length of this Coords position vector. | |
| double | length () const |
| Returns the length of this Coords position vector. | |
| double | getX () const |
| Getter for the x coordinate. | |
| void | setX (double x) |
| Setter for the x coordinate. | |
| double | getY () const |
| Getter for the y coordinate. | |
| void | setY (double y) |
| Setter for the y coordinate. | |
| double | getZ () const |
| Getter for the z coordinate. | |
| void | setZ (double z) |
| Setter for the z coordinate. | |
| bool | isValid () const |
| Returns true if this coordinate is valid. | |
| bool | is2D () const |
| Returns true if this coordinate is two-dimensional. | |
| bool | is3D () const |
| Returns true if this coordinate is three-dimensional. | |
| bool | isInRectangle (const Coord &upperLeftCorner, const Coord &lowerRightCorner) const |
| Checks if this coordinate is inside a specified rectangle. | |
| bool | isInBoundary (const Coord &lowerBound, const Coord &upperBound) const |
| Checks if this coordinate is inside the passed boundary of [lowerBound, upperBound). | |
| Coord | min (const Coord &a) |
| Returns the minimal coordinates. | |
| Coord | max (const Coord &a) |
| Returns the maximal coordinates. | |
Static Public Attributes | |
| static const double | UNDEFINED = 0.0 |
| Constant representing an undefined value. | |
Protected Attributes | |
| bool | use2DFlag |
| Member to store whether this coordinate is 2D or 3D. | |
x, y and z coordinate of the position. | |
| double | x |
| double | y |
| double | z |
Friends | |
| Coord | operator+ (const Coord &a, const Coord &b) |
| Adds two coordinate vectors. | |
| Coord | operator- (const Coord &a, const Coord &b) |
| Subtracts two coordinate vectors. | |
| Coord | operator* (const Coord &a, double f) |
| Multiplies a coordinate vector by a real number. | |
| Coord | operator/ (const Coord &a, double f) |
| Divides a coordinate vector by a real number. | |
| bool | operator== (const Coord &a, const Coord &b) |
| Tests whether two coordinate vectors are equal. | |
| bool | operator!= (const Coord &a, const Coord &b) |
| Tests whether two coordinate vectors are not equal. | |
| bool | operator> (const Coord &a, const Coord &b) |
| Tests whether this coordinate vector is strictly larger than another coordinate vector (component-wise). | |
| bool | operator< (const Coord &a, const Coord &b) |
| Tests whether this coordinate vector is strictly smaller than another coordinate vector (component-wise). | |
Class for storing host positions.
Class for a storing a position / vector. Some comparison and basic arithmetic operators on Coord structures are implemented.
Note: This class can work 2-dimensional or 3-dimensional. The dimension of a Coord can only be set at construction time. The only way to change it afterwards is by assigning Coord a new value with the overloaded "="-operator. So every time you create a new Coord variable you should make sure to use the proper constructor. Since most time you won't have own constructors in Omnet-modules every member variable of type Coord becomes 3D at the beginning (because the default-constructor creates a 3D-Coord). In this case you should give it the right dimension by assigning them a new value in the "initialize()"-Method by a line like this:
coordMember = Coord(x, y); <- 2D coordMember = Coord(x, y, z); <- 3D
See the constructors for more details.
Most methods of Coord does not check for dimension compatibility. For example the overloaded "+"-operator does not check if both Coord are of the same dimension. The user has to assure the proper use of this methods!
Definition at line 61 of file Coord.h.
| double Coord::distance | ( | const Coord & | a | ) | const [inline] |
Returns the distance to Coord 'a'.
Does not check for dimension compatibility!
Definition at line 244 of file Coord.h.
References length().
Referenced by LineSegmentsMobilityBase::beginNextMove(), ChannelAccess::calculatePropagationDelay(), TurtleMobility::executeStatement(), UWBIRStochasticPathlossModel::filterSignal(), UWBIRIEEE802154APathlossModel::filterSignal(), IntensityModel::filterSignal(), BaseMobility::handleIfOutside(), MoBANCoordinator::mainProcess(), MoBANLocal::setTargetPosition(), and ConstSpeedMobility::setTargetPosition().
| double Coord::getZ | ( | ) | const [inline] |
Getter for the z coordinate.
This method should return Coord::UNDEFINED if this is a two-dimensional coordinate. If not, the proper function of the Coord-methods can't be assured.
Definition at line 310 of file Coord.h.
Referenced by BaseMobility::checkIfOutside(), BaseWorldUtility::getRandomPosition(), BaseMobility::goToBorder(), BaseConnectionManager::GridCoord::GridCoord(), BaseConnectionManager::initialize(), BaseWorldUtility::initializeIfNecessary(), MoBANLocal::insideWorld(), MoBANCoordinator::mainProcess(), BaseMobility::playgroundSizeZ(), BaseMobility::reflectCoordinate(), BaseMobility::reflectIfOutside(), MoBANCoordinator::selectDestination(), BaseMobility::updatePosition(), and BaseMobility::wrapIfOutside().
{ return z; }
Checks if this coordinate is inside the passed boundary of [lowerBound, upperBound).
Does not check for dimension compatibility!
| lowerBound | The lower boundary. | |
| upperBound | the upper boundary. |
Definition at line 368 of file Coord.h.
References use2DFlag.
Referenced by PostureTransition::findAreaType(), and MoBANCoordinator::isInsideWorld().
{
return x >= lowerBound.x && x < upperBound.x &&
y >= lowerBound.y && y < upperBound.y &&
(use2DFlag || (z >= lowerBound.z && z < upperBound.z));
}
| bool Coord::isInRectangle | ( | const Coord & | upperLeftCorner, | |
| const Coord & | lowerRightCorner | |||
| ) | const [inline] |
Checks if this coordinate is inside a specified rectangle.
Does not check for dimension compatibility!
| upperLeftCorner | The upper left corner of the rectangle. | |
| lowerRightCorner | the lower right corner of the rectangle. |
Definition at line 353 of file Coord.h.
References use2DFlag.
Referenced by BaseMobility::initialize().
{
return x >= upperLeftCorner.x && x <= lowerRightCorner.x &&
y >= upperLeftCorner.y && y <= lowerRightCorner.y &&
(use2DFlag || (z >= upperLeftCorner.z && z <= lowerRightCorner.z));
}
| bool Coord::isValid | ( | ) | const [inline] |
| void Coord::setZ | ( | double | z | ) | [inline] |
Setter for the z coordinate.
This method does not check its dimension! So never call it if you are working with two-dimensional coordinates! A 2D-Coord looses its functionality if the z-value becomes another value than Coord::UNDEFINED
Definition at line 322 of file Coord.h.
Referenced by BaseMobility::checkIfOutside(), BaseMobility::goToBorder(), BaseMobility::initialize(), BaseConnectionManager::initialize(), MoBANLocal::insideWorld(), max(), min(), MoBANCoordinator::readConfigurationFile(), BaseMobility::reflectCoordinate(), BaseMobility::reflectIfOutside(), MoBANCoordinator::selectDestination(), MoBANLocal::setTargetPosition(), and BaseMobility::wrapIfOutside().
{this->z = z;}
| double Coord::sqrdist | ( | const Coord & | a | ) | const [inline] |
Returns distance^2 to Coord 'a' (omits square root).
Does not check for dimension compatibility!
Definition at line 254 of file Coord.h.
References squareLength().
Referenced by SimplePathlossModel::calcPathloss(), SimplePathlossModel::filterSignal(), BreakpointPathlossModel::filterSignal(), and BaseConnectionManager::updateNicConnections().
{
Coord dist=*this-a;
return dist.squareLength();
}
Returns the squared distance on a torus of this to Coord 'b' (omits square root).
Does not check for dimension compatibility!
Definition at line 8 of file Coord.cc.
Referenced by SimplePathlossModel::calcPathloss(), SimplePathlossModel::filterSignal(), BreakpointPathlossModel::filterSignal(), and BaseConnectionManager::updateNicConnections().
{
double xDist = fabs(x - b.x);
double yDist = fabs(y - b.y);
double zDist = fabs(z - b.z);
/*
* on a torus the end and the begin of the axes are connected so you
* get a circle. On a circle the distance between two points can't be greater
* than half of the circumference.
* If the normal distance between two points on one axis is bigger than
* half of the playground there must be a "shorter way" over the playground
* border on this axis
*/
if(xDist * 2.0 > playgroundSize.x)
{
xDist = playgroundSize.x - xDist;
}
//same for y- and z-coordinate
if(yDist * 2.0 > playgroundSize.y)
{
yDist = playgroundSize.y - yDist;
}
if(zDist * 2.0 > playgroundSize.z)
{
zDist = playgroundSize.z - zDist;
}
return xDist * xDist + yDist * yDist + zDist * zDist;
}
Tests whether two coordinate vectors are equal.
Because coordinates are of type double, this is done through the FWMath::close function.
Does not check for dimension compatibility!
Definition at line 224 of file Coord.h.
{
return FWMath::close(a.x, b.x) && FWMath::close(a.y, b.y) && FWMath::close(a.z, b.z);
}
1.7.1