104 lines
3.0 KiB
C++
104 lines
3.0 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
|
|
|
|
struct Vector2;
|
|
|
|
/// <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 angle in degrees, clockwise rotation
|
|
/// </summary>
|
|
/// The angle is normalized to -180 .. 180
|
|
float angle;
|
|
/// <summary>
|
|
/// The distance in meters
|
|
/// </summary>
|
|
/// The distance should never be negative
|
|
float distance;
|
|
|
|
/// <summary>
|
|
/// Create a new polar vector with zero degrees and distance
|
|
/// </summary>
|
|
Polar();
|
|
/// <summary>
|
|
/// Create a new polar vector
|
|
/// </summary>
|
|
/// <param name="angle">The angle in degrees, clockwise rotation</param>
|
|
/// <param name="distance">The distance in meters</param>
|
|
Polar(float angle, float distance);
|
|
|
|
Polar(Vector2 v);
|
|
|
|
/// <summary>
|
|
/// A polar vector with zero degrees and distance
|
|
/// </summary>
|
|
const static Polar zero;
|
|
|
|
/// <summary>
|
|
/// Negate the polar vector.
|
|
/// </summary>
|
|
/// This will rotate the vector by 180 degrees. Distance will stay the same.
|
|
/// <returns>The negated vector</returns>
|
|
|
|
Polar operator-();
|
|
/// <summary>
|
|
/// Substract a polar vector from this coordinate
|
|
/// </summary>
|
|
/// <param name="v">The vector to subtract from this vector</param>
|
|
/// <returns>The result of the subtraction</returns>
|
|
Polar operator-(const Polar &v) const;
|
|
|
|
/// <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+(const Polar &v) const;
|
|
|
|
/// <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(const Polar &v1, const 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, float angle);
|
|
};
|
|
|
|
#include "Vector2.h"
|
|
|
|
#endif |