/// <summary> /// Creates a new instance of <see cref="Geometry3d.Vector"/>, whose values are randomized. Returned vector is normalized. /// </summary> /// <returns>Random vector.</returns> private static Geometry3d.Vector GetRandomVector() { var randomVector = new Geometry3d.Vector(1, 1, 1); randomVector.X *= random.NextDouble(); randomVector.Y *= random.NextDouble(); randomVector.Z *= random.NextDouble(); return(randomVector.GetNormal()); }
/// <summary> /// Ray tracing algorithm implementation for Tekla Structures. /// </summary> /// <param name="point">Point to be checked.</param> /// <param name="solid">Solid, against which the point is going to be checked.</param> /// <returns>True if point is inside or on the surface of the solid, false otherwise.</returns> public static bool IsInside(this Geometry3d.Point point, Model.Solid solid) { var randomVector = GetRandomVector(); var intersection = solid.Intersect(new Geometry3d.Line(point, randomVector)).Cast <Geometry3d.Point>(); // Tekla does not support rays, a line will be used instead. All points found on opposite direction must be excluded. var pointsOnRay = intersection.Where(x => { var vectorToIntersectionPoint = new Geometry3d.Vector(x - point); var factor = Math.Round(vectorToIntersectionPoint.X / randomVector.X, 3); return(factor == Math.Round(vectorToIntersectionPoint.Y / randomVector.Y, 3) && factor == Math.Round(vectorToIntersectionPoint.Z / randomVector.Z, 3)); }); // If point is inside solid, there will be odd numbers of intersections between solid faces and any ray originated in given point. return(pointsOnRay.Count() % 2 != 0); }