Add convertsion from Vector2
This commit is contained in:
parent
c01640429c
commit
d01c5d9de5
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "Angle.h"
|
#include "Angle.h"
|
||||||
#include "Polar.h"
|
#include "Polar.h"
|
||||||
|
#include "Vector2.h"
|
||||||
|
|
||||||
Polar::Polar() {
|
Polar::Polar() {
|
||||||
angle = 0.0F;
|
angle = 0.0F;
|
||||||
@ -19,6 +20,12 @@ Polar::Polar(float newAngle, float newDistance) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Polar::Polar(Vector2 v) {
|
||||||
|
float signY = (v.y >= 0) - (v.y < 0);
|
||||||
|
angle = atan2(v.y, signY * sqrt(v.y * v.y + v.x * v.x)) * Angle::Rad2Deg;
|
||||||
|
distance = v.magnitude();
|
||||||
|
}
|
||||||
|
|
||||||
const Polar Polar::zero = Polar(0, 0);
|
const Polar Polar::zero = Polar(0, 0);
|
||||||
|
|
||||||
float Polar::Distance(const Polar &v1, const Polar &v2) {
|
float Polar::Distance(const Polar &v1, const Polar &v2) {
|
||||||
|
14
Polar.h
14
Polar.h
@ -5,13 +5,15 @@
|
|||||||
#ifndef POLAR_H
|
#ifndef POLAR_H
|
||||||
#define POLAR_H
|
#define POLAR_H
|
||||||
|
|
||||||
|
class Vector2;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A polar vector
|
/// A polar vector
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// This will use the polar coordinate system consisting of a angle from a
|
/// This will use the polar coordinate system consisting of a angle from a
|
||||||
/// reference direction and a distance.
|
/// reference direction and a distance.
|
||||||
struct Polar {
|
struct Polar {
|
||||||
public:
|
public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The angle in degrees, clockwise rotation
|
/// The angle in degrees, clockwise rotation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -34,6 +36,8 @@ struct Polar {
|
|||||||
/// <param name="distance">The distance in meters</param>
|
/// <param name="distance">The distance in meters</param>
|
||||||
Polar(float angle, float distance);
|
Polar(float angle, float distance);
|
||||||
|
|
||||||
|
Polar(Vector2 v);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A polar vector with zero degrees and distance
|
/// A polar vector with zero degrees and distance
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -51,14 +55,14 @@ struct Polar {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="v">The vector to subtract from this vector</param>
|
/// <param name="v">The vector to subtract from this vector</param>
|
||||||
/// <returns>The result of the subtraction</returns>
|
/// <returns>The result of the subtraction</returns>
|
||||||
Polar operator-(const Polar& v) const;
|
Polar operator-(const Polar &v) const;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add another polar vector to this polar vector
|
/// Add another polar vector to this polar vector
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="v">The vector to add</param>
|
/// <param name="v">The vector to add</param>
|
||||||
/// <returns>The result of adding the vector</returns>
|
/// <returns>The result of adding the vector</returns>
|
||||||
Polar operator+(const Polar& v) const;
|
Polar operator+(const Polar &v) const;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Scale the vector uniformly up
|
/// Scale the vector uniformly up
|
||||||
@ -76,7 +80,7 @@ struct Polar {
|
|||||||
/// <returns>The scaled vector</returns>
|
/// <returns>The scaled vector</returns>
|
||||||
/// This operation will scale the distance of the vector. The angle will be
|
/// This operation will scale the distance of the vector. The angle will be
|
||||||
/// unaffected.
|
/// unaffected.
|
||||||
Polar operator/(const float& factor);
|
Polar operator/(const float &factor);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The distance between two vectors
|
/// The distance between two vectors
|
||||||
@ -84,7 +88,7 @@ struct Polar {
|
|||||||
/// <param name="v1">The first vector</param>
|
/// <param name="v1">The first vector</param>
|
||||||
/// <param name="v2">The second vector</param>
|
/// <param name="v2">The second vector</param>
|
||||||
/// <returns>The distance between the two vectors</returns>
|
/// <returns>The distance between the two vectors</returns>
|
||||||
static float Distance(const Polar& v1, const Polar& v2);
|
static float Distance(const Polar &v1, const Polar &v2);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Rotate the vector
|
/// Rotate the vector
|
||||||
|
Loading…
x
Reference in New Issue
Block a user