Exemple #1
0
        /// <summary>
        /// Method to constrcut the Plane 1 and Point A
        /// </summary>
        private void ConstructPlaneRedPlane1AndPointA()
        {
            ///Constructing Plane1 from Bottom Wishbone Points and the Top Front Pick-Up Point
            ///<remarks>Right now selection of these 3 points is random. Need to figure out how to select them properly</remarks>
            Plane1 = new Plane(BottomFrontInboard.Position.Clone() as Point3D, BottomRearInboard.Position.Clone() as Point3D, TopFrontInboard.Position.Clone() as Point3D);
            ///<summary>Creating a <see cref="Segment3D"/> using the <see cref="SteeringAxis"/> so that I can use the <see cref="Segment3D.IntersectWith(Plane, bool, out Point3D)"/> to compute the intersection of the Plane1 and Steering Axis</summary>
            Segment3D SteeringAxisSegment = new Segment3D(SteeringAxis.StartPoint.Clone() as Point3D, SteeringAxis.EndPoint.Clone() as Point3D);

            ///<summary>Computing the Intersection of the <see cref="SteeringAxis"/> with the <see cref="Plane1"/> which results in <see cref="PointA"/></summary>
            SteeringAxisSegment.IntersectWith(Plane1, true, out PointA);

            ///<summary>Determining the whether the <see cref="PointA"/> is above or below the Wishbones</summary>
            if (PointA.Y > UBJ_Rear.Position.Y && PointA.Y > TopFrontInboard.Position.Y && PointA.Y > TopRearInboard.Position.Y)
            {
                PointAPos = PositionOfPointA.AboveWishbones;
            }
            else if (PointA.Y < LBJ_Rear.Position.Y && PointA.Y < BottomFrontInboard.Position.Y && PointA.Y < BottomRearInboard.Position.Y)
            {
                PointAPos = PositionOfPointA.BelowWishbones;
            }

            ///<summary>Adding them to the VIewport as a Planar Entity</summary>
            PlanarEntity Plane1_Ent = new PlanarEntity(Plane1);
            Joint        PointA_Ent = new Joint(PointA, 10, 2);

            PointA_Ent.Color = Color.AntiqueWhite;
            //cad1.viewportLayout1.Entities.AddRange(new Entity[] { Plane1_Ent, PointA_Ent });
        }
Exemple #2
0
        public bool Intersects(Segment3D segment)
        {
            double p0;
            double p1;

            return(this.GetIntersectionParameters(segment, out p0, out p1));
        }
Exemple #3
0
        /// <summary>
        /// Checking the <see cref="ToeLinkInboard"/> is close to the Bump Steer Line. This would be an indication of how much Bump Steer is there
        /// </summary>
        private void CheckForBumpSteer()
        {
            Segment3D tempBobillierSegment = new Segment3D(BobillierLine.StartPoint, BobillierLine.EndPoint);

            ToeLinkInboard.Position.DistanceTo(tempBobillierSegment);
            double bumpSteerError = ToeLinkInboard.Position.DistanceTo(tempBobillierSegment);
        }
        public static void FillArrow(Graphics g, int x0, int y0, int x1, int y1, double h, double w)
        {
            Segment3D seg = new Segment3D(x0, y0, 0.0D, x1, y1, 0.0D);
            double    len = seg.SegLength();
            double    x   = seg.p1.x - seg.p0.x;
            double    y   = seg.p1.y - seg.p0.y;
            double    angle;
            Vector3D  p2;

            if (len > 0.0D)
            {
                angle = -System.Math.Atan2(x, y);
                p2    = seg.LinearIntarp((len - h) / len);
            }
            else
            {
                angle = 0.0D;
                p2    = new Vector3D(seg.p0);
                p2.y += h;
            }
            //g.DrawLine((int)(seg.p0.x + 0.5D), (int)(seg.p0.y + 0.5D),                    (int)(p2.x + 0.5D), (int)(p2.y + 0.5D));
            smat.SetSMat(w, h, 0.0D);
            rmat.SetRzMat(angle);
            tmat.SetTMat(p2.x, p2.y, p2.z);
            Matrix44  mat = smat.MultMat(rmat).MultMat(tmat);
            Polygon3D arw = triangle.Transform(mat);
            //g.FillPolygon(new SolidBrush(arw.IxArray(), arw.IyArray(), 3);
        }
