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) {
|
||||||
|
4
Polar.h
4
Polar.h
@ -5,6 +5,8 @@
|
|||||||
#ifndef POLAR_H
|
#ifndef POLAR_H
|
||||||
#define POLAR_H
|
#define POLAR_H
|
||||||
|
|
||||||
|
class Vector2;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A polar vector
|
/// A polar vector
|
||||||
/// </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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user