// This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0.If a copy of the MPL was not distributed with this // file, You can obtain one at https ://mozilla.org/MPL/2.0/. #ifndef POLAR_H #define POLAR_H #include "Angle.h" namespace Passer { struct Vector2; struct Spherical; /// /// A polar vector /// /// This will use the polar coordinate system consisting of a angle from a /// reference direction and a distance. struct Polar { public: /// /// The distance in meters /// /// The distance should never be negative /// @brief The distance in meters /// @remark The distance shall never be negative float distance; /// @brief The angle in degrees clockwise rotation /// @remark The angle shall be between -180 .. 180 Angle angle; /// @brief A new vector with polar coordinates with zero degrees and distance Polar(); /// @brief A new vector with polar coordinates /// @param distance The distance in meters /// @param angle The angle in degrees, clockwise rotation /// @note The distance is automatically converted to a positive value. /// @note The angle is automatically normalized to -180 .. 180 Polar(float distance, Angle angle); /// @brief Convert a vector from 2D carthesian coordinates to polar /// coordinates /// @param v The vector to convert Polar(Vector2 v); /// @brief Convert a vector from spherical coordinates to polar coordinates /// @param s The vector to convert /// @note The resulting vector will be projected on the horizontal plane Polar(Spherical s); /// @brief A polar vector with zero degrees and distance const static Polar zero; bool operator==(const Polar &v); /// @brief Negate the vector /// @return The negated vector /// This will rotate the vector by 180 degrees. Distance will stay the same. Polar operator-(); /// @brief Subtract a polar vector from this vector /// @param v The vector to subtract /// @return The result of the subtraction Polar operator-(Polar &v); /// /// Add another polar vector to this polar vector /// /// The vector to add /// The result of adding the vector Polar operator+(Polar &v); /// /// Scale the vector uniformly up /// /// The scaling factor /// The scaled vector /// This operation will scale the distance of the vector. The angle will be /// unaffected. Polar operator*(float factor) const; /// /// Scale the vector uniformly down /// /// The scaling factor /// The scaled vector /// This operation will scale the distance of the vector. The angle will be /// unaffected. Polar operator/(const float &factor); /// /// The distance between two vectors /// /// The first vector /// The second vector /// The distance between the two vectors static float Distance(Polar &v1, Polar &v2); /// /// Rotate the vector /// /// The vector to rotate /// Angle in radias to rotate /// The rotated vector static Polar Rotate(Polar v, Angle angle); }; } // namespace Passer using namespace Passer; #include "Spherical.h" #include "Vector2.h" #endif