ProjectTo() 개인적인 메소드

Projects an axis.
private ProjectTo ( Vector2 axis, float &min, float &max ) : void
axis Vector2 The Axis.
min float The Minimum.
max float The Maximum.
리턴 void
예제 #1
0
        /// <summary>
        ///     A value indicating whether the Polygon has a seperating axis.
        /// </summary>
        /// <param name="other">The other Polygon.</param>
        /// <param name="minOverlap">The MinimumOverlap.</param>
        /// <param name="axis">The Axis.</param>
        /// <returns>True of seperating axis.</returns>
        private bool HasSeparatingAxisTo(Polygon other, ref float minOverlap, ref Vector2 axis)
        {
            int prev = Points.Length - 1;

            for (int i = 0; i < Points.Length; i++)
            {
                Vector2 edge = Points[i] - Points[prev];

                var v = new Vector2(edge.X, edge.Y);
                v = v.CrossProduct();
                v.Normalize();

                float aMin, aMax, bMin, bMax;
                ProjectTo(v, out aMin, out aMax);
                other.ProjectTo(v, out bMin, out bMax);

                if ((aMax < bMin) || (bMax < aMin))
                {
                    return(true);
                }


                float overlapping = aMax < bMax ? aMax - bMin : bMax - aMin;
                if (overlapping < minOverlap)
                {
                    minOverlap = overlapping;
                    axis       = v;
                }

                prev = i;
            }

            return(false);
        }
예제 #2
0
        /// <summary>
        ///     A value indicating whether the Polygon has a seperating axis.
        /// </summary>
        /// <param name="other">The other Polygon.</param>
        /// <param name="minOverlap">The MinimumOverlap.</param>
        /// <param name="axis">The Axis.</param>
        /// <returns>True of seperating axis.</returns>
        private bool HasSeparatingAxisTo(Polygon other, ref float minOverlap, ref Vector2 axis)
        {
            int prev = Points.Length - 1;
            for (int i = 0; i < Points.Length; i++)
            {
                Vector2 edge = Points[i] - Points[prev];

                var v = new Vector2(edge.X, edge.Y);
                v = v.CrossProduct();
                v.Normalize();

                float aMin, aMax, bMin, bMax;
                ProjectTo(v, out aMin, out aMax);
                other.ProjectTo(v, out bMin, out bMax);

                if ((aMax < bMin) || (bMax < aMin))
                    return true;

                float overlapping = aMax < bMax ? aMax - bMin : bMax - aMin;
                if (overlapping < minOverlap)
                {
                    minOverlap = overlapping;
                    axis = v;
                }

                prev = i;
            }

            return false;
        }