Added Polar::Rotate

This commit is contained in:
Pascal Serrarens 2023-01-27 16:53:42 +01:00
parent 882dfdfcdb
commit 295a2b3902
2 changed files with 20 additions and 4 deletions

View File

@ -8,7 +8,8 @@
/// <summary>
/// A polar vector
/// </summary>
/// This will use the polar coordinate system consisting of a angle from a reference direction and a distance.
/// This will use the polar coordinate system consisting of a angle from a
/// reference direction and a distance.
struct Polar {
public:
/// <summary>
@ -43,7 +44,7 @@ struct Polar {
/// </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
@ -64,7 +65,8 @@ struct Polar {
/// </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.
/// This operation will scale the distance of the vector. The angle will be
/// unaffected.
Polar operator*(float factor) const;
/// <summary>
@ -72,7 +74,8 @@ struct Polar {
/// </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.
/// This operation will scale the distance of the vector. The angle will be
/// unaffected.
Polar operator/(const float& factor);
/// <summary>
@ -82,6 +85,14 @@ struct Polar {
/// <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);
};
#endif

View File

@ -66,3 +66,8 @@ Polar Polar::operator*(float f) const {
Polar Polar::operator/(const float& f) {
return Polar(this->angle, this->distance / f);
}
Polar Polar::Rotate(Polar v, float angle) {
v.angle += angle;
return v;
}