当前位置: 首页>>代码示例>>C#>>正文


C# Vector2.LSProjectOn方法代码示例

本文整理汇总了C#中System.Vector2.LSProjectOn方法的典型用法代码示例。如果您正苦于以下问题:C# Vector2.LSProjectOn方法的具体用法?C# Vector2.LSProjectOn怎么用?C# Vector2.LSProjectOn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Vector2的用法示例。


在下文中一共展示了Vector2.LSProjectOn方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetClosestOutsidePoint

        public static Vector2 GetClosestOutsidePoint(Vector2 from, List<Geometry.Polygon> polygons)
        {
            var result = new List<Vector2>();

            foreach (var poly in polygons)
            {
                for (var i = 0; i <= poly.Points.Count - 1; i++)
                {
                    var sideStart = poly.Points[i];
                    var sideEnd = poly.Points[(i == poly.Points.Count - 1) ? 0 : i + 1];

                    result.Add(from.LSProjectOn(sideStart, sideEnd).SegmentPoint);
                }
            }
            return result.MinOrDefault(vector2 => Vector2.Distance(from));
        }
开发者ID:yashine59fr,项目名称:PortAIO,代码行数:16,代码来源:Evader.cs

示例2: GetSpellProjection

        public static Vector2 GetSpellProjection(this Spell spell, Vector2 pos, bool predictPos = false)
        {
            if (spell.spellType == SpellType.Line
                || spell.spellType == SpellType.Arc)
            {
                if (predictPos)
                {
                    var spellPos = spell.currentSpellPosition;
                    var spellEndPos = spell.GetSpellEndPosition();

                    return pos.LSProjectOn(spellPos, spellEndPos).SegmentPoint;
                }
                else
                {
                    return pos.LSProjectOn(spell.startPos, spell.endPos).SegmentPoint;
                }
            }
            else if (spell.spellType == SpellType.Circular)
            {
                return spell.endPos;
            }

            return Vector2.Zero;
        }
开发者ID:yashine59fr,项目名称:PortAIO,代码行数:24,代码来源:Spell.cs

示例3: FindLineCircleIntersections

        //http://csharphelper.com/blog/2014/09/determine-where-a-line-intersects-a-circle-in-c/
        // Find the points of intersection.
        public static int FindLineCircleIntersections(
            Vector2 center, float radius,
            Vector2 from, Vector2 to,
            out Vector2 intersection1, out Vector2 intersection2)
        {
            float cx = center.X;
            float cy = center.Y;
            float dx, dy, A, B, C, det, t;

            dx = to.X - from.X;
            dy = to.Y - from.Y;

            A = dx * dx + dy * dy;
            B = 2 * (dx * (from.X - cx) + dy * (from.Y - cy));
            C = (from.X - cx) * (from.X - cx) +
                (from.Y - cy) * (from.Y - cy) -
                radius * radius;

            det = B * B - 4 * A * C;
            if ((A <= 0.0000001) || (det < 0))
            {
                // No real solutions.
                intersection1 = new Vector2(float.NaN, float.NaN);
                intersection2 = new Vector2(float.NaN, float.NaN);
                return 0;
            }
            else if (det == 0)
            {
                // One solution.
                t = -B / (2 * A);
                intersection1 =
                    new Vector2(from.X + t * dx, from.Y + t * dy);
                intersection2 = new Vector2(float.NaN, float.NaN);

                var projection1 = intersection1.LSProjectOn(from, to);
                if (projection1.IsOnSegment)
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
            else
            {
                // Two solutions.
                t = (float)((-B + Math.Sqrt(det)) / (2 * A));
                intersection1 =
                    new Vector2(from.X + t * dx, from.Y + t * dy);
                t = (float)((-B - Math.Sqrt(det)) / (2 * A));
                intersection2 =
                    new Vector2(from.X + t * dx, from.Y + t * dy);

                var projection1 = intersection1.LSProjectOn(from, to);
                var projection2 = intersection2.LSProjectOn(from, to);

                if (projection1.IsOnSegment && projection2.IsOnSegment)
                {
                    return 2;
                }
                else if (projection1.IsOnSegment && !projection2.IsOnSegment)
                {
                    return 1;
                }
                else if (!projection1.IsOnSegment && projection2.IsOnSegment)
                {
                    intersection1 = intersection2;
                    return 1;
                }

                return 0;
            }
        }
开发者ID:CainWolf,项目名称:PortAIO,代码行数:76,代码来源:MathUtils.cs


注:本文中的System.Vector2.LSProjectOn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。