Exemplo n.º 1
0
        private static IEnumerable <Line> CreateCylinderStartLines2(double alpha, int zLimit, int yLimit)
        {
            var b            = Sqrt(8) / 2;
            var alpha2       = 90 - alpha;
            var beta         = 180 - 45 - alpha2;
            var a            = 2 - Sin(alpha2.ToRadian()) / Sin(beta.ToRadian()) * b;
            var r            = CausticCylinder.R;
            var verticalLine = new Line((0, 0, -r), (-r, 0, 0));
            var distance     = Vector3D.AbsoluteValue(verticalLine.SecondPoint - verticalLine.BasePoint);
            var midpoint     = verticalLine.GetPointOnLine(distance / 2);

            var(xDir, yDir, zDir) = (-1, 0, -1 + a) - midpoint;

            var zRange = Numpy.LinSpace(0, distance, zLimit).ToList();
            var yRange = Numpy.LinSpace(0, CausticCylinder.L, yLimit).ToList();

            foreach (var z in zRange)
            {
                foreach (var y in yRange)
                {
                    var(x, y2, z2) = verticalLine.GetPointOnLine(z);
                    yield return(Line.FromPointAndDirection((x, y, z2), (xDir, yDir, zDir)));
                }
            }
        }
Exemplo n.º 2
0
        private static IEnumerable <Line> OctoSphereStartOLD(double alpha, int xLimit, int yLimit)
        {
            var origin     = new Vector3D(0, 0, 0);
            var planePoint = new Vector3D(1, 1, 0);
            var pointA     = new Vector3D(2, 0, 0);
            var pointB     = new Vector3D(0, 2, 0);
            var distanceFromOriginAtTheBase           = Vector3D.AbsoluteValue(planePoint - origin);
            var distanceFromOriginAtTheBaseOnTheXAxis = distanceFromOriginAtTheBase / Sin(45.0.ToRadian());
            var pointOnXAxisOnTheBase   = new Vector3D(distanceFromOriginAtTheBaseOnTheXAxis, 0.0, 0.0);
            var horizontalDistanceAtTop = Sqrt(8);
            var halfDistanceAtTop       = horizontalDistanceAtTop / 2;
            var horizontalDirection     = (planePoint - pointOnXAxisOnTheBase).Normalize();
            var halfPoint         = (0, 0, 2);
            var verticalDistance  = Vector3D.AbsoluteValue(planePoint - halfPoint);
            var verticalDirection = (planePoint - halfPoint).Normalize();
            var horizontalJumps   = Numpy.LinSpace(0, horizontalDistanceAtTop, xLimit).ToList();
            var verticalJumps     = Numpy.LinSpace(0, verticalDistance, yLimit).ToList();
            var midPoint          = (pointA + (horizontalJumps[xLimit / 2] * horizontalDirection)) + (verticalJumps[yLimit / 2] * verticalDirection);
            var mainDirection     = origin - midPoint;

            foreach (var horizontalJump in horizontalJumps)
            {
                var point = pointA + (horizontalJump * horizontalDirection);
                foreach (var verticalJump in verticalJumps)
                {
                    var finalPoint = point + (verticalJump * verticalDirection);
                    var direction  = RotateVector3D(mainDirection.X, mainDirection.Y, mainDirection.Z, alpha.ToRadian());
                    yield return(Line.FromPointAndDirection(finalPoint, direction));
                }
            }
        }
Exemplo n.º 3
0
        private static IEnumerable <Line> OctoSphereStart(double alpha, int xLimit, int yLimit)
        {
            var xPoint   = new Vector3D(2, 0, 0);
            var yPoint   = new Vector3D(0, 2, 0);
            var topPoint = new Vector3D(0, 0, 2);

            var distance         = Vector3D.AbsoluteValue(yPoint - xPoint);
            var bottomLine       = new Line(xPoint, yPoint);
            var bottomPoint      = bottomLine.GetPointOnLine(distance / 2);
            var verticalDistance = Vector3D.AbsoluteValue(bottomPoint - topPoint);

            var horizontalDirection = (yPoint - xPoint).Normalize();
            var verticalDirection   = (topPoint - bottomPoint).Normalize();
            var mainDirection       = -1 * (new Plane(xPoint, yPoint, topPoint).NormalVector);

            var horizontalJumps = Numpy.LinSpace(0, distance, xLimit);
            var verticalJumps   = Numpy.LinSpace(0, verticalDistance, yLimit);

            foreach (var horizontalJump in horizontalJumps)
            {
                var horiPoint = xPoint + (horizontalJump * horizontalDirection);
                foreach (var verticalJump in verticalJumps)
                {
                    var finalPoint = horiPoint + (verticalJump * verticalDirection);
                    var direction  = RotateVector3D(mainDirection.X, mainDirection.Y, mainDirection.Z, alpha.ToRadian());
                    yield return(Line.FromPointAndDirection(finalPoint, direction));
                }
            }
        }
