Пример #1
0
        public Color FindCollision(HPoint a, HPoint b)
        {
            //figures

            var    sphere = new HPoint(0, 0, -3);
            double radius = 1;

            var plane = new HPoint[3]
            {
                new HPoint(1, -1, 1),
                new HPoint(1, -1, -1),
                new HPoint(-1, -1, 1)
            };

            //figures

            //List<HPoint> collisions

            //if (((b - a)*(sphere - a)).Length()/(a - b).Length() < radius)
            //    return Color.Black;

            HPoint coll = HGeometry.OldIntersectPlaneLine(plane[0], plane[1], plane[2], a, b);

            return(((int)Math.Round(coll.X) + (int)Math.Round(coll.Z)) % 2 == 0 ? Color.White : Color.Black);
        }
Пример #2
0
        public HPoint CollisionPoint(HRay ray)
        {
            HPoint intersectionPoint = HGeometry.OldIntersectPlaneLine(A, B, C, ray.Source, ray.Source + ray.Direction);

            if (intersectionPoint == null) //no intersection point with plane
            {
                return(null);
            }
            if (!HGeometry.IsPointOnRay(intersectionPoint, ray)) //point is invisible
            {
                return(null);
            }

            double firstSquare  = HGeometry.TriangleSquare(A, B, C);
            double secondSquare = HGeometry.TriangleSquare(A, B, intersectionPoint) +
                                  HGeometry.TriangleSquare(A, C, intersectionPoint) +
                                  HGeometry.TriangleSquare(C, B, intersectionPoint);

            return(HAccuracy.DoubleEqual(firstSquare, secondSquare) ? intersectionPoint : null);
        }