Пример #1
0
        private bool ApplyConstraint(FunctionDependency dependency, ref AISInteractiveObject interactive,
                                     Point3D destinationPoint, Point3D sourcePoint, Point3D distancePoint)
        {
            var transform           = dependency[1].Reference.Set <TransformationInterpreter>();
            var substractedDistance = destinationPoint.SubstractCoordinate(sourcePoint);

            if (dependency[0].Reference.Index != dependency[1].Reference.Index)
            {
                if (distancePoint.IsEqual(substractedDistance))
                {
                    interactive = UpdateInteractive(sourcePoint);
                    return(true);
                }

                var translateVal = new Point3D(transform.Translate);
                transform.Translate =
                    translateVal.AddCoordinate(distancePoint.SubstractCoordinate(substractedDistance)).GpPnt;
            }
            else
            {
                var origin           = new Point3D();
                var pointDistance    = distancePoint.Distance(origin);
                var expectedDistance = substractedDistance.Distance(origin);
                if (Math.Abs(pointDistance - expectedDistance) < Precision.Confusion)
                {
                    interactive = UpdateInteractive(sourcePoint);
                    return(true);
                }
                transform.Scale = transform.Scale * pointDistance / expectedDistance;
            }
            return(false);
        }
Пример #2
0
        private void CreateMirrorProfile()
        {
            int index          = 0;
            var totalHeight    = Point3D.Distance(RequiredTopList[index].Line.StartPoint, RequiredTopList[RequiredTopList.Count - 1].Line.EndPoint);
            var architevLength = RequiredTopList[LineType.Architrave_1].Line.EndPoint.X - RequiredTopList[LineType.Architrave_1].Line.StartPoint.X;
            //if (RequiredTopList[LineType.Architrave_2] != null)
            //{
            //    var architev2Length = RequiredTopList[LineType.Architrave_1].Line.EndPoint.X - RequiredTopList[LineType.Architrave_1].Line.StartPoint.X;
            //    architevLength += architev2Length;
            //}


            Point3D bottomBasePoint = new Point3D(Utilities.InputData.RevealWidth / 2 + architevLength, RequiredTopList[index].Line.StartPoint.Y, 0);
            Point3D topBasePoint    = new Point3D(Utilities.InputData.RevealWidth / 2 + architevLength, RequiredTopList[RequiredTopList.Count - 1].Line.EndPoint.Y, 0);

            Line topLine    = new Line(RequiredTopList[index].Line.StartPoint, bottomBasePoint);
            Line bottomLine = new Line(RequiredTopList[RequiredTopList.Count - 1].Line.EndPoint, topBasePoint);

            TopEntities.Add(topLine);
            TopEntities.Add(bottomLine);

            Plane mirrorPlane = new Plane(bottomBasePoint, new Vector3D(1, 0, 0));

            List <Entity>  mirroredEntities = new List <Entity>();
            Transformation mirror           = new Mirror(mirrorPlane);

            foreach (var topEntity in TopEntities)
            {
                Entity entity = topEntity.Clone() as Entity;
                entity.TransformBy(mirror);
                mirroredEntities.Add(entity);
            }

            TopEntities.AddRange(mirroredEntities);
        }
Пример #3
0
 public Scara(Point3D _Base_pt, Point3D _pt1, Point3D _pt2, Point3D _pt3)
 {
     this.Base_pt = _Base_pt;
     this.pt1     = _pt1;
     this.pt2     = _pt2;
     this.pt3     = _pt3;
     this.armb_1  = Point3D.Distance(_Base_pt, _pt1);
     this.arm1_2  = Point3D.Distance(_pt1, _pt2);
     this.arm2_3  = Point3D.Distance(_pt2, _pt3);
 }