Exemple #5
0
        /// <summary>
        /// Method to Construct the <see cref="PlaneB"/> and <see cref="PointB"/>
        /// </summary>
        private void ConstructPlaneBAndPointB()
        {
            ///<summary>Calculating the angle between the <see cref="PlaneRED"/> and the <see cref="Bisector2"/></summary>
            Angle Angle_Bis2_PlaneRED = SetupChangeDatabase.AngleInRequiredView(Custom3DGeometry.GetMathNetVector3D(LineForAngle_PlaneRED),
                                                                                Custom3DGeometry.GetMathNetVector3D(Bisector2),
                                                                                Custom3DGeometry.GetMathNetVector3D(new Line(InstantAxis.StartPoint, InstantAxis.EndPoint)));

            ///<summary>Calculating the angle between the <see cref="PlaneRED2"/> and the <see cref="Bisector2"/></summary>
            Angle Angle_Bis2_PlaneRED2 = SetupChangeDatabase.AngleInRequiredView(Custom3DGeometry.GetMathNetVector3D(LineForAngle_PlaneRed2),
                                                                                 Custom3DGeometry.GetMathNetVector3D(Bisector2),
                                                                                 Custom3DGeometry.GetMathNetVector3D(new Line(InstantAxis.StartPoint, InstantAxis.EndPoint)));

            ///<summary>Depending on which of the above 2 angles is smaller the final angle called <see cref="Angle_Bis2_Final_PlaneREDs"/> is assigned</summary>
            if (Math.Abs(Angle_Bis2_PlaneRED.Degrees) < Math.Abs(Angle_Bis1_PlaneRED.Degrees))
            {
                Angle_Bis2_Final_PlaneREDs = Angle_Bis2_PlaneRED;
                PlaneToConstructPlaneB     = PlaneRED.Clone() as Plane;
            }
            else
            {
                Angle_Bis2_Final_PlaneREDs = Angle_Bis2_PlaneRED2;
                PlaneToConstructPlaneB     = PlaneRED2.Clone() as Plane;
            }

            ///<summary>Rotating the <see cref="PlaneToConstructPlaneB"/> by an amount equal to twice the final angle calculated above</summary>
            PlaneToConstructPlaneB.Rotate(-Angle_Bis2_Final_PlaneREDs.Radians * 2, new Vector3D(InstantAxis.StartPoint, InstantAxis.EndPoint), InstantAxis.MidPoint);

            ///<summary>Depending upon the Position of <see cref="PointA"/> the <see cref="SegmentForPointB"/> is decided</summary>
            if (PointAPos == PositionOfPointA.AboveWishbones)
            {
                SegmentForPointB = new Segment3D(LBJ_Rear.Position, ToeLinkupright.Position);
            }
            else if (PointAPos == PositionOfPointA.BelowWishbones)
            {
                SegmentForPointB = new Segment3D(UBJ_Rear.Position, ToeLinkupright.Position);
            }

            ///<summary>Computing the Intersection between the <see cref="SegmentForPointB"/> and the <see cref="PlaneToConstructPlaneB"/> which results in the <see cref="PointB"/></summary>
            SegmentForPointB.IntersectWith(PlaneToConstructPlaneB, true, out PointB);

            ///<summary>Depending upon whether the <<see cref="PointA"/> is above or below the Wishbones, the Points to draw <see cref="PlaneB"/> (apart from <see cref="PointB"/>!!!) are chosen</summary>
            if (PointAPos == PositionOfPointA.AboveWishbones)
            {
                PlaneB = new Plane(BottomRearInboard.Position, BottomFrontInboard.Position, PointB);
            }
            else if (PointAPos == PositionOfPointA.BelowWishbones)
            {
                PlaneB = new Plane(TopRearInboard.Position, TopFrontInboard.Position, PointB);
            }

            PlanarEntity PlaneB_Ent = new PlanarEntity(PlaneB);
            Joint        PointB_Ent = new Joint(PointB, 5, 2);

            PointB_Ent.Color = Color.AntiqueWhite;
            //cad1.viewportLayout1.Entities.AddRange(new Entity[] { PlaneB_Ent, PointB_Ent });
        }
Exemple #6
0
        public static Segment3D Transform(this Transform transform, Segment3D segment3D, bool convertUnits = true)
        {
            if (transform == null || segment3D == null)
                return null;

            if (transform.IsIdentity)
                return new Segment3D(segment3D);

            return new Segment3D(Transform(transform, segment3D[0], convertUnits), Transform(transform, segment3D[1], convertUnits));
        }
Exemple #7
0
 public bool Intersect(Slice3D b, out Segment3D intersection)
 {
     // todo: check. this always returns false????
     intersection = null;
     if (!Plane.Intersect(b.Plane, out var line))
     {
         return(false);
     }
     return(false);
 }
Exemple #8
0
        public IList <Segment4D> Transform(Segment3D segment)
        {
            Segment4D        segment1      = new Segment4D(this.matrix4D_0.TransformTo4D(segment.Start), this.matrix4D_0.TransformTo4D(segment.End));
            List <Segment4D> segment4DList = new List <Segment4D>();

            foreach (Segment4D segment4D in (IEnumerable <Segment4D>) this.blinnClipper4D_0.Clip(segment1))
            {
                segment4DList.Add(new Segment4D(this.matrix4D_1.Transform(segment4D.Start), this.matrix4D_1.Transform(segment4D.End)));
            }
            return((IList <Segment4D>)segment4DList);
        }
        public IList <Segment4D> Transform(Segment3D segment)
        {
            Segment4D         segment1      = new Segment4D((Vector4D)segment.Start, (Vector4D)segment.End);
            IList <Segment4D> segment4DList = (IList <Segment4D>) new List <Segment4D>();

            foreach (Segment4D segment4D in (IEnumerable <Segment4D>) this.interface32_0.Clip(segment1))
            {
                segment4DList.Add(new Segment4D(this.matrix4D_0.Transform(segment4D.Start), this.matrix4D_0.Transform(segment4D.End)));
            }
            return(segment4DList);
        }
 public ReciprocatingEngine()
 {
     ac             = new Vector3D();
     vd             = new Vector3D();
     h              = 0.0D;
     v0             = 0.0D;
     enginePower0   = 0.0D;
     thrust         = 0.0D;
     fv             = new Vector3D();
     tv             = new Vector3D();
     wash_direction = new Vector3D(1.0D, 0.0D, 0.0D);
     wash_line      = new Segment3D();
 }
Exemple #11
0
        public void TestPushingOf()
        {
            var testSegment3 = new Segment3D(new Point3D(0, 0, 5), new Point3D(0, 0, 10), "TestSegment3");
            var testSegment4 = new Segment3D(new Point3D(0, -5, 2), new Point3D(0, 5, 4), "TestSegment4");
            var testSegment5 = new Segment3D(new Point3D(0, -10, 2), new Point3D(0, 0, 4), "TestSegment5");
            var testPolygon1 = new Polygon3D(new[]
                                             { new Point3D(-5, -5, 0), new Point3D(-5, 5, 0), new Point3D(5, 5, 0), new Point3D(5, -5, 0) }, "TestPolygon1");

            Assert.AreEqual(default(Vector3D), testSegment3.PushingOf(testSegment4, new Vector3D(0, 0, -5)));
            Assert.AreEqual(new Vector3D(0, 0, -5), testSegment3.PushingOf(testPolygon1, new Vector3D(0, 0, -10)));
            Assert.AreEqual(new Vector3D(0, 0, -8), testSegment4.PushingOf(testPolygon1, new Vector3D(0, 0, -10)));
            Assert.AreEqual(new Vector3D(0, 0, -7), testSegment5.PushingOf(testPolygon1, new Vector3D(0, 0, -10)));
        }