Exemplo n.º 4
0
 public Cylinder(Vector3D top, Vector3D bottom, PointChecker checker, double radius)
 {
     Checker         = checker;
     Radius          = radius;
     TopCenter       = top;
     BottomCenter    = bottom;
     _cylinderHeight = Vector3D.AbsoluteValue(BottomCenter - TopCenter);
 }
Exemplo n.º 5
0
        private static IEnumerable <Line> OctoSphereTri()
        {
            const double alpha    = 0.0;
            var          xPoint   = new Vector3D(2, 0, 0);
            var          yPoint   = new Vector3D(0, 2, 0);
            var          topPoint = new Vector3D(0, 0, 2);

            var side1 = Vector3D.AbsoluteValue(yPoint - xPoint);
            var side2 = Vector3D.AbsoluteValue(topPoint - xPoint);
            var side3 = Vector3D.AbsoluteValue(topPoint - yPoint);
            var bigT  = Heron(side1, side2, side3);

            var distance         = Vector3D.AbsoluteValue(yPoint - xPoint);
            var bottomLine       = new Line(xPoint, yPoint);
            var bottomPoint      = bottomLine.GetPointOnLine(distance / 2);
            var verticalDistance = Vector3D.AbsoluteValue(bottomPoint - topPoint);

            var horizontalDirection = (yPoint - xPoint).Normalize();
            var verticalDirection   = (topPoint - bottomPoint).Normalize();
            var mainDirection       = -1 * (new Plane(xPoint, yPoint, topPoint).NormalVector);

            var horizontalJumps = Numpy.LinSpace(0, distance, 500);
            var verticalJumps   = Numpy.LinSpace(0, verticalDistance, 500);

            foreach (var horizontalJump in horizontalJumps)
            {
                var horiPoint = xPoint + (horizontalJump * horizontalDirection);
                foreach (var verticalJump in verticalJumps)
                {
                    var finalPoint = horiPoint + (verticalJump * verticalDirection);
                    var dist1      = Vector3D.AbsoluteValue(finalPoint - xPoint);
                    var dist2      = Vector3D.AbsoluteValue(finalPoint - yPoint);
                    var dist3      = Vector3D.AbsoluteValue(finalPoint - topPoint);

                    var T1 = Heron(side1, dist1, dist2);
                    var T2 = Heron(side2, dist1, dist3);
                    var T3 = Heron(side3, dist2, dist3);
                    var T  = T1 + T2 + T3;

                    var difference = Abs(bigT - T);
                    if (difference >= 0e-5)
                    {
                        yield return(Line.GetInvalid());
                    }
                    else
                    {
                        var direction = RotateVector3D(mainDirection.X, mainDirection.Y, mainDirection.Z, alpha.ToRadian());
                        yield return(Line.FromPointAndDirection(finalPoint, direction));
                    }
                }
            }
        }
Exemplo n.º 6
0
        private static Sphere CreateSphereBarrier(IEnumerable <ITrackBoundary> trackObjects, [NotNull] Sphere sphere)
        {
            if (sphere == null)
            {
                throw new ArgumentNullException(nameof(sphere));
            }

            var walls = trackObjects.OfType <Wall>().GroupBy(x =>
                                                             x.Corners.Select(y => Vector3D.AbsoluteValue(y - sphere.Center)).Min())
                        .OrderBy(x => x.Key).SelectMany(x => x).Take(3).ToList();
            var corner = walls.Select(x => x.Corners).Aggregate((x, y) => x.Intersect(y).ToList()).Single();

            var intersectionPoints = walls.Select(sphere.GetInterSection).ToList();
            var barrier            = new Plane(intersectionPoints[0], intersectionPoints[1], intersectionPoints[2]);
            var sign    = barrier.DeterminePointPosition(corner);
            var checker = new PointChecker(barrier, sign);

            sphere.Checker = checker;
            return(sphere);
        }