Пример #4
0
        public ISystem PosAlongRoute(double percentage, int error = 0)             // go along route and give me a co-ord along it..
        {
            List <ISystem> knownsystems = KnownSystemList();

            double totaldist = CumulativeDistance(null, knownsystems);
            double distleft  = totaldist * percentage / 100.0;

            if (knownsystems.Count < 2)     // need a path
            {
                return(null);
            }

            Point3D syspos = null;
            string  name   = "";

            if (percentage < 0 || percentage > 100)                         // not on route, interpolate to/from
            {
                int i = (percentage < 0) ? 0 : knownsystems.Count - 2;      // take first two, or last two.

                Point3D pos1    = P3D(knownsystems[i]);
                Point3D pos2    = P3D(knownsystems[i + 1]);
                double  p12dist = pos1.Distance(pos2);
                double  pospath = (percentage > 100) ? (1.0 + (percentage - 100) * totaldist / p12dist / 100.0) : (percentage * totaldist / p12dist / 100.0);
                syspos = pos1.PointAlongPath(pos2, pospath);        // amplify percentage by totaldist/this path dist
                name   = "System at " + percentage.ToString("N1");
            }
            else
            {
                for (int i = 1; i < knownsystems.Count; i++)
                {
                    double d = knownsystems[i].Distance(knownsystems[i - 1]);

                    if (distleft < d || (i == knownsystems.Count - 1))        // if left, OR last system (allows for some rounding errors on floats)
                    {
                        d = distleft / d;
                        //System.Diagnostics.Debug.WriteLine(percentage + " " + d + " last:" + last.X + " " + last.Y + " " + last.Z + " s:" + s.X + " " + s.Y + " " + s.Z);
                        name   = "WP" + knownsystems[i - 1].ID.ToString() + "-" + "WP" + knownsystems[i].ID.ToString() + "-" + d.ToString("#.00");
                        syspos = new Point3D(knownsystems[i - 1].X + (knownsystems[i].X - knownsystems[i - 1].X) * d, knownsystems[i - 1].Y + (knownsystems[i].Y - knownsystems[i - 1].Y) * d, knownsystems[i - 1].Z + (knownsystems[i].Z - knownsystems[i - 1].Z) * d);
                        break;
                    }

                    distleft -= d;
                }
            }

            if (error > 0)
            {
                return(new SystemClass(name, syspos.X + rnd.Next(error), syspos.Y + rnd.Next(error), syspos.Z + rnd.Next(error)));
            }
            else
            {
                return(new SystemClass(name, syspos.X, syspos.Y, syspos.Z));
            }
        }
Пример #5
0
        private static Point3D CalculateEndPointOnArc(Point3D center, Point3D startPoint, Point3D currentEndPoint)
        {
            var radius = center.Distance(startPoint);

            Ensure.IsTrue(radius > 0);
            var endPointVector = new gpVec(center.GpPnt, currentEndPoint.GpPnt);

            endPointVector.Normalize();
            endPointVector.Multiply(radius);
            return(GeomUtils.BuildTranslation(center, endPointVector));
        }
Пример #6
0
 public Puma(Point3D _Base_pt, Point3D _pt1, Point3D _pt2, Point3D _pt3, Point3D _pt4)
 {
     this.Base_pt = _Base_pt;
     this.pt1     = _pt1;
     this.pt2     = _pt2;
     this.pt3     = _pt3;
     this.pt4     = _pt4;
     this.armb_1  = Point3D.Distance(_Base_pt, _pt1);
     this.arm1_2  = Point3D.Distance(_pt1, _pt2);
     this.arm2_3  = Point3D.Distance(_pt2, _pt3);
     this.arm3_4  = Point3D.Distance(_pt3, _pt4);
 }
Пример #7
0
        private void CreateTopSlots()
        {
            double slotHeight  = 20;
            double slotWidth   = 2.5;
            int    index       = 0;
            var    totalHeight = Point3D.Distance(RequiredTopList[index].Line.StartPoint, RequiredTopList[RequiredTopList.Count - 1].Line.EndPoint);

            var slotPoints = GetTopSlotPoints(totalHeight, JsonData.TabData.TabBase, slotHeight, slotWidth);

            foreach (var point in slotPoints)
            {
                var slotLines = DrawPocketLines(point, slotHeight, slotWidth);
                TopEntities.AddRange(slotLines);
            }
        }
Пример #8
0
        private void AddTriangleEdge(Dictionary <Tuple <int, int>, Edge> borders,
                                     int A, int B, Point3D[] points, int curTriangleNumber)
        {
            Tuple <int, int> border = new Tuple <int, int>(Math.Min(A, B), Math.Max(A, B));
            Edge             edge;

            if (borders.TryGetValue(border, out edge))
            {
                edge.To = curTriangleNumber;
            }
            else
            {
                edge = new Edge(Point3D.Distance(points[A], points[B]), curTriangleNumber, -1);
                borders.Add(border, edge);
            }
        }