Exemple #12
0
        public void TestConstructor()
        {
            var testSegment = new Segment3D(new Point3D(0, 0, 0), new Point3D(1, 1, 1), "TestSegment1");

            Assert.AreEqual("TestSegment1", testSegment.Name);
            Assert.AreEqual(new Vector3D(1, 1, 1), testSegment.Vector);
            Assert.AreEqual(new Vector3D(1, 1, 1).Orthogonal, testSegment.Normal);

            const double tinyDiff = MSystem.Tolerance / 10;

            new Segment3D(new Point3D(0, 0, 0), new Point3D(tinyDiff, 0, 0), "TestSegment2");
            // Exception should occur here
        }
        private static void LineExtender(Line _lineToBeExtended, double _extension)
        {
            Segment3D segmentToBeInfinite = new Segment3D(_lineToBeExtended.StartPoint, _lineToBeExtended.EndPoint);

            Point3D extendedPointStart = new Point3D();
            Point3D extendedPointEnd   = new Point3D();

            extendedPointEnd.X = segmentToBeInfinite.P1.X - (((segmentToBeInfinite.P1.X - segmentToBeInfinite.P0.X) / segmentToBeInfinite.Length) * _extension);
            extendedPointEnd.Y = segmentToBeInfinite.P1.Y - (((segmentToBeInfinite.P1.Y - segmentToBeInfinite.P0.Y) / segmentToBeInfinite.Length) * _extension);
            extendedPointEnd.Z = segmentToBeInfinite.P1.Z - (((segmentToBeInfinite.P1.Z - segmentToBeInfinite.P0.Z) / segmentToBeInfinite.Length) * _extension);

            extendedPointStart.X = segmentToBeInfinite.P0.X + (((segmentToBeInfinite.P1.X - segmentToBeInfinite.P0.X) / segmentToBeInfinite.Length) * _extension);
            extendedPointStart.Y = segmentToBeInfinite.P0.Y + (((segmentToBeInfinite.P1.Y - segmentToBeInfinite.P0.Y) / segmentToBeInfinite.Length) * _extension);
            extendedPointStart.Z = segmentToBeInfinite.P0.Z + (((segmentToBeInfinite.P1.Z - segmentToBeInfinite.P0.Z) / segmentToBeInfinite.Length) * _extension);


            _lineToBeExtended.EndPoint   = extendedPointEnd;
            _lineToBeExtended.StartPoint = extendedPointStart;
        }
        public IList <Segment4D> Transform(Segment3D segment)
        {
            if (this.iclippingTransformer_0 != null)
            {
                return(this.iclippingTransformer_0.Transform(segment));
            }
            List <Segment4D> segment4DList = new List <Segment4D>();
            List <Segment3D> segment3DList = new List <Segment3D>();

            segment3DList.Add(segment);
            int count = this.linkedList_0.Count;

            foreach (IClippingTransformer clippingTransformer in this.linkedList_0)
            {
                segment4DList.Clear();
                foreach (Segment3D segment1 in segment3DList)
                {
                    segment4DList.AddRange((IEnumerable <Segment4D>)clippingTransformer.Transform(segment1));
                }
                if (segment4DList.Count != 0)
                {
                    if (--count != 0)
                    {
                        segment3DList.Clear();
                        foreach (Segment4D segment4D in segment4DList)
                        {
                            segment3DList.Add(new Segment3D((Point3D)segment4D.Start, (Point3D)segment4D.End));
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
            return((IList <Segment4D>)segment4DList);
        }
Exemple #15
0
        public static ISegmentable3D Segmentable3D(this MEPCurve mEPCurve)
        {
            if (mEPCurve == null)
            {
                return(null);
            }

            Curve curve = (mEPCurve.Location as LocationCurve)?.Curve;

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

            if (curve is Line)
            {
                Segment3D result = ((Line)curve).ToSAM();
                return(result);
            }

            return(curve.ToSAM_Polyline3D());
        }
Exemple #16
0
 public LandingGear()
 {
     damper_k   = 0.5D;
     flag       = 0;
     sa         = new Segment3D();
     t_lag_move = new double[2];
     brake      = 0.0D;
     delta      = 1.0D;
     p0w        = new Vector3D();
     p0g        = new Vector3D();
     pw         = new Vector3D();
     pg         = new Vector3D();
     vd         = new Vector3D();
     pa         = new Vector3D();
     vda        = new Vector3D();
     a_fv       = new Vector3D();
     a_tv       = new Vector3D();
     n_fv       = new Vector3D();
     n_tv       = new Vector3D();
     f_fv       = new Vector3D();
     f_tv       = new Vector3D();
 }
Exemple #17
0
 public IList <Segment4D> Transform(Segment3D segment)
 {
     return((IList <Segment4D>) new Segment4D[1] {
         new Segment4D(this.matrix4D_0.TransformTo4D(segment.Start), this.matrix4D_0.TransformTo4D(segment.End))
     });
 }
Exemple #18
0
        public static List <Autodesk.Revit.DB.Wall> TrimOrExtendWall(this IEnumerable <Autodesk.Revit.DB.Wall> walls, double maxDistance, double tolerance = Core.Tolerance.Distance)
        {
            Dictionary <double, Dictionary <Autodesk.Revit.DB.Wall, Segment2D> > dictionary = new Dictionary <double, Dictionary <Autodesk.Revit.DB.Wall, Segment2D> >();

            foreach (Autodesk.Revit.DB.Wall wall in walls)
            {
                Curve     curve     = (wall.Location as LocationCurve).Curve;
                Segment3D segment3D = Geometry.Revit.Convert.ToSAM_Segment3D(curve);

                double elevation = Math.Min(segment3D[0].Z, segment3D[1].Z);

                Dictionary <Autodesk.Revit.DB.Wall, Segment2D> dictionary_Wall = null;
                if (!dictionary.TryGetValue(elevation, out dictionary_Wall))
                {
                    dictionary_Wall       = new Dictionary <Autodesk.Revit.DB.Wall, Segment2D>();
                    dictionary[elevation] = dictionary_Wall;
                }

                dictionary_Wall[wall] = Geometry.Spatial.Plane.WorldXY.Convert(segment3D);
            }

            List <Autodesk.Revit.DB.Wall> result = new List <Autodesk.Revit.DB.Wall>();

            foreach (KeyValuePair <double, Dictionary <Autodesk.Revit.DB.Wall, Segment2D> > keyValuePair in dictionary)
            {
                List <Segment2D> segment2Ds = keyValuePair.Value.Values.ToList();

                //Filtering Walls by Level
                List <Tuple <Autodesk.Revit.DB.Wall, Segment2D, List <int>, bool> > tupleList = new List <Tuple <Autodesk.Revit.DB.Wall, Segment2D, List <int>, bool> >();
                foreach (KeyValuePair <Autodesk.Revit.DB.Wall, Segment2D> keyValuePair_Wall in keyValuePair.Value)
                {
                    LocationCurve locationCurve = keyValuePair_Wall.Key.Location as LocationCurve;

                    List <int> indexes = new List <int>();

                    ElementArray elementArray = null;

                    elementArray = locationCurve.get_ElementsAtJoin(0);
                    if (elementArray == null || elementArray.Size == 0)
                    {
                        indexes.Add(0);
                    }

                    elementArray = locationCurve.get_ElementsAtJoin(1);
                    if (elementArray == null || elementArray.Size == 0)
                    {
                        indexes.Add(1);
                    }

                    //if (indexes.Count > 0)
                    tupleList.Add(new Tuple <Autodesk.Revit.DB.Wall, Segment2D, List <int>, bool>(keyValuePair_Wall.Key, keyValuePair_Wall.Value, indexes, false));
                }

                //Seeking for walls to be extended/trimmed
                bool updated = true;
                while (updated)
                {
                    updated = false;
                    List <Tuple <Autodesk.Revit.DB.Wall, Segment2D, List <int>, bool> > tupleList_Unconnected = tupleList.FindAll(x => x.Item3 != null && x.Item3.Count > 0);
                    for (int i = 0; i < tupleList_Unconnected.Count; i++)
                    {
                        Tuple <Autodesk.Revit.DB.Wall, Segment2D, List <int>, bool> tuple = tupleList_Unconnected[i];

                        List <Tuple <Autodesk.Revit.DB.Wall, Segment2D, List <int>, bool> > tupleList_Temp = new List <Tuple <Autodesk.Revit.DB.Wall, Segment2D, List <int>, bool> >(tupleList);
                        tupleList_Temp.Remove(tuple);

                        Segment2D segment2D = tuple.Item2;
                        List <Tuple <Point2D, Segment2D> > tupleList_Intersection = new List <Tuple <Point2D, Segment2D> >();
                        foreach (Segment2D segment2D_Temp in tupleList_Temp.ConvertAll(x => x.Item2))
                        {
                            Point2D point2D_Intersection = segment2D_Temp.Intersection(segment2D, false, tolerance);
                            if (point2D_Intersection == null)
                            {
                                //Checking Colinear Segment2Ds if can be extended

                                Vector2D direction_Temp = segment2D_Temp.Direction;
                                Vector2D direction      = segment2D.Direction;

                                if (!direction_Temp.AlmostEqual(direction, tolerance) && !direction_Temp.AlmostEqual(direction.GetNegated(), tolerance))
                                {
                                    continue;
                                }

                                Point2D point2D_Temp = null;
                                Point2D point2D      = null;
                                if (!Geometry.Planar.Query.Closest(segment2D_Temp, segment2D, out point2D_Temp, out point2D, tolerance))
                                {
                                    continue;
                                }

                                if (point2D_Temp.AlmostEquals(point2D, tolerance))
                                {
                                    continue;
                                }

                                Vector2D direction_New = new Vector2D(point2D, point2D_Temp).Unit;
                                if (!direction_Temp.AlmostEqual(direction_New, tolerance) && !direction_Temp.AlmostEqual(direction_New.GetNegated(), tolerance))
                                {
                                    continue;
                                }

                                point2D_Intersection = point2D;
                            }

                            double distance;

                            distance = segment2D.Distance(point2D_Intersection);
                            if (distance > maxDistance)
                            {
                                continue;
                            }

                            distance = segment2D_Temp.Distance(point2D_Intersection);
                            if (distance > maxDistance)
                            {
                                continue;
                            }

                            tupleList_Intersection.Add(new Tuple <Point2D, Segment2D>(point2D_Intersection, segment2D_Temp));
                        }

                        if (tupleList_Intersection.Count == 0)
                        {
                            continue;
                        }

                        foreach (int index in tuple.Item3)
                        {
                            Point2D point2D = segment2D[index];

                            tupleList_Intersection.Sort((x, y) => x.Item1.Distance(point2D).CompareTo(y.Item1.Distance(point2D)));
                            Tuple <Point2D, Segment2D> tuple_Intersection = tupleList_Intersection.Find(x => x.Item1.Distance(point2D) < maxDistance);
                            if (tuple_Intersection == null)
                            {
                                continue;
                            }

                            Segment2D segment2D_Intersection = tuple_Intersection.Item2;

                            int j = tupleList.FindIndex(x => x.Item2 == segment2D_Intersection);
                            if (j == -1)
                            {
                                continue;
                            }

                            int k = tupleList.FindIndex(x => x.Item2 == segment2D);
                            if (k == -1)
                            {
                                continue;
                            }

                            //TODO: Double Check if works (added 2020.05.14)
                            if ((index == 0 && segment2D[1].AlmostEquals(tuple_Intersection.Item1)) || (index == 1 && segment2D[0].AlmostEquals(tuple_Intersection.Item1)))
                            {
                                tupleList[k] = new Tuple <Autodesk.Revit.DB.Wall, Segment2D, List <int>, bool>(tuple.Item1, new Segment2D(tuple_Intersection.Item1, tuple_Intersection.Item1), tuple.Item3.FindAll(x => x != index), true);

                                updated = true;
                                break;
                            }

                            Segment2D segment2D_Temp;

                            if (segment2D_Intersection[0].Distance(tuple_Intersection.Item1) < maxDistance || segment2D_Intersection[1].Distance(tuple_Intersection.Item1) < maxDistance)
                            {
                                segment2D_Temp = new Segment2D(segment2D_Intersection);
                                segment2D_Temp.Adjust(tuple_Intersection.Item1);
                                if (!segment2D_Temp.AlmostSimilar(segment2D_Intersection) && segment2D_Temp.GetLength() > segment2D_Intersection.GetLength())
                                {
                                    tupleList[j] = new Tuple <Autodesk.Revit.DB.Wall, Segment2D, List <int>, bool>(tupleList[j].Item1, segment2D_Temp, tupleList[j].Item3.FindAll(x => x != segment2D_Temp.GetEndIndex(tuple_Intersection.Item1)), true);
                                }
                            }

                            segment2D_Temp = new Segment2D(segment2D);
                            segment2D_Temp.Adjust(tuple_Intersection.Item1);
                            if (segment2D_Temp.AlmostSimilar(segment2D))
                            {
                                continue;
                            }

                            tupleList[k] = new Tuple <Autodesk.Revit.DB.Wall, Segment2D, List <int>, bool>(tuple.Item1, segment2D_Temp, tuple.Item3.FindAll(x => x != index), true);

                            updated = true;
                            break;
                        }

                        if (updated)
                        {
                            break;
                        }
                    }
                }

                tupleList.RemoveAll(x => !x.Item4);

                //Updating Revit Walls
                foreach (Tuple <Autodesk.Revit.DB.Wall, Segment2D, List <int>, bool> tuple in tupleList)
                {
                    Autodesk.Revit.DB.Wall wall = tuple.Item1;
                    if (!wall.IsValidObject)
                    {
                        continue;
                    }

                    Segment2D segment2D = tuple.Item2;
                    if (segment2D.GetLength() < tolerance)
                    {
                        wall.Document.Delete(wall.Id);
                        continue;
                    }

                    LocationCurve locationCurve = wall.Location as LocationCurve;

                    JoinType[] joinTypes = new JoinType[] { locationCurve.get_JoinType(0), locationCurve.get_JoinType(1) };
                    WallUtils.DisallowWallJoinAtEnd(wall, 0);
                    WallUtils.DisallowWallJoinAtEnd(wall, 1);

                    Segment3D segment3D = new Segment3D(new Point3D(segment2D[0].X, segment2D[0].Y, keyValuePair.Key), new Point3D(segment2D[1].X, segment2D[1].Y, keyValuePair.Key));

                    Line line = Geometry.Revit.Convert.ToRevit(segment3D);

                    locationCurve.Curve = line;

                    WallUtils.AllowWallJoinAtEnd(wall, 0);
                    locationCurve.set_JoinType(0, joinTypes[0]);

                    WallUtils.AllowWallJoinAtEnd(wall, 1);
                    locationCurve.set_JoinType(1, joinTypes[1]);

                    result.Add(tuple.Item1);
                }
            }

            return(result);
        }
Exemple #19
0
        // Draws preview of horizontal/vertical dimension for a line
        private void DrawInteractiveLinearDim()
        {
            // We need to have two reference points selected, might be snapped vertices
            if (points.Count < 2)
            {
                return;
            }

            bool verticalDim = (current.X > points[0].X && current.X > points[1].X) || (current.X < points[0].X && current.X < points[1].X);

            Vector3D axisX;

            if (verticalDim)
            {
                axisX = Vector3D.AxisY;

                extPt1 = new Point3D(current.X, points[0].Y);
                extPt2 = new Point3D(current.X, points[1].Y);

                if (current.X > points[0].X && current.X > points[1].X)
                {
                    extPt1.X += dimTextHeight / 2;
                    extPt2.X += dimTextHeight / 2;
                }
                else
                {
                    extPt1.X -= dimTextHeight / 2;
                    extPt2.X -= dimTextHeight / 2;
                }
            }
            else//for horizontal
            {
                axisX = Vector3D.AxisX;

                extPt1 = new Point3D(points[0].X, current.Y);
                extPt2 = new Point3D(points[1].X, current.Y);

                if (current.Y > points[0].Y && current.Y > points[1].Y)
                {
                    extPt1.Y += dimTextHeight / 2;
                    extPt2.Y += dimTextHeight / 2;
                }
                else
                {
                    extPt1.Y -= dimTextHeight / 2;
                    extPt2.Y -= dimTextHeight / 2;
                }
            }

            Vector3D axisY = Vector3D.Cross(Vector3D.AxisZ, axisX);


            List <Point3D> pts = new List <Point3D>();

            // Draw extension line1
            pts.Add(WorldToScreen(points[0]));
            pts.Add(WorldToScreen(extPt1));

            // Draw extension line2
            pts.Add(WorldToScreen(points[1]));
            pts.Add(WorldToScreen(extPt2));

            //Draw dimension line
            Segment3D extLine1 = new Segment3D(points[0], extPt1);
            Segment3D extLine2 = new Segment3D(points[1], extPt2);
            Point3D   pt1      = current.ProjectTo(extLine1);
            Point3D   pt2      = current.ProjectTo(extLine2);

            pts.Add(WorldToScreen(pt1));
            pts.Add(WorldToScreen(pt2));

            renderContext.DrawLines(pts.ToArray());

            //store dimensioning plane
            drawingPlane = new Plane(points[0], axisX, axisY);

            //draw dimension text
            renderContext.EnableXOR(false);

            string dimText = "L " + extPt1.DistanceTo(extPt2).ToString("f3");

            DrawText(mouseLocation.X, (int)Size.Height - mouseLocation.Y + 10, dimText,
                     new Font("Tahoma", 8.25f), DrawingColor, ContentAlignment.BottomLeft);
        }
Exemple #20
0
        protected override void TrySolveInstance(IGH_DataAccess dataAccess)
        {
            int index = -1;

            bool run = false;

            index = Params.IndexOfInputParam("_run");
            if (index == -1 || !dataAccess.GetData(index, ref run) || !run)
            {
                return;
            }

            double maxDistance = 0.2;

            index = Params.IndexOfInputParam("_maxDistance");
            if (index == -1 || !dataAccess.GetData(index, ref maxDistance))
            {
                return;
            }

            RhinoInside.Revit.GH.Types.Level level_GH = null;
            index = Params.IndexOfInputParam("_level");
            if (index == -1 || !dataAccess.GetData(index, ref level_GH))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            RhinoInside.Revit.GH.Types.Level referenceLevel_GH = null;
            index = Params.IndexOfInputParam("_referenceLevel");
            if (index == -1 || !dataAccess.GetData(index, ref referenceLevel_GH))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            Level level = level_GH.Value;

            if (level == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            Level referenceLevel = referenceLevel_GH.Value;

            if (level == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

#if Revit2017 || Revit2018 || Revit2019 || Revit2020
            double elevation          = UnitUtils.ConvertFromInternalUnits(level.Elevation, DisplayUnitType.DUT_METERS);
            double referenceElevation = UnitUtils.ConvertFromInternalUnits(referenceLevel.Elevation, DisplayUnitType.DUT_METERS);
#else
            double elevation          = UnitUtils.ConvertFromInternalUnits(level.Elevation, UnitTypeId.Meters);
            double referenceElevation = UnitUtils.ConvertFromInternalUnits(referenceLevel.Elevation, UnitTypeId.Meters);
#endif

            Document document = level.Document;

            IEnumerable <Autodesk.Revit.DB.Wall> walls_All = new FilteredElementCollector(document).OfClass(typeof(Autodesk.Revit.DB.Wall)).Cast <Autodesk.Revit.DB.Wall>();
            if (walls_All == null || walls_All.Count() == 0)
            {
                return;
            }

            StartTransaction(document);

            ConvertSettings convertSettings = new ConvertSettings(true, true, true);

            List <Panel> panels           = new List <Panel>();
            List <Panel> panels_Reference = new List <Panel>();
            foreach (Autodesk.Revit.DB.Wall wall in walls_All)
            {
                List <Panel> panels_Temp = Analytical.Revit.Convert.ToSAM(wall, convertSettings);
                foreach (Panel panel in panels_Temp)
                {
                    double max = panel.MaxElevation();
                    double min = panel.MinElevation();

                    if (Math.Abs(min - elevation) < Core.Tolerance.Distance || (min - Core.Tolerance.Distance < elevation && max - Core.Tolerance.Distance > elevation))
                    {
                        panels.Add(panel);
                    }

                    if (Math.Abs(min - referenceElevation) < Core.Tolerance.Distance || (min - Core.Tolerance.Distance < referenceElevation && max - Core.Tolerance.Distance > referenceElevation))
                    {
                        panels_Reference.Add(panel);
                    }
                }
            }

            IEnumerable <ElementId> elementIds           = panels.ConvertAll(x => x.ElementId()).Distinct();
            IEnumerable <ElementId> elementIds_Reference = panels_Reference.ConvertAll(x => x.ElementId()).Distinct();

            Geometry.Spatial.Plane plane = new Geometry.Spatial.Plane(new Point3D(0, 0, elevation), Vector3D.WorldZ);

            Dictionary <Segment2D, HostObjAttributes> dictionary_Reference = new Dictionary <Segment2D, HostObjAttributes>();
            foreach (ElementId elementId in elementIds_Reference)
            {
                Element element = document.GetElement(elementId);
                if (element == null)
                {
                    continue;
                }

                HostObjAttributes hostObjAttributes = document.GetElement(element.GetTypeId()) as HostObjAttributes;
                if (hostObjAttributes == null)
                {
                    continue;
                }

                LocationCurve  locationCurve = element.Location as LocationCurve;
                ISegmentable3D segmentable3D = locationCurve.ToSAM() as ISegmentable3D;
                if (segmentable3D == null)
                {
                    continue;
                }

                List <Segment3D> segment3Ds = segmentable3D.GetSegments();
                if (segment3Ds == null || segment3Ds.Count == 0)
                {
                    continue;
                }

                segment3Ds.ForEach(x => dictionary_Reference[plane.Convert(x)] = hostObjAttributes);
            }

            Dictionary <Segment2D, ElementId> dictionary = new Dictionary <Segment2D, ElementId>();
            foreach (ElementId elementId in elementIds)
            {
                LocationCurve locationCurve = document.GetElement(elementId).Location as LocationCurve;
                Segment3D     segment3D     = locationCurve.ToSAM() as Segment3D;
                if (segment3D == null)
                {
                    continue;
                }

                dictionary[plane.Convert(plane.Project(segment3D))] = elementId;
            }

            Dictionary <Segment2D, ElementId> dictionary_Result = new Dictionary <Segment2D, ElementId>();
            foreach (KeyValuePair <Segment2D, ElementId> keyValuePair in dictionary)
            {
                Segment2D segment2D = keyValuePair.Key;

                List <Segment2D> segment2Ds_Temp = dictionary_Reference.Keys.ToList().FindAll(x => x.Collinear(segment2D) && x.Distance(segment2D) <= maxDistance + Core.Tolerance.MacroDistance && x.Distance(segment2D) > Core.Tolerance.MacroDistance);
                if (segment2Ds_Temp == null || segment2Ds_Temp.Count == 0)
                {
                    continue;
                }

                Element element = document.GetElement(keyValuePair.Value);
                if (element == null)
                {
                    continue;
                }

                HostObjAttributes hostObjAttributes = document.GetElement(element.GetTypeId()) as HostObjAttributes;
                if (hostObjAttributes == null)
                {
                    continue;
                }

                segment2Ds_Temp.Sort((x, y) => segment2D.Distance(x).CompareTo(segment2D.Distance(y)));

                Segment2D segment2D_Reference = null;

                foreach (Segment2D segment2D_Temp in segment2Ds_Temp)
                {
                    HostObjAttributes hostObjAttributes_Temp = dictionary_Reference[segment2D_Temp];
                    if (hostObjAttributes.Name.Equals(hostObjAttributes_Temp.Name))
                    {
                        segment2D_Reference = segment2D_Temp;
                        break;
                    }
                }

                if (segment2D_Reference == null)
                {
                    HashSet <PanelType> panelTypes = new HashSet <PanelType>();
                    panelTypes.Add(Analytical.Revit.Query.PanelType(hostObjAttributes));
                    switch (panelTypes.First())
                    {
                    case PanelType.CurtainWall:
                        panelTypes.Add(PanelType.WallExternal);
                        break;

                    case PanelType.UndergroundWall:
                        panelTypes.Add(PanelType.WallExternal);
                        break;

                    case PanelType.Undefined:
                        panelTypes.Add(PanelType.WallInternal);
                        break;
                    }

                    foreach (Segment2D segment2D_Temp in segment2Ds_Temp)
                    {
                        HostObjAttributes hostObjAttributes_Temp = dictionary_Reference[segment2D_Temp];
                        PanelType         panelType_Temp         = Analytical.Revit.Query.PanelType(hostObjAttributes_Temp);
                        if (panelTypes.Contains(panelType_Temp))
                        {
                            segment2D_Reference = segment2D_Temp;
                            break;
                        }
                    }
                }

                if (segment2D_Reference == null)
                {
                    segment2D_Reference = segment2Ds_Temp.First();
                }

                Segment2D segment2D_Project = segment2D_Reference.Project(segment2D);
                if (segment2D_Project == null)
                {
                    continue;
                }

                dictionary_Result[segment2D_Project] = dictionary[segment2D];
            }

            List <HostObject> result = new List <HostObject>();

            foreach (KeyValuePair <Segment2D, ElementId> keyValuePair in dictionary_Result)
            {
                Autodesk.Revit.DB.Wall wall = document.GetElement(keyValuePair.Value) as Autodesk.Revit.DB.Wall;

                if (wall == null || !wall.IsValidObject)
                {
                    continue;
                }

                Segment2D segment2D = keyValuePair.Key;

                bool pinned = wall.Pinned;

                if (wall.Pinned)
                {
                    using (SubTransaction subTransaction = new SubTransaction(document))
                    {
                        subTransaction.Start();
                        wall.Pinned = false;
                        subTransaction.Commit();
                    }
                }

                Segment3D     segment3D     = plane.Convert(segment2D);
                LocationCurve locationCurve = wall.Location as LocationCurve;

                using (SubTransaction subTransaction = new SubTransaction(document))
                {
                    subTransaction.Start();

                    document.Regenerate();
                    locationCurve.Curve = Geometry.Revit.Convert.ToRevit(segment3D);

                    subTransaction.Commit();
                }

                if (wall.Pinned != pinned)
                {
                    using (SubTransaction subTransaction = new SubTransaction(document))
                    {
                        subTransaction.Start();
                        wall.Pinned = pinned;
                        subTransaction.Commit();
                    }
                }
                result.Add(wall);
            }

            index = Params.IndexOfOutputParam("walls");
            if (index != -1)
            {
                dataAccess.SetDataList(index, result);
            }
        }
Exemple #21
0
 public static Line ToRevit(this Segment3D segment3D)
 {
     return(Line.CreateBound(segment3D.GetStart().ToRevit(), segment3D.GetEnd().ToRevit()));
 }
Exemple #22
0
        // Draws preview of horizontal/vertical dimension for a line
        private void DrawInteractiveLinearDim()
        {
            // 2 points needed to draw the interactive LinearDim
            if (_numPoints < 2)
            {
                return;
            }

            bool verticalDim = (_current.X > _points[0].X && _current.X > _points[1].X) || (_current.X < _points[0].X && _current.X < _points[1].X);

            Vector3D axisX;

            double convertedDimTextHeight = DimTextHeight * GetUnitsConversionFactor();

            if (verticalDim)
            {
                axisX = Vector3D.AxisY;

                _extPt1 = new Point3D(_current.X, _points[0].Y);
                _extPt2 = new Point3D(_current.X, _points[1].Y);

                if (_current.X > _points[0].X && _current.X > _points[1].X)
                {
                    _extPt1.X += convertedDimTextHeight / 2;
                    _extPt2.X += convertedDimTextHeight / 2;
                }
                else
                {
                    _extPt1.X -= convertedDimTextHeight / 2;
                    _extPt2.X -= convertedDimTextHeight / 2;
                }
            }
            else // for horizontal LinearDim
            {
                axisX = Vector3D.AxisX;

                _extPt1 = new Point3D(_points[0].X, _current.Y);
                _extPt2 = new Point3D(_points[1].X, _current.Y);

                if (_current.Y > _points[0].Y && _current.Y > _points[1].Y)
                {
                    _extPt1.Y += convertedDimTextHeight / 2;
                    _extPt2.Y += convertedDimTextHeight / 2;
                }
                else
                {
                    _extPt1.Y -= convertedDimTextHeight / 2;
                    _extPt2.Y -= convertedDimTextHeight / 2;
                }
            }

            // defines the Y axis
            Vector3D axisY = Vector3D.Cross(Vector3D.AxisZ, axisX);

            List <Point3D> pts = new List <Point3D>();

            // draws extension line1
            pts.Add(WorldToScreen(_points[0]));
            pts.Add(WorldToScreen(_extPt1));

            // draws extension line2
            pts.Add(WorldToScreen(_points[1]));
            pts.Add(WorldToScreen(_extPt2));

            // draws dimension line
            Segment3D extLine1 = new Segment3D(_points[0], _extPt1);
            Segment3D extLine2 = new Segment3D(_points[1], _extPt2);
            Point3D   pt1      = _current.ProjectTo(extLine1);
            Point3D   pt2      = _current.ProjectTo(extLine2);

            pts.Add(WorldToScreen(pt1));
            pts.Add(WorldToScreen(pt2));

            renderContext.DrawLines(pts.ToArray());

            // stores dimensioning plane
            _drawingPlane = new Plane(_points[0], axisX, axisY);

            // draws dimension text
            renderContext.EnableXOR(false);

            // calculates the scaled distance
            var    scaledDistance = _extPt1.DistanceTo(_extPt2) * (1 / _viewScale);
            string dimText        = "L " + scaledDistance.ToString("f3");

            DrawText(_mouseLocation.X, (int)Size.Height - _mouseLocation.Y + 10, dimText,
                     new Font("Tahoma", 8.25f), DrawingColor, ContentAlignment.BottomLeft);
        }
Exemple #23
0
 public Segment3D Project(Segment3D segment)
 {
     return(new Segment3D(Project(segment.A), Project(segment.B)));
 }
Exemple #24
0
        public bool GetIntersectionParameters(Segment3D segment, out double p0, out double p1)
        {
            p0 = 0.0;
            p1 = 1.0;
            Point3D  start = segment.Start;
            Vector3D delta = segment.GetDelta();
            double   num1  = 1.0 / delta.X;
            double   num2  = (this.point3D_0.X - start.X) * num1;

            if (double.IsNaN(num2))
            {
                num2 = double.NegativeInfinity;
            }
            double num3 = (this.point3D_1.X - start.X) * num1;

            if (double.IsNaN(num3))
            {
                num3 = double.PositiveInfinity;
            }
            if (num3 < num2)
            {
                double num4 = num3;
                num3 = num2;
                num2 = num4;
            }
            p0 = System.Math.Max(p0, num2);
            p1 = System.Math.Min(p1, num3);
            if (p1 < p0)
            {
                return(false);
            }
            double num5 = 1.0 / delta.Y;
            double num6 = (this.point3D_0.Y - start.Y) * num5;

            if (double.IsNaN(num6))
            {
                num6 = double.NegativeInfinity;
            }
            double num7 = (this.point3D_1.Y - start.Y) * num5;

            if (double.IsNaN(num7))
            {
                num7 = double.PositiveInfinity;
            }
            if (num7 < num6)
            {
                double num4 = num7;
                num7 = num6;
                num6 = num4;
            }
            p0 = System.Math.Max(p0, num6);
            p1 = System.Math.Min(p1, num7);
            if (p1 < p0)
            {
                return(false);
            }
            double num8 = 1.0 / delta.Z;
            double num9 = (this.point3D_0.Z - start.Z) * num8;

            if (double.IsNaN(num9))
            {
                num9 = double.NegativeInfinity;
            }
            double num10 = (this.point3D_1.Z - start.Z) * num8;

            if (double.IsNaN(num10))
            {
                num10 = double.PositiveInfinity;
            }
            if (num10 < num9)
            {
                double num4 = num10;
                num10 = num9;
                num9  = num4;
            }
            p0 = System.Math.Max(p0, num9);
            p1 = System.Math.Min(p1, num10);
            return(p1 >= p0);
        }
Exemple #25
0
        public static List <T> ToSAM <T>(this GeometryElement geometryElement, Transform transform = null) where T : ISAMGeometry
        {
            if (geometryElement == null)
            {
                return(null);
            }

            List <T> result = new List <T>();

            foreach (GeometryObject geometryObject in geometryElement)
            {
                if (geometryObject is GeometryInstance)
                {
                    GeometryInstance geometryInstance = (GeometryInstance)geometryObject;

                    Transform geometryTransform = geometryInstance.Transform;
                    if (transform != null)
                    {
                        geometryTransform = geometryTransform.Multiply(transform.Inverse);
                    }

                    GeometryElement geometryElement_Temp = geometryInstance.GetInstanceGeometry(geometryTransform);
                    if (geometryElement_Temp == null)
                    {
                        continue;
                    }

                    List <T> sAMGeometries = ToSAM <T>(geometryElement_Temp);
                    if (sAMGeometries != null && sAMGeometries.Count > 0)
                    {
                        result.AddRange(sAMGeometries);
                    }
                }
                else if (geometryObject is Solid)
                {
                    if (typeof(T).IsAssignableFrom(typeof(Shell)))
                    {
                        Shell shell = ((Solid)geometryObject).ToSAM();
                        if (shell != null)
                        {
                            result.Add((T)(ISAMGeometry)shell);
                        }
                    }
                    else if (typeof(T).IsAssignableFrom(typeof(Face3D)))
                    {
                        List <Face3D> face3Ds = ((Solid)geometryObject).ToSAM_Face3Ds();
                        if (face3Ds != null)
                        {
                            foreach (Face3D face3D in face3Ds)
                            {
                                result.Add((T)(ISAMGeometry)face3D);
                            }
                        }
                    }
                }
                else if (geometryObject is Line)
                {
                    if (typeof(T).IsAssignableFrom(typeof(ISegmentable3D)))
                    {
                        Segment3D segment3D = ((Line)geometryObject).ToSAM();
                        if (segment3D != null)
                        {
                            result.Add((T)(ISAMGeometry)segment3D);
                        }
                    }
                }
                else if (geometryObject is Curve)
                {
                    if (typeof(T).IsAssignableFrom(typeof(ICurve3D)))
                    {
                        ICurve3D curve3D = ((Curve)geometryObject).ToSAM();
                        if (curve3D != null)
                        {
                            result.Add((T)curve3D);
                        }
                    }
                }
            }
            return(result);
        }