MoonTools.Bonk/Bonk/Vector2Extensions.cs

19 lines
539 B
C#
Raw Normal View History

2019-10-31 23:19:30 +00:00
using System.Numerics;
2019-10-25 10:46:47 +00:00
2020-02-21 02:07:59 +00:00
namespace MoonTools.Bonk.Extensions
2019-10-25 10:46:47 +00:00
{
2019-10-25 19:42:39 +00:00
internal static class Vector2Extensions
2019-10-25 10:46:47 +00:00
{
2019-10-26 05:00:34 +00:00
internal static float Cross(this Vector2 a, Vector2 b)
2019-10-25 10:46:47 +00:00
{
2019-10-26 05:00:34 +00:00
return Vector3.Cross(new Vector3(a.X, a.Y, 0), new Vector3(b.X, b.Y, 0)).Z;
2019-10-25 10:46:47 +00:00
}
2019-10-26 05:00:34 +00:00
internal static Vector2 Perpendicular(this Vector2 a, Vector2 b)
2019-10-25 10:46:47 +00:00
{
2019-10-26 05:00:34 +00:00
var ab = b - a;
return a.Cross(b) > 0 ? Vector2.Normalize(new Vector2(ab.Y, ab.X)) : Vector2.Normalize(new Vector2(ab.Y, -ab.X));
2019-10-25 10:46:47 +00:00
}
}
2020-02-21 02:07:59 +00:00
}