Пример #9
0
        protected void AssignTopDisplacement()
        {
            var calc = (Utilities.InputData.Return1 - JsonData.TopViewDataList[LineType.Return_1].BendAllowance) +
                       (Utilities.InputData.Return2 - JsonData.TopViewDataList[LineType.Return_2].BendAllowance) +
                       (Utilities.InputData.Architrave1 - JsonData.TopViewDataList[LineType.Architrave_1].BendAllowance) +
                       (Utilities.InputData.Architrave2 - JsonData.TopViewDataList[LineType.Architrave_2].BendAllowance) +
                       (JsonData.TopViewData.ConstVLine3 + JsonData.TopViewData.ConstVLine3);

            int index       = 0;
            var totalHeight = Point3D.Distance(JsonData.TopViewDataList[index].Line.StartPoint,
                                               JsonData.TopViewDataList[JsonData.TopViewDataList.Count - 1].Line.EndPoint);

            var minWidth = totalHeight - calc;

            var allowances = JsonData.TopViewDataList;

            allowances[LineType.Return_1].ModifiedLengthTxt = Utilities.InputData.Return1;
            allowances[LineType.Return_1].Displacement      = Utilities.InputData.Return1 - JsonData.ProfileInfo.Return1;

            allowances[LineType.Architrave_1].ModifiedLengthTxt = Utilities.InputData.Architrave1;
            allowances[LineType.Architrave_1].Displacement      = Utilities.InputData.Architrave1 - JsonData.ProfileInfo.Architrave1;

            allowances[LineType.Rebate_1].ModifiedLengthTxt = JsonData.TopViewData.ConstVLine3;
            allowances[LineType.Rebate_1].Displacement      = 0;

            allowances[LineType.StopHgt_1].ModifiedLengthTxt = JsonData.TopViewData.ConstHLine4;
            allowances[LineType.StopHgt_1].Displacement      = 0;

            allowances[LineType.Throat].ModifiedLengthTxt = JsonData.TopViewData.MidWidth;
            allowances[LineType.Throat].Displacement      = minWidth - JsonData.TopViewData.MidWidth;

            allowances[LineType.StopHgt_2].ModifiedLengthTxt = JsonData.TopViewData.ConstHLine4;
            allowances[LineType.StopHgt_2].Displacement      = 0;

            allowances[LineType.Rebate_2].ModifiedLengthTxt = JsonData.TopViewData.ConstVLine3;
            allowances[LineType.Rebate_2].Displacement      = 0;

            allowances[LineType.Architrave_2].ModifiedLengthTxt = Utilities.InputData.Architrave2;
            allowances[LineType.Architrave_2].Displacement      = Utilities.InputData.Architrave2 - JsonData.ProfileInfo.Architrave2;

            allowances[LineType.Return_2].ModifiedLengthTxt = Utilities.InputData.Return2;
            allowances[LineType.Return_2].Displacement      = Utilities.InputData.Return2 - JsonData.ProfileInfo.Return2;
        }
Пример #10
0
        private List <Point3D> GetTopSlotPoints(double totalWidth, double tabBase, double slotFeatLength, double slotFeatWidth)
        {
            List <Point3D> topSlotPointList = new List <Point3D>();

            double factor1 = Utilities.InputData.Rebate1 > 48 ? 16.5 : 15.5;
            double factor2 = Utilities.InputData.Rebate2 > 48 ? 16.5 : 15.5;

            double slotCenterDist1 = GetCenterDist(factor1, tabBase);

            double slotCenterDist2 = GetCenterDist(factor2, tabBase);

            // Slot 1
            double slot1X = RequiredTopList[LineType.Rebate_1].Line.StartPoint.X - slotFeatWidth;
            double slot1Y = RequiredTopList[LineType.Rebate_1].Line.StartPoint.Y + slotCenterDist1 - (slotFeatLength / 2);

            // Slot 2
            var disp = Point3D.Distance(RequiredTopList[LineType.Throat].Line.StartPoint, RequiredTopList[LineType.Throat].Line.EndPoint);



            double slot2X = RequiredTopList[LineType.Rebate_1].Line.EndPoint.X + RequiredTopList[LineType.StopHgt_1].Line.EndPoint.X - slotFeatWidth;
            double slot2Y = RequiredTopList[LineType.Throat].Line.StartPoint.Y + (disp / 2.0);


            // Slot 3
            double slot3X = RequiredTopList[LineType.Rebate_2].Line.EndPoint.X - slotFeatWidth;
            double slot3Y = RequiredTopList[LineType.Rebate_2].Line.EndPoint.Y - slotCenterDist2 - (slotFeatLength / 2);

            topSlotPointList.Add(new Point3D {
                X = slot1X, Y = slot1Y
            });
            topSlotPointList.Add(new Point3D {
                X = slot2X, Y = slot2Y
            });
            topSlotPointList.Add(new Point3D {
                X = slot3X, Y = slot3Y
            });

            return(topSlotPointList);
        }
