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


C# Vector2d.Negate方法代码示例

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


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

示例1: Loop

        public void Loop(TimeSpan loopTime)
        {
            foreach (var connection in Graph.Connectivities)
            {
                var node1 = connection.Node1;
                var node2 = connection.Node2;

                var distance = Vector2d.GetDistance(node1.Position, node2.Position);
                if (distance < 0.1)
                {
                    // Jitter
                    distance = 0.1;
                }

                var forceS = Settings.DistanceToForceFct(distance);
                forceS *= Settings.ForceFactor;
                forceS *= connection.Connectivity;

                var dX = Math.Max(0.1, node1.Position.X - node2.Position.X);
                var dY = Math.Max(0.1, node1.Position.Y - node2.Position.Y);

                Vector2d force = new Vector2d(forceS * dX / distance, forceS * dY / distance);
                node1.ForceN.AddTo(force.Negate());
                node2.ForceN.AddTo(force);
            }
        }
开发者ID:mbrenn,项目名称:burnsystems.evolutionary,代码行数:26,代码来源:ConnectionForceSimulation.cs

示例2: Loop

        public void Loop(TimeSpan loopTime)
        {
            var random = new Random();
            var nodeCount = graph.Nodes.Count;

            for (var n = 0; n < (nodeCount - 1); n++)
            {
                for (var m = n + 1; m < nodeCount; m++)
                {
                    var node1 = graph.Nodes[n];
                    var node2 = graph.Nodes[m];

                    var distance = Vector2d.GetDistance(node1.Position, node2.Position);

                    if (distance < Settings.MinimumDistance)
                    {
                        var forceS = (distance - Settings.MinimumDistance) / Settings.MinimumDistance;

                        var dX = node1.Position.X - node2.Position.X;
                        var dY = node1.Position.Y - node2.Position.Y;

                        if ( distance < 0.01)
                        {
                            dX = (random.NextDouble() - 0.5) * 2;
                            dY = Math.Sqrt(1 - dX * dX);
                        }
                        else
                        {
                            dX /= distance;
                            dY /= distance;
                        }

                        Vector2d force = new Vector2d(forceS * dX, forceS * dY);
                        node1.ForceN.AddTo(force.Negate());
                        node2.ForceN.AddTo(force);
                    }
                }
            }
        }
开发者ID:mbrenn,项目名称:burnsystems.evolutionary,代码行数:39,代码来源:MinimumDistanceForceSimulation.cs


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