/// <summary>
        /// Clones of the current BoundingBox.
        /// </summary>
        public BoundingBox Clone()
        {
            BoundingBox clonedBox = new BoundingBox(_minimumBounds.Clone(), _maximumBounds.Clone());

            return(clonedBox);
        }
Пример #2
0
        /// <summary>
        /// Projects an array of points onto the model in the Z axis and returns the nearest point to each one.
        /// </summary>
        /// <param name="pointsToProject">List of the points to project.</param>
        /// <param name="projectDownOnly">If True, points above the point of projection are ignored.</param>
        public List <Point> ProjectPoints(List <Point> pointsToProject, bool projectDownOnly = false)
        {
            // Zone model here in case user forgets.
            ZoneModel();

            // Loop through all the points and for each one find the nearest point in the z axis
            List <Point> projectedPoints = new List <Point>();

            Vector projectionVector = new Vector(0.0, 0.0, -1.0);

            // Work out the size of the zones in the x and y directions
            double minX = 0;
            double minY = 0;

            double xZoneLength = 0;
            double yZoneLength = 0;

            int numXZones = 0;
            int numYZones = 0;

            BoundingBox modelBoundingBox = BoundingBox;
            var         _with2           = modelBoundingBox;

            xZoneLength = _with2.XSize / Math.Sqrt(_numberOfZones);
            yZoneLength = _with2.YSize / Math.Sqrt(_numberOfZones);

            numXZones = (int)(_with2.XSize / xZoneLength) + 1;
            numYZones = (int)(_with2.YSize / yZoneLength) + 1;

            minX = _with2.MinX;
            minY = _with2.MinY;

            foreach (Point pointToProject in pointsToProject)
            {
                // First find which zone (row and column) the point is in

                int row = 0;
                int col = 0;

                row = (int)((pointToProject.X - minX) / xZoneLength);
                col = (int)((pointToProject.Y - minY) / yZoneLength);

                Point nearestPoint = null;

                if ((row >= 0) & (col >= 0) && row < _zones.Count && col < _zones[row].Count)
                {
                    // Get the zone
                    DMTTriangleZone zone = _zones[row][col];

                    // Now loop through all triangles in the zone
                    double nearest = double.MaxValue;

                    // Loop through all the triangles in the zone
                    foreach (DMTTriangleZoneEntry triangleEntry in zone.Triangles)
                    {
                        //' Get the triangle itself
                        //Dim triangle As DMTTriangle
                        //With triangleEntry
                        //    triangle = CType(_blocks(.Block), DMTTriangleBlock).Triangles(.Triangle)
                        //End With

                        // Check to see if the projection point intersects this triangle
                        Point projectedPoint = null;
                        projectedPoint = ProjectPointToTriangle(pointToProject,
                                                                projectionVector,
                                                                _blocks[triangleEntry.Block].GetVertex1(triangleEntry.Triangle),
                                                                _blocks[triangleEntry.Block].GetVertex2(triangleEntry.Triangle),
                                                                _blocks[triangleEntry.Block].GetVertex3(triangleEntry.Triangle));

                        // If it does then see if it is nearer than any point found so far
                        if (projectedPoint != null)
                        {
                            // Ignore if we are projecting down only and the point is above us
                            if (projectDownOnly && pointToProject.Z < projectedPoint.Z)
                            {
                                continue;
                            }
                            double distance = Math.Abs(Convert.ToDouble(pointToProject.Z - projectedPoint.Z));
                            if (distance < nearest)
                            {
                                // It is the nearest so far
                                nearest      = distance;
                                nearestPoint = projectedPoint.Clone();
                            }
                        }
                    }
                }

                // Add the nearest point to the list of output points
                projectedPoints.Add(nearestPoint);
            }

            return(projectedPoints);
        }
Пример #3
0
        /// <summary>
        /// Returns a clone of this Workplane.
        /// </summary>
        public Workplane Clone()
        {
            Workplane cloneWorkplane = new Workplane(_origin.Clone(), XAxis.Clone(), YAxis.Clone(), ZAxis.Clone());

            return(cloneWorkplane);
        }