Пример #11
0
        private static double GetLength_OBSOLETE(Point3D p0, Point3D p1, Point3D p2, Point3D p3, double accuracy,
                                                 double level = 0)
        {
            const int minLevel = 2;
            const int maxLevel = 15;

            var len = level >= minLevel?p0.Distance(p3) : -1;

            if (level > maxLevel || len >= 0 && (p0 + p3).Distance(p1 + p2) <= accuracy * len)
            //if (len < 0.00001D)
            //if (level > 128)
            {
                //Аппроксимируем кругом
                var cos = (p0 - p1).Cos(p2 - p3);

                if (cos >= 1)
                {
                    return(len);
                }

                var angle = Math.Acos(cos);
                var sin   = Math.Sqrt((1 - cos) / 2);
                var diam  = len / sin;

                return(diam * angle / 2);
            }
            var q0 = (p0 + p1) / 2;
            var q1 = (p1 + p2) / 2;
            var q2 = (p2 + p3) / 2;
            var r0 = (q0 + q1) / 2;
            var r1 = (q1 + q2) / 2;
            var s0 = (r0 + r1) / 2;

            level++;

            return(GetLength_OBSOLETE(p0, q0, r0, s0, accuracy, level) +
                   GetLength_OBSOLETE(s0, r1, q2, p3, accuracy, level));
        }
Пример #12
0
        protected override void CreateRightProfile()
        {
            int firstIndex  = 0;
            var firstPoint  = RequiredHingeList[firstIndex].Line.StartPoint;
            var secondPoint = RequiredHingeList[RequiredHingeList.Count - 1].Line.EndPoint;

            var    width        = Point3D.Distance(firstPoint, secondPoint);
            double totalLength1 = Utilities.InputData.RevealHeight + Utilities.InputData.Architrave1 - JsonData.HingeDataList[LineType.Architrave_1].BendAllowance;
            double totalLength2 = Utilities.InputData.RevealHeight + Utilities.InputData.Architrave2 - JsonData.HingeDataList[LineType.Architrave_2].BendAllowance;

            var thirdPoint  = new Point3D(firstPoint.X + totalLength1, firstPoint.Y);
            var fourthPoint = new Point3D(firstPoint.X + totalLength1, firstPoint.Y + width);

            Line firstLine  = new Line(firstPoint, thirdPoint);
            Line secondLine = new Line(secondPoint, fourthPoint);
            Line thirdLine  = new Line(thirdPoint, fourthPoint);

            HingEntities.Add(firstLine);
            HingEntities.Add(secondLine);
            HingEntities.Add(thirdLine);

            rightProfileTop = fourthPoint;
            // rightProfileBottom = thirdPoint;
        }
Пример #13
0
 private bool ArePointsOutOfZoomRange(Point3D splineIntermediaryPoint, Point3D mousePoint)
 {
     return(splineIntermediaryPoint.Distance(mousePoint) > _zoom);
 }
