Exemplo n.º 1
0
        private void SetHangers(PanelFrame panelFrame, List <Point3d> bayMinima)
        {
            foreach (Point3d p in bayMinima)
            {
                if (panelFrame.UnitBoundary.Contains(p, panelFrame.localPlane, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance) == PointContainment.Inside)
                {
                    Point3d planePt = panelFrame.localPlane.ClosestPoint(p);

                    List <Line> frameLinesX = new List <Line>();
                    List <Line> frameLinesY = new List <Line>();
                    Plane       pln         = new Plane(planePt, panelFrame.localPlane.YAxis);
                    panelFrame.SetFrameLines(ref panelFrame.nodeGrid, ref frameLinesX, ref frameLinesY);
                    Dictionary <Point3d, double> pointDist = new Dictionary <Point3d, double>();
                    double   t           = 0;
                    bool     shiftStalac = false;
                    Vector3d shift       = new Vector3d();
                    foreach (Line frame  in frameLinesY)
                    {
                        Rhino.Geometry.Intersect.Intersection.LinePlane(frame, pln, out t);
                        if (t >= 0 && t <= 1)
                        {
                            Point3d interPt = frame.PointAt(t);
                            if (interPt.DistanceTo(frame.To) < 300)
                            {
                                shift       = frame.To - interPt;
                                interPt     = frame.To;
                                shiftStalac = true;
                            }

                            if (interPt.DistanceTo(frame.From) < 300)
                            {
                                shift       = frame.From - interPt;
                                interPt     = frame.From;
                                shiftStalac = true;
                            }

                            pointDist.Add(interPt, interPt.DistanceTo(planePt));
                        }
                    }
                    if (shiftStalac)
                    {
                        //move the point
                        Transform xform = Transform.Translation(shift);
                        p.Transform(xform);
                    }

                    if (pointDist.Count < 2)
                    {
                        Line vertical = new Line(p, planePt);
                        panelFrame.stalactiteVertical.Add(vertical);
                        RhinoDoc.ActiveDoc.Objects.AddLine(vertical);
                        continue;
                    }
                    var myList = pointDist.ToList();

                    myList.Sort((pair1, pair2) => pair1.Value.CompareTo(pair2.Value));
                    Point3d s         = myList[0].Key;
                    Point3d e         = myList[1].Key;
                    Line    startLine = new Line(s, panelFrame.localPlane.ZAxis * 100000);
                    Line    endLine   = new Line(e, panelFrame.localPlane.ZAxis * 100000);

                    Point3d Start = new Point3d();
                    Point3d End   = new Point3d();
                    double  p1    = 0;
                    double  p2    = 0;

                    foreach (Line frame in panelFrame.frameLinesY)
                    {
                        bool inter1 = Rhino.Geometry.Intersect.Intersection.LineLine(startLine, frame, out p1, out p2);
                        if (startLine.PointAt(p1).DistanceTo(frame.PointAt(p2)) < 5)
                        {
                            if (p2 >= 0 && p2 <= 1 && p1 >= 0 && p1 <= 1)
                            {
                                Start = frame.PointAt(p2);
                            }
                        }
                    }
                    foreach (Line frame in panelFrame.frameLinesY)
                    {
                        bool inter2 = Rhino.Geometry.Intersect.Intersection.LineLine(endLine, frame, out p1, out p2);
                        if (endLine.PointAt(p1).DistanceTo(frame.PointAt(p2)) < 5)
                        {
                            if (p2 >= 0 && p2 <= 1 && p1 >= 0 && p1 <= 1)
                            {
                                End = frame.PointAt(p2);
                            }
                        }
                    }
                    if (End.Z == 0 || Start.Z == 0)
                    {
                        Line vertical = new Line(p, planePt);
                        panelFrame.stalactiteVertical.Add(vertical);
                        RhinoDoc.ActiveDoc.Objects.AddLine(vertical);
                    }
                    else
                    {
                        Line sFrame   = new Line(Start, End);
                        Line vLine    = new Line(p, panelFrame.localPlane.ZAxis * 100000);
                        bool inter3   = Rhino.Geometry.Intersect.Intersection.LineLine(vLine, sFrame, out p1, out p2);
                        Line vertical = new Line(p, sFrame.PointAt(p2));
                        if (!shiftStalac)
                        {
                            panelFrame.stalactiteSubFrame.Add(sFrame);
                            RhinoDoc.ActiveDoc.Objects.AddLine(sFrame);
                        }
                        panelFrame.stalactiteVertical.Add(vertical);
                        RhinoDoc.ActiveDoc.Objects.AddLine(vertical);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void TrySnapGhosts(PanelFrame panelFrame, int rowToAdjust)
        {
            //only apply to edge near clash
            if (panelFrame.clashFixAttempted)
            {
                return;
            }
            panelFrame.clashFixAttempted = true;
            for (int i = 0; i < panelFrame.meshnodes.Count; i++)
            {
                //skip middle row
                if (panelFrame.meshnodes.Count == 3 && i == 1)
                {
                    continue;
                }
                if (i != rowToAdjust)
                {
                    continue;
                }
                for (int j = 0; j < panelFrame.meshnodes[i].Count; j++)
                {
                    if (panelFrame.meshnodes[i][j].isGhost)
                    {
                        bool     replaceSupport = false;
                        Point3d  closestExtra   = CaveTools.ClosestPoint(panelFrame.frameGrid[i][j], panelFrame.meshExtraSupport.Stubs.Select(x => x.From).ToList());
                        Line     frameline      = new Line();
                        Vector3d test           = panelFrame.frameGrid[i][j] - closestExtra;

                        foreach (Line line in panelFrame.frameLinesX)
                        {
                            if (panelFrame.frameGrid[i][j].DistanceTo(line.ClosestPoint(panelFrame.frameGrid[i][j], true)) < 5)
                            {
                                frameline = line;
                            }
                            // angle should be small a and dist on line
                            double angle = Vector3d.VectorAngle(test, line.Direction);
                            if (Math.Abs(angle - Math.PI) < 0.05 || angle < 0.05)
                            {
                                //the extra stub is on the same frame line
                                Point3d ptOnLn = line.ClosestPoint(closestExtra, true);

                                if (panelFrame.frameGrid[i][j].DistanceTo(ptOnLn) < line.Length && closestExtra.DistanceTo(ptOnLn) < 5)
                                {
                                    replaceSupport = true;
                                    break;
                                }
                            }
                        }
                        if (replaceSupport)
                        {
                            FrameGridToExtraSupportPos(panelFrame, frameline, i, j, closestExtra);
                        }
                        else
                        {
                            FrameGridToLineCentre(panelFrame, frameline, i, j);
                        }
                    }
                }
            }
            //now re set frame
            panelFrame.frameLinesX = new List <Line>();
            panelFrame.frameLinesY = new List <Line>();
            panelFrame.SetFrameLines(ref panelFrame.frameGrid, ref panelFrame.frameLinesX, ref panelFrame.frameLinesY);
        }