Пример #1
0
        public float DistanceSquaredToLineSegment(Vec2 v, Vec2 w, out Vec2 closestPointOnLineSegment)
        {
            Vec2  vec2_1 = this;
            float num1   = v.DistanceSquared(w);

            if ((double)num1 == 0.0)
            {
                closestPointOnLineSegment = v;
            }
            else
            {
                float num2 = Vec2.DotProduct(vec2_1 - v, w - v) / num1;
                if ((double)num2 < 0.0)
                {
                    closestPointOnLineSegment = v;
                }
                else if ((double)num2 > 1.0)
                {
                    closestPointOnLineSegment = w;
                }
                else
                {
                    Vec2 vec2_2 = v + (w - v) * num2;
                    closestPointOnLineSegment = vec2_2;
                }
            }
            return(vec2_1.DistanceSquared(closestPointOnLineSegment));
        }
Пример #2
0
        public static Vec2 Slerp(Vec2 start, Vec2 end, float percent)
        {
            float  num1 = MBMath.ClampFloat(Vec2.DotProduct(start, end), -1f, 1f);
            float  num2 = (float)Math.Acos((double)num1) * percent;
            Vec2   vec2 = end - start * num1;
            double num3 = (double)vec2.Normalize();

            return(start * (float)Math.Cos((double)num2) + vec2 * (float)Math.Sin((double)num2));
        }