Пример #14
0
        public static List <Face3D> Profiles_Wall(this Wall wall)
        {
            if (wall == null)
            {
                return(null);
            }

            List <Face3D> result = Profiles_FromSketch(wall, !wall.Flipped);

            if (result != null && result.Count > 0)
            {
                return(result);
            }

            BoundingBoxXYZ boundingBoxXYZ = wall.get_BoundingBox(null);

            if (boundingBoxXYZ != null)
            {
                LocationCurve locationCurve = wall.Location as LocationCurve;
                if (locationCurve != null)
                {
                    ICurve3D curve3D_Location = Convert.ToSAM(locationCurve);

                    IEnumerable <ICurve3D> curves = null;
                    if (curve3D_Location is ISegmentable3D)
                    {
                        curves = ((ISegmentable3D)curve3D_Location).GetSegments().Cast <ICurve3D>();
                    }
                    else
                    {
                        curves = new List <ICurve3D>()
                        {
                            curve3D_Location
                        }
                    };

                    double        max       = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Max.Z, DisplayUnitType.DUT_METERS);
                    Spatial.Plane plane_max = new Spatial.Plane(new Point3D(0, 0, max), new Vector3D(0, 0, 1));

                    double        min       = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Min.Z, DisplayUnitType.DUT_METERS);
                    Spatial.Plane plane_min = new Spatial.Plane(new Point3D(0, 0, min), new Vector3D(0, 0, 1));

                    result = new List <Face3D>();
                    foreach (ICurve3D curve3D in curves)
                    {
                        if (curve3D == null)
                        {
                            continue;
                        }

                        ICurve3D maxCurve = plane_max.Project(curve3D);
                        ICurve3D minCurve = plane_min.Project(curve3D);

                        Point3D point3D_1 = minCurve.GetEnd();
                        Point3D point3D_2 = maxCurve.GetStart();
                        Point3D point3D_3 = maxCurve.GetEnd();
                        if (point3D_1.Distance(point3D_3) < point3D_1.Distance(point3D_2))
                        {
                            Point3D point_Temp = point3D_2;

                            maxCurve.Reverse();
                            point3D_2 = point3D_3;
                            point3D_3 = point_Temp;
                        }

                        List <Point3D> point3Ds = new List <Point3D>()
                        {
                            minCurve.GetStart(), point3D_3, point3D_2, point3D_1
                        };
                        if (wall.Flipped)
                        {
                            point3Ds.Reverse();
                        }

                        result.Add(new Face3D(new Polygon3D(point3Ds)));
                    }

                    if (result != null && result.Count > 0)
                    {
                        return(result);
                    }
                }
            }

            if (!ExporterIFCUtils.HasElevationProfile(wall))
            {
                return(null);
            }

            IList <CurveLoop> curveLoops = ExporterIFCUtils.GetElevationProfile(wall);

            if (curveLoops == null)
            {
                return(null);
            }

            result = new List <Face3D>();
            foreach (CurveLoop curveLoop in curveLoops)
            {
                Polygon3D polygon3D = curveLoop.ToSAM_Polygon3D();
                if (polygon3D != null)
                {
                    result.Add(new Face3D(polygon3D));
                }
            }

            return(result);
        }
Пример #15
0
 public float Distance(Point3D Position)
 {
     return(Vector.Distance(Position));
 }
Пример #16
0
 public Single Distance(Point3D Position)
 {
     return(Vector.Distance(Position));
 }
Пример #17
0
        private void NotifyCrossSectionChanging(Region section)
        {
            var solid = section.ExtrudeAsSolid(Point3D.Distance(this.StartPoint, this.EndPoint), 0.0);

            solid.TransformBy(Position.GetCurrentTData());
        }
