Use Angle type for Polar
This commit is contained in:
parent
8a2ce21abc
commit
9bea94f21c
33
Polar.cpp
33
Polar.cpp
@ -35,20 +35,20 @@ Polar::Polar(Spherical s) {
|
||||
|
||||
const Polar Polar::zero = Polar(0, 0);
|
||||
|
||||
float Polar::Distance(const Polar &v1, const Polar &v2) {
|
||||
float d =
|
||||
Angle::CosineRuleSide(v1.distance, v2.distance, v2.angle - v1.angle);
|
||||
float Polar::Distance(Polar &v1, Polar &v2) {
|
||||
float d = Angle::CosineRuleSide(v1.distance, v2.distance,
|
||||
(float)v2.angle - (float)v1.angle);
|
||||
return d;
|
||||
}
|
||||
|
||||
Polar Polar::operator+(const Polar &v2) const {
|
||||
Polar Polar::operator+(Polar &v2) {
|
||||
if (v2.distance == 0)
|
||||
return Polar(this->distance,
|
||||
this->angle); // Polar(this->angle, this->distance);
|
||||
if (this->distance == 0)
|
||||
return v2;
|
||||
|
||||
float deltaAngle = Angle::Normalize(v2.angle - this->angle);
|
||||
float deltaAngle = Angle::Normalize(v2.angle - (float)this->angle);
|
||||
float rotation = deltaAngle < 0 ? 180 + deltaAngle : 180 - deltaAngle;
|
||||
|
||||
if (rotation == 180 && v2.distance > 0) {
|
||||
@ -64,24 +64,25 @@ Polar Polar::operator+(const Polar &v2) const {
|
||||
float angle =
|
||||
Angle::CosineRuleAngle(newDistance, this->distance, v2.distance);
|
||||
|
||||
float newAngle = deltaAngle < 0 ? Angle::Normalize(this->angle - angle)
|
||||
: Angle::Normalize(this->angle + angle);
|
||||
float newAngle =
|
||||
deltaAngle < 0 ? (float)this->angle - angle : (float)this->angle + angle;
|
||||
newAngle = Angle::Normalize(newAngle);
|
||||
Polar vector = Polar(newDistance, newAngle); // Polar(newAngle, newDistance);
|
||||
return vector;
|
||||
}
|
||||
|
||||
Polar Polar::operator-() {
|
||||
Polar vector =
|
||||
Polar(this->distance,
|
||||
this->angle - 180); // Polar(this->angle - 180, this->distance);
|
||||
Polar vector = Polar(this->distance,
|
||||
(float)this->angle -
|
||||
180); // Polar(this->angle - 180, this->distance);
|
||||
return vector;
|
||||
}
|
||||
|
||||
Polar Polar::operator-(const Polar &v2) const {
|
||||
Polar vector =
|
||||
*this + Polar(v2.distance,
|
||||
v2.angle - 180); //(Polar(v2.angle - 180, v2.distance));
|
||||
return vector;
|
||||
Polar Polar::operator-(Polar &v2) {
|
||||
// Polar vector = *this + Polar(v2.distance, (float)v2.angle - 180);
|
||||
//(Polar(v2.angle - 180, v2.distance));
|
||||
Polar vector = -v2;
|
||||
return *this + v2;
|
||||
}
|
||||
|
||||
Polar Polar::operator*(float f) const {
|
||||
@ -94,7 +95,7 @@ Polar Polar::operator/(const float &f) {
|
||||
this->angle); // Polar(this->angle, this->distance / f);
|
||||
}
|
||||
|
||||
Polar Polar::Rotate(Polar v, float angle) {
|
||||
Polar Polar::Rotate(Polar v, Angle angle) {
|
||||
v.angle = Angle::Normalize(v.angle + angle);
|
||||
return v;
|
||||
}
|
10
Polar.h
10
Polar.h
@ -23,7 +23,7 @@ public:
|
||||
/// The angle in degrees, clockwise rotation
|
||||
/// </summary>
|
||||
/// The angle is normalized to -180 .. 180
|
||||
float angle;
|
||||
Angle angle;
|
||||
/// <summary>
|
||||
/// The distance in meters
|
||||
/// </summary>
|
||||
@ -70,14 +70,14 @@ public:
|
||||
/// </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;
|
||||
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+(const Polar &v) const;
|
||||
Polar operator+(Polar &v);
|
||||
|
||||
/// <summary>
|
||||
/// Scale the vector uniformly up
|
||||
@ -103,7 +103,7 @@ public:
|
||||
/// <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);
|
||||
static float Distance(Polar &v1, Polar &v2);
|
||||
|
||||
/// <summary>
|
||||
/// Rotate the vector
|
||||
@ -111,7 +111,7 @@ public:
|
||||
/// <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);
|
||||
static Polar Rotate(Polar v, Angle angle);
|
||||
};
|
||||
} // namespace Passer
|
||||
#include "Spherical.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user