113 lines
3.4 KiB
C++
113 lines
3.4 KiB
C++
// 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;
|
|
|
|
/// <summary>
|
|
/// A polar vector
|
|
/// </summary>
|
|
/// This will use the polar coordinate system consisting of a angle from a
|
|
/// reference direction and a distance.
|
|
struct Polar {
|
|
public:
|
|
/// <summary>
|
|
/// The distance in meters
|
|
/// </summary>
|
|
/// 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);
|
|
|
|
/// <summary>
|
|
/// Add another polar vector to this polar vector
|
|
/// </summary>
|
|
/// <param name="v">The vector to add</param>
|
|
/// <returns>The result of adding the vector</returns>
|
|
Polar operator+(Polar &v);
|
|
|
|
/// <summary>
|
|
/// Scale the vector uniformly up
|
|
/// </summary>
|
|
/// <param name="factor">The scaling factor</param>
|
|
/// <returns>The scaled vector</returns>
|
|
/// This operation will scale the distance of the vector. The angle will be
|
|
/// unaffected.
|
|
Polar operator*(float factor) const;
|
|
|
|
/// <summary>
|
|
/// Scale the vector uniformly down
|
|
/// </summary>
|
|
/// <param name="factor">The scaling factor</param>
|
|
/// <returns>The scaled vector</returns>
|
|
/// This operation will scale the distance of the vector. The angle will be
|
|
/// unaffected.
|
|
Polar operator/(const float &factor);
|
|
|
|
/// <summary>
|
|
/// The distance between two vectors
|
|
/// </summary>
|
|
/// <param name="v1">The first vector</param>
|
|
/// <param name="v2">The second vector</param>
|
|
/// <returns>The distance between the two vectors</returns>
|
|
static float Distance(Polar &v1, Polar &v2);
|
|
|
|
/// <summary>
|
|
/// Rotate the vector
|
|
/// </summary>
|
|
/// <param name="v">The vector to rotate</param>
|
|
/// <param name="angle">Angle in radias to rotate</param>
|
|
/// <returns>The rotated vector</returns>
|
|
static Polar Rotate(Polar v, Angle angle);
|
|
};
|
|
} // namespace Passer
|
|
using namespace Passer;
|
|
|
|
#include "Spherical.h"
|
|
#include "Vector2.h"
|
|
|
|
#endif |