Пример #1
0
 public double Distance(double2 v)
 {
     double2 delta = v - this;
     double len = delta.Dot(delta);
     return (double)System.Math.Sqrt((double)len);
 }
Пример #2
0
 public double2(double2 f)
 {
     x = f.x;
     y = f.y;
 }
Пример #3
0
 public static double2 Lerp(double2 a, double2 b, double alpha)
 {
     return (a * (1.0f - alpha)) + (b * alpha);
 }
Пример #4
0
 public double2 Rotate(double rot)
 {
     double2 result = new double2();
     result.x = (double)(System.Math.Cos(rot) * x - System.Math.Sin(rot) * y);
     result.y = (double)(System.Math.Sin(rot) * x + System.Math.Cos(rot) * y);
     return result;
 }
Пример #5
0
 public double2 Saturate(double2 v)
 {
     return v.Min(new double2(1, 1)).Max(new double2(0, 0));
 }
Пример #6
0
 public double2 Reflect(double2 normal)
 {
     return this - normal * this.Dot(normal) * 2.0f;
     //v = i - 2 * dot(i, n) * n.
 }
Пример #7
0
 public double2 PowSign(double v)
 {
     double2 ret = new double2();
     ret.x = System.Math.Sign(x) * (double)System.Math.Pow(System.Math.Abs(x), v);
     ret.y = System.Math.Sign(y) * (double)System.Math.Pow(System.Math.Abs(y), v);
     return ret;
 }
Пример #8
0
 public double2 Min(double2 v)
 {
     double2 ret = new double2();
     ret.x = x < v.x ? x : v.x;
     ret.y = y < v.y ? y : v.y;
     return ret;
 }
Пример #9
0
 public double2 Max(double2 v)
 {
     double2 ret = new double2();
     ret.x = x > v.x ? x : v.x;
     ret.y = y > v.y ? y : v.y;
     return ret;
 }
Пример #10
0
 // math functions
 public double Dot(double2 v)
 {
     return (x * v.x) + (y * v.y);
 }