Exemplo n.º 7
0
        private static void NearAutoCorrelation(double radius)
        {
            var startingPoints = VeryCloseStartingPoints(2);
            var distances      = new List <List <Vector3D> >();

            Parallel.ForEach(startingPoints, (startLine, _, l) =>
            {
                var room = TrackFactory.RoomWithPlaneRoof(radius);
                room.NumberOfIterations = 2_000;
                room.Start(startLine);
                WriteSequence(room, false, l.ToString());
                lock (LockObject)
                {
                    Console.WriteLine($"Done with {startLine.Direction}");
                    distances.Add(room.EveryHitpoint);
                }
            });
            Directory.CreateDirectory(@"C:\Users\haraszti\Desktop\szakdoga\NearAuto2\kozel\");
            var distance = distances[0].Zip(distances[1], (x, y) => Vector3D.AbsoluteValue(x - y));

            File.WriteAllLines(@"C:\Users\haraszti\Desktop\szakdoga\NearAuto2\kozel\dist.txt",
                               distance.Select(x => x.ToString(CultureInfo.CurrentCulture)));
        }
Exemplo n.º 8
0
        private static Cylinder CalculateCylinder(Line first, Line second, Line wallLine, double radius)
        {
            var angle               = Vector3D.Angle(first.Direction, second.Direction);
            var distance            = Math.Sin(90.0.ToRadian()) / Math.Sin(angle / 2) * radius;
            var minimumWallDistance = Math.Sqrt(Math.Pow(distance, 2) - Math.Pow(radius, 2));

            var referencePoint = wallLine.Contains(first.BasePoint) ? first.BasePoint : first.SecondPoint;
            var firstSign      = first.BasePoint == referencePoint ? +1 : -1;
            var secondSign     = second.BasePoint == referencePoint ? +1 : -1;

            var firstPoint  = first.GetPointOnLine(referencePoint, firstSign * minimumWallDistance);
            var secondPoint = second.GetPointOnLine(referencePoint, secondSign * minimumWallDistance);

            var crossLine  = new Line(firstPoint, secondPoint);
            var directLine = new Line(referencePoint, crossLine.ClosestPoint(referencePoint));
            var top        = directLine.GetPointOnLine(distance);

            var difference = top - referencePoint;
            var otherPoint = referencePoint == wallLine.BasePoint ? wallLine.SecondPoint : wallLine.BasePoint;
            var bottom     = otherPoint + difference;

            var basLine     = new Line(top, bottom);
            var reverseBase = new Line(bottom, top);

            var correctTop    = basLine.GetPointOnLine(radius);
            var correctBottom = reverseBase.GetPointOnLine(radius);

            var wallHeight  = Vector3D.AbsoluteValue(wallLine.SecondPoint - wallLine.BasePoint);
            var sign        = otherPoint == wallLine.BasePoint ? -1 : +1;
            var bottomPoint = firstPoint + sign * wallHeight * (wallLine.SecondPoint - wallLine.BasePoint).Normalize();

            var barrier = new Plane(firstPoint, secondPoint, bottomPoint);
            var checker = new PointChecker(barrier, barrier.DeterminePointPosition(referencePoint));

            return(new Cylinder(correctTop, correctBottom, checker, radius));
        }
Exemplo n.º 9
0
        public void Start(Line startLine)
        {
            var currentLine = startLine;

            foreach (var item in Boundaries)
            {
                if (item.IsInCorrectPosition(startLine))
                {
                    throw new ArgumentException(item.BoundaryName);
                }
            }

            for (var i = 0; i < NumberOfIterations; ++i)
            {
                List <(ITrackBoundary boundary, Vector3D intersectionPoint)> hitPoints = Boundaries
                                                                                         .Select(boundary => (boundary, boundary.GetIntersectionPoints(in currentLine)))
                                                                                         .Where(x => x.Item2.Any())
                                                                                         .Select(x =>
                                                                                                 (x.boundary, x.Item2.OrderByDescending(v => Vector3D.AbsoluteValue(v - currentLine.BasePoint))
                                                                                                  .First()))
                                                                                         .ToList();
                var hitted = hitPoints.OrderBy(x => Selector(x.boundary)).First();
                HitSequence.Add(hitted.boundary.BoundaryName);

                EveryHitpoint.Add(hitted.intersectionPoint);
                currentLine = hitted.boundary.LineAfterHit(in currentLine, in hitted.intersectionPoint);
            }
        }