Пример #18
0
        public static T Find <T>(this IEnumerable <Element> elements, Point3D point3D, double min = Tolerance.Distance, double max = Tolerance.MacroDistance) where T : Element
        {
            if (elements == null || point3D == null)
            {
                return(null);
            }

            List <Tuple <T, ISAMGeometry3D, double> > tuples = new List <Tuple <T, ISAMGeometry3D, double> >();

            foreach (Element element in elements)
            {
                T t = element as T;
                if (t == null)
                {
                    continue;
                }

                ISAMGeometry3D sAMGeometry3D = element?.Location();
                if (sAMGeometry3D == null)
                {
                    continue;
                }

                if (sAMGeometry3D is Point3D)
                {
                    Point3D point3D_Temp = (Point3D)sAMGeometry3D;
                    double  distance     = point3D.Distance(point3D_Temp);
                    if (distance <= min)
                    {
                        return(t);
                    }

                    if (distance > max)
                    {
                        continue;
                    }

                    tuples.Add(new Tuple <T, ISAMGeometry3D, double>(t, point3D_Temp, distance));
                }
                else if (sAMGeometry3D is ISegmentable3D)
                {
                    ISegmentable3D segmentable3D = (ISegmentable3D)sAMGeometry3D;
                    double         distance      = segmentable3D.Distance(point3D);
                    if (distance <= min)
                    {
                        return(t);
                    }

                    if (distance > max)
                    {
                        continue;
                    }

                    tuples.Add(new Tuple <T, ISAMGeometry3D, double>(t, segmentable3D, distance));
                }
            }

            if (tuples == null || tuples.Count == 0)
            {
                return(null);
            }

            if (tuples.Count == 1)
            {
                return(tuples[0].Item1);
            }

            tuples.Sort((x, y) => x.Item3.CompareTo(y.Item3));

            return(tuples.First().Item1);
        }
Пример #19
0
        private static List <Face3D> Profiles_FromLocation(this Wall wall, double tolerance_Angle = Core.Tolerance.Angle, double tolerance_Distance = Core.Tolerance.Distance)
        {
            BoundingBoxXYZ boundingBoxXYZ = wall.get_BoundingBox(null);

            if (boundingBoxXYZ == null)
            {
                return(null);
            }

            LocationCurve locationCurve = wall.Location as LocationCurve;

            if (locationCurve == null)
            {
                return(null);
            }

            ICurve3D curve3D_Location = Convert.ToSAM(locationCurve);

            IEnumerable <ICurve3D> curves = null;

            if (curve3D_Location is ISegmentable3D)
            {
                curves = ((ISegmentable3D)curve3D_Location).GetSegments().Cast <ICurve3D>();
            }
            else
            {
                curves = new List <ICurve3D>()
                {
                    curve3D_Location
                }
            };

            Vector3D direction = Vector3D.WorldZ;

#if Revit2017 || Revit2018 || Revit2019 || Revit2020
            double max = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Max.Z, DisplayUnitType.DUT_METERS);
#else
            double max = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Max.Z, UnitTypeId.Meters);
#endif

            Spatial.Plane plane_max = new Spatial.Plane(new Point3D(0, 0, max), direction);

#if Revit2017 || Revit2018 || Revit2019 || Revit2020
            double min = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Min.Z, DisplayUnitType.DUT_METERS);
#else
            double min = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Min.Z, UnitTypeId.Meters);
