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


C# Segment.Rotate方法代码示例

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


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

示例1: collide

        public bool collide()
        {
            // Retrieve the environment singleton
            Environment env = Environment.Instance;

            // Create the initial segment for the angle and starting point of the bumper
            double a = angle / nbsegments;
            Segment vector = new Segment(env.AgentPosition, env.AgentPosition + new Point(-radius, 0));
            vector = vector.Rotate(-(180 - angle) / 2);
            vector = vector.Rotate(env.AgentAngle);

            // Create the bumper segments
            for (int i = 0; i < nbsegments; i++)
            {
                Segment seg = new Segment();
                seg.Start = vector.End;
                vector = vector.Rotate(-a);
                seg.End = vector.End;

                segments[i] = seg;
            }

            // Check if any of the segment collides
            lock (env.Segments)
            {
                foreach (Segment s in env.Segments)
                {
                    foreach (Segment b in segments)
                    {
                        if (b.Intersects(s) != null)
                            return true;
                    }
                }
            }

            return false;
        }
开发者ID:vipuldivyanshu92,项目名称:Projects,代码行数:37,代码来源:Bumper.cs

示例2: straight

        public void straight(int speed)
        {
            // Retrieve the environment singleton
            Environment env = Environment.Instance;

            // Calculate the next position
            Segment nextPos = new Segment();
            nextPos.Start.X = env.AgentPosition.X;
            nextPos.Start.Y = env.AgentPosition.Y;
            nextPos.End.X = env.AgentPosition.X;
            nextPos.End.Y = env.AgentPosition.Y + 1;
            nextPos = nextPos.Rotate(env.AgentAngle);

            env.AgentPosition = nextPos.End;

            // Sleep to give the speed limitation behaviour
            if (env.SimulationSpeed != 0)
                System.Threading.Thread.Sleep((int)(1000 / (speed * env.SimulationSpeed)));
        }
开发者ID:vipuldivyanshu92,项目名称:Projects,代码行数:19,代码来源:Movement.cs

示例3: getDistance

        public double getDistance()
        {
            // Retrieve the environment
            Environment env = Environment.Instance;
            double minDistance = -1;

            // Create the offset segment
            Segment offset = new Segment();
            offset.Start = env.AgentPosition;
            offset.End = env.AgentPosition + new Point(0, lengthOffset);

            // Create the range segment
            Segment full = new Segment();
            full.Start = env.AgentPosition;
            full.End = env.AgentPosition + new Point(0, length + lengthOffset);

            range = new Segment();
            range.Start = offset.Rotate(env.AgentAngle + angleOffset).End;
            range.End = full.Rotate(env.AgentAngle + angleOffset).End;

            // Go through the list of segments, not neat O(n) but execution
            // fast enough for this simulation purpose
            foreach (Segment s in env.Segments)
            {
                Point p;
                if ((p = range.Intersects(s)) != null)
                {
                    double v = p.Distance(range.Start);
                    if (v < minDistance || minDistance == -1)
                    {
                        minDistance = v;
                    }
                }
            }

            return minDistance;
        }
开发者ID:vipuldivyanshu92,项目名称:Projects,代码行数:37,代码来源:ProximitySensor.cs


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