Exemplo n.º 1
0
        static LineSegment generateRandomLine()
        {
            var p1 = new Vec2();
            var p2 = new Vec2();
            do
            {
                p1.X = Tools.rnd.Next(size);
                p1.Y = Tools.rnd.Next(size);

                p2.X = Tools.rnd.Next(size);
                p2.Y = Tools.rnd.Next(size);
            }
            while ((p1 - p2).Length() < minLineLength);

            var l = new LineSegment() { pos1 = p1, pos2 = p2 };

            return l;
        }
Exemplo n.º 2
0
        static IEnumerable<Vec2> generatePointsOnLine(LineSegment l, float epsilon)
        {
            var linePoints = (int)(lineDensity * (l.pos1 - l.pos2).Length());
            for (int i = 0; i < linePoints; ++i)
            {
                var d = l.pos2 - l.pos1;
                var a = (float)Tools.rnd.NextDouble();

                var x = l.pos1.X + d.X * a;
                var y = l.pos1.Y + d.Y * a;
                var p = l.pos1 + (d * a);
                /// HACK: replace with normal dist
                p.X += epsilon * (float)(2.0 * (Tools.rnd.NextDouble() - 0.5));
                p.Y += epsilon * (float)(2.0 * (Tools.rnd.NextDouble() - 0.5));

                yield return p;
            }
        }