#endif
            Spatial.Plane plane_min = new Spatial.Plane(new Point3D(0, 0, min), direction);

            double height = max - min;

            Document document = wall.Document;

            //List<Face3D> face3Ds_Cutting = new List<Face3D>();

            //Dictionary<ElementId, List<Face3D>> dictionary = GeneratingElementIdDictionary(wall);
            //foreach (KeyValuePair<ElementId, List<Face3D>> keyValuePair in dictionary)
            //{
            //    if (keyValuePair.Value == null || keyValuePair.Value.Count == 0)
            //    {
            //        continue;
            //    }

            //    HostObject hostObject_Cutting = document.GetElement(keyValuePair.Key) as HostObject;
            //    if (hostObject_Cutting == null)
            //    {
            //        continue;
            //    }

            //    if (hostObject_Cutting is Floor || hostObject_Cutting is RoofBase)
            //    {
            //        List<Face3D> face3Ds_Temp = hostObject_Cutting.Profiles();
            //        if (face3Ds_Temp != null && face3Ds_Temp.Count != 0)
            //        {
            //            face3Ds_Cutting.AddRange(face3Ds_Temp);
            //        }
            //    }
            //}

            List <Face3D> result = new List <Face3D>();
            foreach (ICurve3D curve3D in curves)
            {
                if (curve3D == null)
                {
                    continue;
                }

                ICurve3D maxCurve = Spatial.Query.Project(plane_max, curve3D);
                ICurve3D minCurve = Spatial.Query.Project(plane_min, curve3D);

                Point3D point3D_1 = minCurve.GetEnd();
                Point3D point3D_2 = maxCurve.GetStart();
                Point3D point3D_3 = maxCurve.GetEnd();
                Point3D point3D_4 = minCurve.GetStart();
                if (point3D_1.Distance(point3D_3) < point3D_1.Distance(point3D_2))
                {
                    Point3D point_Temp = point3D_2;

                    maxCurve.Reverse();
                    point3D_2 = point3D_3;
                    point3D_3 = point_Temp;
                }

                List <Point3D> point3Ds = new List <Point3D>()
                {
                    point3D_4, point3D_3, point3D_2, point3D_1
                };
                if (wall.Flipped)
                {
                    point3Ds.Reverse();
                }

                Face3D face3D = new Face3D(new Polygon3D(point3Ds, tolerance_Distance));
                result.Add(face3D);

                //Spatial.Plane plane = Spatial.Create.Plane(point3Ds, tolerance_Distance);
                //if (plane == null)
                //{
                //    continue;
                //}

                //Vector3D vector3D = new Vector3D(point3D_4, point3D_3);

                //Segment2D segment2D = plane.Convert(new Segment3D(point3D_4, point3D_1));

                //List<Segment2D> segment2Ds_Intersection = new List<Segment2D>();
                //foreach (Face3D face3D_Cutting in face3Ds_Cutting)
                //{
                //    PlanarIntersectionResult planarIntersectionResult = Spatial.Create.PlanarIntersectionResult(plane, face3D_Cutting, tolerance_Angle, tolerance_Distance);
                //    if (planarIntersectionResult == null || !planarIntersectionResult.Intersecting)
                //    {
                //        continue;
                //    }

                //    List<Segment2D> segment2Ds_Intersection_Temp = planarIntersectionResult.GetGeometry2Ds<Segment2D>();
                //    if (segment2Ds_Intersection_Temp != null && segment2Ds_Intersection_Temp.Count > 0)
                //    {
                //        segment2Ds_Intersection.AddRange(segment2Ds_Intersection_Temp);
                //    }
                //}

                //List<Face2D> face2Ds = Profiles_From2D(segment2D, plane.Convert(vector3D), segment2Ds_Intersection, tolerance_Distance);
                //if (face2Ds != null && face2Ds.Count > 0)
                //{
                //    result.AddRange(face2Ds.ConvertAll(x => plane.Convert(x)));
                //}
            }

            if (result != null && result.Count > 0)
            {
                return(result);
            }

            return(result);
        }
Пример #20
0
        public ClosestInfo ClosestTo(ISystem currentsystem)
        {
            Point3D currentsystemp3d = P3D(currentsystem);

            List <ISystem> knownsystems = KnownSystemList();

            if (knownsystems.Count < 1)     // need at least one
            {
                return(null);
            }

            double mininterceptdist  = Double.MaxValue;
            int    interceptendpoint = -1;

            double closesttodist = Double.MaxValue;
            int    closestto     = -1;

            for (int i = 0; i < knownsystems.Count; i++)
            {
                if (i > 0)
                {
                    Point3D lastp3d = P3D(knownsystems[i - 1]);
                    Point3D top3d   = P3D(knownsystems[i]);

                    double distbetween = lastp3d.Distance(top3d);

                    double interceptpercent = lastp3d.InterceptPercentageDistance(top3d, currentsystemp3d, out double dist);       //dist to intercept point on line note.
                    //System.Diagnostics.Debug.WriteLine("From " + knownsystems[i - 1].ToString() + " to " + knownsystems[i].ToString() + " Percent " + interceptpercent + " Distance " + dist);

                    // allow a little margin in the intercept point for randomness, must be min dist, and not stupidly far.
                    if (interceptpercent >= -0.01 && interceptpercent < 1.01 && dist < mininterceptdist && dist < distbetween)
                    {
                        interceptendpoint = i;
                        mininterceptdist  = dist;
                    }
                }

                double disttofirstpoint = currentsystemp3d.Distance(P3D(knownsystems[i]));

                if (disttofirstpoint < closesttodist)
                {
                    closesttodist = disttofirstpoint;
                    closestto     = i;
                }
            }

            int topos = interceptendpoint; // default value

            if (topos == -1)               // if not on path
            {
                topos            = closestto;
                mininterceptdist = -1;
                //System.Diagnostics.Debug.WriteLine("Not on path, closest to" + knownsystems[closestto].ToString());
            }
            else
            {
                //System.Diagnostics.Debug.WriteLine("Lies on line to WP" + interceptendpoint + " " + knownsystems[interceptendpoint].ToString());
            }

            double distto   = currentsystemp3d.Distance(P3D(knownsystems[topos]));
            double cumldist = CumulativeDistance(knownsystems[topos], knownsystems);

            return(new ClosestInfo(knownsystems[topos], (int)knownsystems[topos].ID, mininterceptdist, cumldist, distto));
        }
