Use Vector{2,3}D.GetLength ()

This commit is contained in:
Alexander Krotov
2017-04-05 10:56:05 +03:00
parent 67162e4935
commit dd3a4d2a43
3 changed files with 4 additions and 14 deletions

View File

@@ -73,7 +73,7 @@ Angles::Angles (double p, double t)
Angles::Angles (Vector v)
: phi (std::atan2 (v.y, v.x)),
theta (std::acos (v.z / sqrt (v.x*v.x + v.y*v.y + v.z*v.z)))
theta (std::acos (v.z / v.GetLength ()))
{
}

View File

@@ -92,20 +92,13 @@ double
CalculateDistance (const Vector3D &a, const Vector3D &b)
{
NS_LOG_FUNCTION (a << b);
double dx = b.x - a.x;
double dy = b.y - a.y;
double dz = b.z - a.z;
double distance = std::sqrt (dx * dx + dy * dy + dz * dz);
return distance;
return (b - a).GetLength ();
}
double
CalculateDistance (const Vector2D &a, const Vector2D &b)
{
NS_LOG_FUNCTION (a << b);
double dx = b.x - a.x;
double dy = b.y - a.y;
double distance = std::sqrt (dx * dx + dy * dy);
return distance;
return (b - a).GetLength ();
}
std::ostream &operator << (std::ostream &os, const Vector3D &vector)

View File

@@ -88,10 +88,7 @@ MobilityModel::GetDistanceFrom (Ptr<const MobilityModel> other) const
double
MobilityModel::GetRelativeSpeed (Ptr<const MobilityModel> other) const
{
double x = GetVelocity().x - other->GetVelocity().x;
double y = GetVelocity().y - other->GetVelocity().y;
double z = GetVelocity().z - other->GetVelocity().z;
return sqrt( (x*x) + (y*y) + (z*z) );
return (GetVelocity () - other->GetVelocity ()).GetLength ();
}
void