From 54c788d74eb94e2680ad5eea1071e4cd475b2991 Mon Sep 17 00:00:00 2001 From: Tommaso Zugno Date: Thu, 4 Jun 2020 19:18:46 +0200 Subject: [PATCH] spectrum: fix wrong usage of atan --- .../examples/three-gpp-channel-example.cc | 18 +++++---------- .../test/three-gpp-channel-test-suite.cc | 22 ++++++------------- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/src/spectrum/examples/three-gpp-channel-example.cc b/src/spectrum/examples/three-gpp-channel-example.cc index 2ba7e8e2a..e21635c25 100644 --- a/src/spectrum/examples/three-gpp-channel-example.cc +++ b/src/spectrum/examples/three-gpp-channel-example.cc @@ -68,19 +68,11 @@ DoBeamforming (Ptr thisDevice, Ptr thisAnt // compute the azimuth and the elevation angles Angles completeAngle (bPos,aPos); - double posX = bPos.x - aPos.x; - double phiAngle = atan ((bPos.y - aPos.y) / posX); - - if (posX < 0) - { - phiAngle = phiAngle + M_PI; - } - if (phiAngle < 0) - { - phiAngle = phiAngle + 2 * M_PI; - } - - double hAngleRadian = fmod ((phiAngle + M_PI),2 * M_PI - M_PI); // the azimuth angle + double hAngleRadian = fmod (completeAngle.phi, 2.0 * M_PI); // the azimuth angle + if (hAngleRadian < 0) + { + hAngleRadian += 2.0 * M_PI; + } double vAngleRadian = completeAngle.theta; // the elevation angle // retrieve the number of antenna elements diff --git a/src/spectrum/test/three-gpp-channel-test-suite.cc b/src/spectrum/test/three-gpp-channel-test-suite.cc index 9d3440cdf..df1866841 100644 --- a/src/spectrum/test/three-gpp-channel-test-suite.cc +++ b/src/spectrum/test/three-gpp-channel-test-suite.cc @@ -402,28 +402,20 @@ ThreeGppSpectrumPropagationLossModelTest::~ThreeGppSpectrumPropagationLossModelT void ThreeGppSpectrumPropagationLossModelTest::DoBeamforming (Ptr thisDevice, Ptr thisAntenna, Ptr otherDevice, Ptr otherAntenna) { - uint8_t noPlane = 1; ThreeGppAntennaArrayModel::ComplexVector antennaWeights; Vector aPos = thisDevice->GetNode ()->GetObject ()->GetPosition (); Vector bPos = otherDevice->GetNode ()->GetObject ()->GetPosition (); + // compute the azimuth and the elevation angles Angles completeAngle (bPos,aPos); - double posX = bPos.x - aPos.x; - double phiAngle = atan ((bPos.y - aPos.y) / posX); - - if (posX < 0) - { - phiAngle = phiAngle + M_PI; - } - if (phiAngle < 0) - { - phiAngle = phiAngle + 2 * M_PI; - } - - double hAngleRadian = fmod ((phiAngle + (M_PI / noPlane)),2 * M_PI / noPlane) - (M_PI / noPlane); - double vAngleRadian = completeAngle.theta; + double hAngleRadian = fmod (completeAngle.phi, 2.0 * M_PI); // the azimuth angle + if (hAngleRadian < 0) + { + hAngleRadian += 2.0 * M_PI; + } + double vAngleRadian = completeAngle.theta; // the elevation angle int totNoArrayElements = thisAntenna->GetNumberOfElements (); double power = 1 / sqrt (totNoArrayElements);