Пример #21
0
        /// <summary>
        /// Trims selected entity by the cutting entity. Removes portion of the curve near mouse click.
        /// </summary>
        private void TrimEntity()
        {
            if (firstSelectedEntity == null)
            {
                if (selEntityIndex != -1)
                {
                    firstSelectedEntity = Entities[selEntityIndex];
                    selEntityIndex      = -1;
                    return;
                }
            }
            else if (secondSelectedEntity == null)
            {
                if (selEntityIndex != -1)
                {
                    secondSelectedEntity = Entities[selEntityIndex];
                }
                else
                {
                    DrawSelectionMark(mouseLocation);
                    renderContext.EnableXOR(false);
                    DrawText(mouseLocation.X, (int)Size.Height - mouseLocation.Y + 10, "Select entity to be trimmed",
                             new Font("Tahoma", 8.25f), DrawingColor, ContentAlignment.BottomLeft);
                }
            }

            if (firstSelectedEntity != null && secondSelectedEntity != null)
            {
                if (firstSelectedEntity is ICurve && secondSelectedEntity is ICurve)
                {
                    ICurve trimmingCurve = firstSelectedEntity as ICurve;
                    ICurve curve         = secondSelectedEntity as ICurve;
#if NURBS
                    Point3D[] intersetionPoints = Curve.Intersection(trimmingCurve, curve);
                    if (intersetionPoints.Length > 0 && points.Count > 0)
                    {
                        List <double> parameters = new List <double>();
                        for (int i = 0; i < intersetionPoints.Length; i++)
                        {
                            var    intersetionPoint = intersetionPoints[i];
                            double t = ((InterPoint)intersetionPoint).s;
                            parameters.Add(t);
                        }

                        double distSelected = 1;

                        ICurve[] trimmedCurves = null;
                        if (parameters != null)
                        {
                            parameters.Sort();
                            double u;
                            curve.ClosestPointTo(points[0], out u);
                            distSelected  = Point3D.Distance(points[0], curve.PointAt(u));
                            distSelected += distSelected / 1e3;

                            if (u <= parameters[0])
                            {
                                curve.SplitBy(new Point3D[] { curve.PointAt(parameters[0]) }, out trimmedCurves);
                            }
                            else if (u > parameters[parameters.Count - 1])
                            {
                                curve.SplitBy(new Point3D[] { curve.PointAt(parameters[parameters.Count - 1]) },
                                              out trimmedCurves);
                            }
                            else
                            {
                                for (int i = 0; i < parameters.Count - 1; i++)
                                {
                                    if (u > parameters[i] && u <= parameters[i + 1])
                                    {
                                        curve.SplitBy(
                                            new Point3D[] { curve.PointAt(parameters[i]), curve.PointAt(parameters[i + 1]) },
                                            out trimmedCurves);
                                    }
                                }
                            }
                        }

                        bool success = false;
                        //Decide which portion of curve to be deleted
                        for (int i = 0; i < trimmedCurves.Length; i++)
                        {
                            ICurve trimmedCurve = trimmedCurves[i];
                            double t;

                            trimmedCurve.ClosestPointTo(points[0], out t);
                            {
                                if ((t < trimmedCurve.Domain.t0 || t > trimmedCurve.Domain.t1) ||
                                    Point3D.Distance(points[0], trimmedCurve.PointAt(t)) > distSelected)
                                {
                                    AddAndRefresh((Entity)trimmedCurve, secondSelectedEntity.LayerName);
                                    success = true;
                                }
                            }
                        }

                        // Delete original entity to be trimmed
                        if (success)
                        {
                            Entities.Remove(secondSelectedEntity);
                        }
                    }
                    ClearAllPreviousCommandData();
#endif
                }
            }
        }