Exemple #1
0
        //addRhinoObject-pointOnObjRef (where curve on)
        //drawPoint,editPointSN in PointMarkers-addSceneNode
        public void resetVariables()
        {
            point_g      = new Geometry.PointMarker(new Vector3());
            currentState = State.READY;

            targetPRhObjID = Guid.Empty;
            //pointOnObjRef = null;
            drawPoint = null;
            projectP  = new Point3d();

            snapPointsList = new List <Point3d>();
            rayCastingObjs = new List <ObjRef>();

            pointsList   = new List <Point3d>();
            pointMarkers = new List <SceneNode>();
            contourCurve = null;
            curvePlane   = new Plane();

            toleranceMax = 100;
            snapDistance = 40;
            isSnap       = false;
            shouldSnap   = false;

            moveControlerOrigin = new Point3d();
            movePlaneRef        = null;
            planeNormal         = new Rhino.Geometry.Vector3d();

            lastTranslate = 0.0f;
        }
Exemple #2
0
        public static string ToSVG(this Rg.Ellipse input)
        {
            Rg.Vector3d axisX = input.Plane.XAxis;
            axisX.Unitize();
            axisX = axisX * input.Radius1;

            Rg.Vector3d axisY = input.Plane.YAxis;
            axisY.Unitize();
            axisY = axisY * input.Radius2;

            Rg.Point3d A = input.Plane.Origin + axisX;
            Rg.Point3d B = input.Plane.Origin + axisY;

            axisX.Reverse();
            axisY.Reverse();

            Rg.Point3d C = input.Plane.Origin + axisX;
            Rg.Point3d D = input.Plane.Origin + axisY;

            double radians = Rg.Vector3d.VectorAngle(input.Plane.YAxis, Rg.Vector3d.YAxis, Rg.Plane.WorldXY);
            double degrees = 180.0 - (radians / Math.PI) * 180.0;
            int    flip    = Convert.ToInt32(!(Rg.Vector3d.VectorAngle(input.Plane.ZAxis, Rg.Vector3d.ZAxis) > 1));

            return("M " + A.ToSVG()
                   + " A " + input.Radius1 + ", " + input.Radius2 + " " + degrees + " 0," + flip + " " + B.ToSVG()
                   + " A " + input.Radius1 + ", " + input.Radius2 + " " + degrees + " 0," + flip + " " + C.ToSVG()
                   + " A " + input.Radius1 + ", " + input.Radius2 + " " + degrees + " 0," + flip + " " + D.ToSVG()
                   + " A " + input.Radius1 + ", " + input.Radius2 + " " + degrees + " 0," + flip + " " + A.ToSVG());
        }
 public void set_direction(Rhino.Geometry.Point3d rec, Rhino.Geometry.Point3d dir)
 {
     this.Enabled = true;
     Rhino.Geometry.Vector3d V = new Vector3d(dir.X, dir.Y, dir.Z);
     V.Unitize();
     Dir = new Rhino.Geometry.Line(rec, rec + V);
 }
Exemple #4
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Rhino.Geometry.Point3d startPoint = new Rhino.Geometry.Point3d();
            DA.GetData(0, ref startPoint);

            Rhino.Geometry.Vector3d directionVector = new Rhino.Geometry.Vector3d();
            DA.GetData(1, ref directionVector);

            double lineDistance = 0;

            DA.GetData(2, ref lineDistance);

            double startingVectorLength = directionVector.Length;
            double scalingFactor        = lineDistance / startingVectorLength;

            Rhino.Geometry.Vector3d newDirectionVector = directionVector * scalingFactor;

            double deltaX = newDirectionVector.X;
            double deltaY = newDirectionVector.Y;

            double baseX = startPoint.X;
            double baseY = startPoint.Y;

            Rhino.Geometry.Point2d outputCurveEndPoint   = new Rhino.Geometry.Point2d(baseX + deltaX, baseY + deltaY);
            Rhino.Geometry.Point2d outputCurveStartPoint = new Rhino.Geometry.Point2d(baseX - deltaX, baseY - deltaY);

            Rhino.Geometry.Curve outputCurve = new Rhino.Geometry.LineCurve(outputCurveStartPoint, outputCurveEndPoint) as Rhino.Geometry.Curve;

            DA.SetData(0, outputCurve);
        }
Exemple #5
0
        /***************************************************/
        /**** Public Methods - IRender                  ****/
        /***************************************************/

        public static Text3d ToRhino(this RenderText renderText)
        {
            if (renderText == null)
            {
                return(null);
            }

            RHG.Vector3d xdir      = (RHG.Vector3d)renderText.Cartesian.X.IToRhino();
            RHG.Vector3d ydir      = (RHG.Vector3d)renderText.Cartesian.Y.IToRhino();
            RHG.Point3d  pos       = (RHG.Point3d)renderText.Cartesian.Origin.IToRhino();
            RHG.Plane    textPlane = new RHG.Plane(pos, xdir, ydir);
            Text3d       text3D    = new Text3d(renderText.Text, textPlane, renderText.Height);

            if (renderText.FontName.Contains("Italic"))
            {
                text3D.Italic = true;
            }

            if (renderText.FontName.Contains("Bold"))
            {
                text3D.Bold = true;
            }

            text3D.FontFace = renderText.FontName.Replace("Italic", "").Replace("Bold", "").Trim();

            return(text3D);
        }
Exemple #6
0
        public static Rhino.Geometry.Rectangle3d MakeRect(Rhino.Geometry.Point3d origin,
                                                          int x_Ex, int y_Ex, int gridSize, int offset = 0)
        {
            var offsOrigin = new Point3d(origin.X + offset, origin.Y + offset, 0);
            var planeXY    = new  Plane(offsOrigin, Vector3d.ZAxis);

            return(new Rhino.Geometry.Rectangle3d(planeXY, (x_Ex * gridSize) - offset * 2, (y_Ex * gridSize) - offset * 2));
        }
Exemple #7
0
 public static Rhino.Geometry.Point3d Lerp(Rhino.Geometry.Point3d p0, Rhino.Geometry.Point3d p1, double amount)
 {
     return(new Rhino.Geometry.Point3d(
                Lerp(p0.X, p1.X, amount),
                Lerp(p0.Y, p1.Y, amount),
                Lerp(p0.Z, p1.Z, amount)
                ));
 }
Exemple #8
0
 public static System.Drawing.Point ToDrawingPoint(this Rg.Point3d input, int transposition = 0)
 {
     if (transposition > 0)
     {
         return(new System.Drawing.Point((int)input.X, (int)(transposition - input.Y)));
     }
     return(new System.Drawing.Point((int)input.X, (int)input.Y));
 }
Exemple #9
0
        public static Rhino.Geometry.Rectangle3d MakeRect(Rhino.Geometry.Point3d center, double width, double height)
        {
            var plane = new Plane(center, Vector3d.ZAxis);
            var max   = new Point3d(center.X + (width / 2.0), center.Y + (height / 2.0), 0);
            var min   = new Point3d(center.X - (width / 2.0), center.Y - (height / 2.0), 0);
            var rect  = new Rectangle3d(plane, max, min);

            return(rect);
        }
Exemple #10
0
 /// <summary> Add a user determined point object and add point in Rhino space </summary>
 /// <returns> Rhino Point 3D </returns>
 public Rhino.Commands.Result selectPoint()
 {
     Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
     gp.SetCommandPrompt("Drawing plane origin");
     gp.Get();
     org = gp.Point();
     mRhinoDoc.Objects.AddPoint(org);
     mRhinoDoc.Views.Redraw();
     return(Rhino.Commands.Result.Success);
 }
Exemple #11
0
        private List <Rhino.Geometry.Point3d> ReadRfemNodes(string pointsListInput)
        {
            // Gets interface to running RFEM application.
            app = Marshal.GetActiveObject("RFEM5.Application") as IApplication;
            // Locks RFEM licence
            app.LockLicense();

            // Gets interface to active RFEM model.
            model = app.GetActiveModel();

            // Gets interface to model data.
            IModelData data = model.GetModelData();

            //Create new array for Rhino point objects
            List <Rhino.Geometry.Point3d> rhinoPointArray = new List <Rhino.Geometry.Point3d>();

            try
            {
                for (int index = 0; index < data.GetNodeCount(); index++)
                {
                    Dlubal.RFEM5.Node      currentNode      = data.GetNode(index, ItemAt.AtIndex).GetData();
                    Rhino.Geometry.Point3d currentRhinoNode = new Rhino.Geometry.Point3d();
                    currentRhinoNode.X = currentNode.X;
                    currentRhinoNode.Y = currentNode.Y;
                    currentRhinoNode.Z = currentNode.Z;

                    rhinoPointArray.Add(currentRhinoNode);
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // Releases interface to RFEM model.
            model = null;

            // Unlocks licence and releases interface to RFEM application.
            if (app != null)
            {
                app.UnlockLicense();
                app = null;
            }

            // Cleans Garbage Collector and releases all cached COM interfaces.
            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();

            ///the lines below outputs created RFEM nodes in output parameter
            ///current funcionality does not use this
            ///it uses a custom class (written within this project) RfemNodeType to wrap the Dlubal.RFEM5.Node objects.
            return(rhinoPointArray);
        }
Exemple #12
0
        /***************************************************/

        public static bool IsEqual(this BHG.Point bhPoint, RHG.Point3d rhPoint, double tolerance = BHG.Tolerance.Distance)
        {
            if (bhPoint == null & rhPoint == default(RHG.Point3d))
            {
                return(true);
            }

            return(Math.Abs(bhPoint.X - rhPoint.X) < tolerance &&
                   Math.Abs(bhPoint.Y - rhPoint.Y) < tolerance &&
                   Math.Abs(bhPoint.Z - rhPoint.Z) < tolerance);
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public PlatonicGetPoint(Rhino.Geometry.Brep[] faces, Rhino.Geometry.Point3d origin)
        {
            m_faces  = faces;
            m_origin = origin;

            m_length = 0.0;
            m_draw   = false;

            this.MouseMove   += new System.EventHandler <Rhino.Input.Custom.GetPointMouseEventArgs>(PlatonicGetPoint_MouseMove);
            this.DynamicDraw += new System.EventHandler <Rhino.Input.Custom.GetPointDrawEventArgs>(PlatonicGetPoint_DynamicDraw);
        }
Exemple #14
0
        public static RhinoNamespace.Geometry.Point3d[] ToRhinoPoint3dArray(double[,] data)
        {
            RhinoNamespace.Geometry.Point3d[] result = new RhinoNamespace.Geometry.Point3d[data.GetLength(0)];

            for (int i = 0; i < data.GetLength(0); i++)
            {
                result[i] = new RhinoNamespace.Geometry.Point3d(data[i, 0], data[i, 1], data[i, 2]);
            }

            return(result);
        }
Exemple #15
0
        public static bool TestIntersect(Mesh meshA, Mesh meshB, ref Point3d pt, bool fast = true)
        {
            bool meshInterects = false;

            bool bboxIntersection = TestBBIntersect(meshA, meshB);

            if (!bboxIntersection)
            {
                return(false); // if bounding boxes don't intersect then meshes don't interesect
            }
            Mesh largeMesh;
            Mesh smallMesh;

            if (meshA.Faces.Count > meshB.Faces.Count)
            {
                largeMesh = meshA;
                smallMesh = meshB;
            }
            else
            {
                largeMesh = meshB;
                smallMesh = meshA;
            }

            var scene = EmbreeTools.BuildScene(largeMesh);

            var meshVertices = smallMesh.Vertices.ToPoint3fArray();

            foreach (var face in smallMesh.Faces)
            {
                int numVertices = face.IsTriangle ? 3 : 4;
                for (int v = 0; v < numVertices; v++)
                {
                    var  ray    = RayFromVertices(meshVertices[face[v]], meshVertices[face[(v + 1) % numVertices]]);
                    var  packet = scene.Intersects(ray.Item1, 0, ray.Item2);
                    bool hit    = (packet.geomID != RTC.InvalidGeometryID);
                    if (hit)
                    {
                        meshInterects = true;
                        var intersect = packet.ToIntersection <Model>(scene);
                        var hitPos    = ray.Item1.PointAt(intersect.Distance);
                        pt = new Rhino.Geometry.Point3d(hitPos.X, hitPos.Y, hitPos.Z);
                        break;
                    }
                }
                if (meshInterects)
                {
                    break;
                }
            }

            return(meshInterects);
        }
Exemple #16
0
 /// <summary>
 /// Convert a Rhino point to a Nucleus vector.
 /// This will automatically be converted into the current Rhino units.
 /// </summary>
 /// <param name="point">The point to convert</param>
 /// <returns>A new vector with the same components as the Rhino one.
 /// If the point is invalid, Vector.Unset will be returned instead.</returns>
 public static Vector Convert(RC.Point3d point)
 {
     if (point.IsValid)
     {
         double f = ConversionFactor;
         return(new Vector(point.X * f, point.Y * f, point.Z * f));
     }
     else
     {
         return(Vector.Unset);
     }
 }
Exemple #17
0
        public static List <Rg.Polyline> TraceToRhino(this Bitmap input, double threshold, double alpha, double tolerance, int size, bool optimize, TurnModes mode)
        {
            List <List <Pt.Curve> > crvs      = new List <List <Pt.Curve> >();
            List <Rg.Polyline>      polylines = new List <Rg.Polyline>();
            int height = input.Height;

            Pt.Potrace.Clear();

            Pt.Potrace.turnpolicy = (Pt.TurnPolicy)mode;

            Pt.Potrace.curveoptimizing = optimize;

            Pt.Potrace.opttolerance = tolerance;
            Pt.Potrace.Treshold     = threshold;
            Pt.Potrace.alphamax     = alpha * 1.3334;

            Pt.Potrace.turdsize = size;

            Pt.Potrace.Potrace_Trace(input, crvs);

            foreach (var crvList in crvs)
            {
                Rg.Polyline polyline = new Rg.Polyline();
                polyline.Add(crvList[0].A.ToRhPoint(height));
                foreach (Pt.Curve curve in crvList)
                {
                    Rg.Point3d a = curve.ControlPointA.ToRhPoint(height);
                    Rg.Point3d b = curve.ControlPointB.ToRhPoint(height);
                    Rg.Point3d c = curve.B.ToRhPoint(height);

                    if (a != polyline[polyline.Count - 1])
                    {
                        polyline.Add(a);
                    }
                    if (b != a)
                    {
                        polyline.Add(b);
                    }
                    if (c != b)
                    {
                        polyline.Add(c);
                    }
                }
                if (!polyline.IsClosed)
                {
                    polyline.Add(crvList[0].A.ToRhPoint(height));
                }
                polylines.Add(polyline);
            }

            return(polylines);
        }
        //RhinoDoc doc;
        public static Rhino.Commands.Result AddCircle(Rhino.RhinoDoc doc)
        {
            Rhino.Geometry.Point3d center = new Rhino.Geometry.Point3d(0, 0, 0);
            const double           radius = 10.0;

            Rhino.Geometry.Circle c = new Rhino.Geometry.Circle(center, radius);
            if (doc.Objects.AddCircle(c) != Guid.Empty)
            {
                doc.Views.Redraw();
                return(Rhino.Commands.Result.Success);
            }
            return(Rhino.Commands.Result.Failure);
        }
Exemple #19
0
        private Brep CreateBrep(double size, double thickness)
        {
            Rhino.Geometry.Point3d center = new Rhino.Geometry.Point3d(0, 0, 0);
            Circle pessarySize            = new Circle(center, size);

            Plane[] perpFrame = pessarySize.ToNurbsCurve().GetPerpendicularFrames(new List <double> {
                0, 1, 2, 3
            });
            Circle pessaryThickness = new Circle(perpFrame[0], thickness);

            Brep[] b = Rhino.Geometry.Brep.CreateFromSweep(pessarySize.ToNurbsCurve(), pessaryThickness.ToNurbsCurve(), true, 0.01);

            return(b[0]);
        }
Exemple #20
0
        /// <summary> btnNewDwgPlane creates new drawing plane perpedicular to camera centered around chosed origin </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnNewDwgPlane_Click(object sender, EventArgs e)
        {
            Rhino.Geometry.Point3d pt1 = org;

            Rhino.Geometry.Transform move1 = Rhino.Geometry.Transform.Translation(view3.MainViewport.CameraX);
            Rhino.Geometry.Transform move2 = Rhino.Geometry.Transform.Translation(view3.MainViewport.CameraY);

            var xRev = view3.MainViewport.CameraX;
            var yRev = view3.MainViewport.CameraY;

            xRev.Reverse();
            yRev.Reverse();

            Rhino.Geometry.Transform move3 = Rhino.Geometry.Transform.Translation(xRev);
            Rhino.Geometry.Transform move4 = Rhino.Geometry.Transform.Translation(yRev);

            Rhino.Geometry.Point3d pt2 = org;
            Rhino.Geometry.Point3d pt3 = org;
            Rhino.Geometry.Point3d pt4 = org;
            Rhino.Geometry.Point3d pt5 = org;

            //Rhino.Geometry.Vector3d.l

            pt2.Transform(move1);
            pt2.Transform(move2);

            pt3.Transform(move3);
            pt3.Transform(move4);

            pt4.Transform(move1);
            pt4.Transform(move4);

            pt5.Transform(move3);
            pt5.Transform(move2);

            srf1   = Rhino.Geometry.NurbsSurface.CreateFromCorners(pt2, pt4, pt3, pt5);
            plane1 = new Plane(org, view3.MainViewport.CameraX, view3.MainViewport.CameraY);
            Rhino.Geometry.Transform scale1 = Rhino.Geometry.Transform.Scale(org, 400);
            srf1.Transform(scale1);

            mRhinoDoc.Objects.AddPoint(pt1);
            mRhinoDoc.Objects.AddPoint(pt2);
            mRhinoDoc.Objects.AddPoint(pt3);
            mRhinoDoc.Objects.AddPoint(pt4);
            mRhinoDoc.Objects.AddPoint(pt5);

            mRhinoDoc.Objects.AddSurface(srf1);

            mRhinoDoc.Views.Redraw();
        }
Exemple #21
0
        public static List <Rhino.Geometry.Point3d> RandomPt(Rectangle3d rect, int num)
        {
            var rtnList = new List <Rhino.Geometry.Point3d>();

            var myRandomGenerator = new Random();

            for (int k = 0; k < 10000; k++)
            {
                for (int i = 0; i < num; i++)
                {
                    double x = myRandomGenerator.NextDouble();
                    double y = myRandomGenerator.NextDouble();
                    double z = 0.0;

                    double rectMaxX = (rect.Center.X + (rect.Width / 2.0));
                    double rectMinX = (rect.Center.X - (rect.Width / 2.0));
                    double rectMaxY = (rect.Center.Y + (rect.Height / 2.0));
                    double rectMinY = (rect.Center.Y - (rect.Height / 2.0));

                    x = x.Remap(0.0, 1.0, rectMinX, rectMaxX);
                    y = y.Remap(0.0, 1.0, rectMinY, rectMaxY);
                    var myRandomPoint = new Rhino.Geometry.Point3d(x, y, z);
                    rtnList.Add(myRandomPoint);
                }

                int dupCount = 0;
                for (int j = 0; j < rtnList.Count; j++)
                {
                    var others = new List <Point3d>(rtnList);
                    others.RemoveAt(j);

                    if (others.Contains(rtnList[j]))
                    {
                        dupCount++;
                    }
                }

                if (dupCount == 0)
                {
                    return(rtnList);
                }
                else
                {
                    rtnList.Clear();
                }
            }
            return(rtnList);
        }
Exemple #22
0
        //TODO- check if the x,y axis of the plane will change whenever we call tryGetPlane
        //railPlaneSN-addRhinoObjSceneNode(draw on referece), curveOnObjRef-addRhinoObj(!=In3D)
        //drawPoint, strokeSN-addSceneNode, renderObjSN-updateSceneNode(Revolve or Curve2)
        public void resetVariables()
        {
            stroke_g     = new Geometry.GeometryStroke(ref mScene);
            currentState = State.READY;

            reducePoints = new List <Vector3>();

            targetPRhObjID = Guid.Empty;
            drawPoint      = null;
            snapPointSN    = null;
            projectP       = new Point3d();

            rhinoCurvePoints      = new List <Point3d>();
            rhinoCurve            = null;
            proj_plane            = new Plane();
            simplifiedCurvePoints = new List <Point3d>();
            simplifiedCurve       = null;
            editCurve             = null; //for extrude
            //curveOnObjRef = null;


            backgroundStart = false;
            displacement    = 0;
            dynamicBrep     = null;
            modelName       = "tprint";
            //dynamicRender = "none"; // need to save same as drawType and shapeType
            snapPointsList = new List <Point3d>();
            rayCastingObjs = new List <ObjRef>();


            toleranceMax = 100000;
            snapDistance = 40;
            isSnap       = false;
            shouldSnap   = false;

            moveControlerOrigin = new Point3d();
            movePlaneRef        = null;
            planeNormal         = new Rhino.Geometry.Vector3d();

            curvePlane    = new Plane();
            lastTranslate = 0.0f;
            d             = null;

            localListCurve  = mScene.iCurveList;
            oldCurveOnObjID = "";
            oldPlaneOrigin  = "";
            oldPlaneNormal  = "";
        }
Exemple #23
0
        public virtual Rhino.Display.Color4f GetColor(Rhino.Geometry.Point3d uvw, Rhino.Geometry.Vector3d duvwdx, Rhino.Geometry.Vector3d duvwdy)
        {
            if (m_runtime_serial_number > 0)
            {
                return(Rhino.Display.Color4f.Empty);
            }
            IntPtr pConstThis = ConstPointer();

            Rhino.Display.Color4f rc = new Rhino.Display.Color4f();

            if (!UnsafeNativeMethods.Rdk_TextureEvaluator_GetColor(pConstThis, uvw, duvwdx, duvwdy, ref rc))
            {
                return(Rhino.Display.Color4f.Empty);
            }
            return(rc);
        }
Exemple #24
0
            public EdgeSource(int[] attr_in, Hare.Geometry.Point PtZ0, Hare.Geometry.Point _PtZ, Vector[] _Tangents)
            {
                attr    = attr_in;
                Tangent = _Tangents;
                Z_Norm  = _PtZ - PtZ0;

                Z_Range   = Z_Norm.Length();
                Z_dot     = Z_Range * Z_Range;//Hare_math.Dot(Z_Norm, Z_Norm);
                Z_Norm   /= Z_Range;
                Z_Range_2 = Z_Range / 2;
                Z_mid     = (PtZ0 + _PtZ) / 2;
                Vector Bisector = (Tangent[0] + Tangent[1]) / 2;

                Bisector.Normalize();
                double BisectAngle = Math.Acos(Hare_math.Dot(Tangent[0], Bisector));

                if (BisectAngle == 0)
                {
                    BisectAngle = 1E-12;
                }
                v = new double[2] {
                    Math.PI / (2 * BisectAngle), Math.PI / (Utilities.Numerics.PiX2 - 2 * BisectAngle)
                };
                v_4pi = new double[2] {
                    v[0] / (4 * Math.PI), v[1] / (4 * Math.PI)
                };
                v_2pi = new double[2] {
                    v[0] / (2 * Math.PI), v[1] / (2 * Math.PI)
                };
                Normal[0] = Hare_math.Cross(_Tangents[0], Z_Norm);
                Normal[1] = Hare_math.Cross(_Tangents[1], Z_Norm * -1);

                if (Hare_math.Dot(Normal[0], Bisector) > 0)
                {
                    Normal[0] *= -1;
                    Normal[1] *= -1;
                }

                ////////////////////////////
                //VisCheck//
                Rhino.Geometry.Point3d pt = new Rhino.Geometry.Point3d(Z_mid.x, Z_mid.y, Z_mid.z);
                Rhino.RhinoDoc.ActiveDoc.Objects.AddLine(pt, pt + new Rhino.Geometry.Point3d(Normal[0].x, Normal[0].y, Normal[0].z));
                Rhino.RhinoDoc.ActiveDoc.Objects.AddLine(pt, pt + new Rhino.Geometry.Point3d(Normal[1].x, Normal[1].y, Normal[1].z));
                //Rhino.RhinoDoc.ActiveDoc.Objects.AddLine(pt, pt + new Rhino.Geometry.Point3d(Tangent[0].x, Tangent[0].y, Tangent[0].z));
                //Rhino.RhinoDoc.ActiveDoc.Objects.AddLine(pt, pt + new Rhino.Geometry.Point3d(Tangent[1].x, Tangent[1].y, Tangent[1].z));
                //////Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(new Rhino.Geometry.Point3d(Z_mid.x, Z_mid.y, Z_mid.z));
            }
        /// <summary>
        /// Transform calculator
        /// </summary>
        public bool CalculateTransform(Rhino.Display.RhinoViewport vp, Rhino.Geometry.Point3d pt, ref Rhino.Geometry.Transform xform)
        {
            bool rc = false;

            if (null == xform)
            {
                xform = new Rhino.Geometry.Transform();
            }
            xform = Rhino.Geometry.Transform.Identity;

            if (pt.IsValid)
            {
                Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(vp.ConstructionPlane())
                {
                    Origin = m_origin
                };

                Rhino.Geometry.Vector3d xaxis = (pt - plane.Origin);
                double length = xaxis.Length;

                if (length >= Rhino.RhinoMath.ZeroTolerance)
                {
                    Rhino.Geometry.Vector3d yaxis;
                    yaxis = 0 != xaxis.IsParallelTo(plane.Normal) ? plane.YAxis : Rhino.Geometry.Vector3d.CrossProduct(plane.Normal, xaxis);

                    plane = new Rhino.Geometry.Plane(plane.Origin, xaxis, yaxis);
                    if (!plane.IsValid)
                    {
                        return(rc);
                    }

                    Rhino.Geometry.Transform rotate_xform = Rhino.Geometry.Transform.PlaneToPlane(Rhino.Geometry.Plane.WorldXY, plane);
                    Rhino.Geometry.Transform scale_xform  = Rhino.Geometry.Transform.Scale(plane, length, length, length);

                    xform = scale_xform * rotate_xform;
                    rc    = xform.IsValid;

                    if (rc)
                    {
                        m_length = length;
                    }
                }
            }

            return(rc);
        }
Exemple #26
0
 public PlaneConverter(Vector3DConverter vecConv, Point3dConverter ptConv) :
     base(
         (rhp) =>
 {
     pp.Vec origin = ptConv.ToPipe <rh.Point3d, pp.Vec>(rhp.Origin);
     pp.Vec x      = vecConv.ToPipe <rh.Vector3d, pp.Vec>(rhp.XAxis);
     pp.Vec y      = vecConv.ToPipe <rh.Vector3d, pp.Vec>(rhp.YAxis);
     //we won't convert the z-axis because we can simply cross the x and y
     return(new pp.Plane(origin, x, y));
 },
         (ppp) =>
 {
     rh.Point3d origin = ptConv.FromPipe <rh.Point3d, pp.Vec>(ppp.Origin);
     rh.Vector3d x     = vecConv.FromPipe <rh.Vector3d, pp.Vec>(ppp.X);
     rh.Vector3d y     = vecConv.FromPipe <rh.Vector3d, pp.Vec>(ppp.Y);
     return(new rh.Plane(origin, x, y));
 }
         ) { }
Exemple #27
0
        public void OnObjectAdded(RhinoObjectEventArgs ea)
        {
            bool sendBool = utils.properties.getPushState();

            if (sendBool == false)
            {
                //Do nothing.
            }
            else if (sendBool == true)
            {
                //debug.alert("Addition event!");

                //Check if change being processed is the docbox.
                string docBoxID = utils.properties.tryGetDocBox();
                if (ea.ObjectId.ToString() == docBoxID)
                {
                    //Cache reference point.
                    Rhino.Geometry.Point3d refPoint = utils.properties.getRefPoint();

                    string D20_Path = utils.file_structure.getPathFor("D20");
                    System.IO.File.WriteAllText(D20_Path, refPoint.X.ToString() + "," + refPoint.Y.ToString());

                    outbound.push.docBoxChanges(ea.TheObject);
                }
                else
                {
                    string G00_Path = utils.file_structure.getPathFor("G00");
                    if (System.IO.File.Exists(G00_Path) == false)
                    {
                        System.IO.File.WriteAllText(G00_Path, "1");
                    }

                    //Verify object to parse is a curve before translating.
                    if (ea.TheObject.Geometry.ObjectType.ToString().ToLower().Contains("curve"))
                    {
                        outbound.translate.curves(1, ea.TheObject);
                    }
                    else
                    {
                        //Added object is not a curve, do nothing.
                    }
                }
            }
        }
Exemple #28
0
        private static void NegativeNearClippingHelper(double near_dist, double far_dist, ViewportInfo vp)
        {
            double n = near_dist;
            double f = far_dist;

            double min_near_dist = 0.000100;

            if (double.IsNaN(min_near_dist) || min_near_dist < 1.0e-6)
            {
                min_near_dist = 1.0e-6;
            }
            if (vp.IsParallelProjection && n < min_near_dist)
            {
                // move camera back in ortho projection so everything shows
                double d = 1.00001 * min_near_dist - n;
                if (d < 0.005)
                {
                    d = 0.005;
                }
                n += d;
                f += d;
                if (double.IsNaN(d) ||
                    d <= 0.0 ||
                    double.IsNaN(n) ||
                    double.IsNaN(f) ||
                    n < min_near_dist ||
                    f <= n
                    )
                {
                    // Just give up but ... refuse to accept garbage
                    n = 0.005;
                    f = 1000.0;
                }
                else
                {
                    Rhino.Geometry.Point3d new_loc = vp.CameraLocation + d * vp.CameraZ;
                    vp.SetCameraLocation(new_loc);
                }
                near_dist = n;
                far_dist  = f;
            }
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Rhino.Geometry.Point3d pt = Rhino.Geometry.Point3d.Unset;

            //create a variable to store the points
            List <Point3d> inputPts = new List <Point3d>();

            List <Point3d> inputPoints = new List <Point3d>();

            if ((!DA.GetDataList(0, inputPts)))
            {
                return;
            }



            if (inputPts.Count < 3)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "You need at least 3 points");
            }
            else if (AreThereErrors(inputPoints) == true)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "ERROR - There are some duplicates");
            }
            else
            {
            }

            for (int i = 0; i < inputPts.Count - 1; i++)
            {
                inputPoints.Add(inputPts[i]);
            }

            //if you do not have any errors calculate the polyline
            Polyline resCH = ConvexHull.CalculateCH(inputPoints);

            //create an output messge to inform the user
            String outMessage = "Congrats you have  drawn a polyline around your points " + inputPoints.Count;

            DA.SetData(0, resCH);
            DA.SetData(1, outMessage);
        }
Exemple #30
0
        /***************************************************/

        private static int AddVertex(this RHG.Brep brep, RHG.Point3d point)
        {
            int id = -1;

            for (int j = 0; j < brep.Vertices.Count; j++)
            {
                if (point.DistanceTo(brep.Vertices[j].Location) <= BHG.Tolerance.Distance)
                {
                    id = j;
                    break;
                }
            }

            if (id == -1)
            {
                brep.Vertices.Add(point, BHG.Tolerance.Distance);
                id = brep.Vertices.Count - 1;
            }

            return(id);
        }
            public EdgeSource(int[] attr_in, Hare.Geometry.Point PtZ0, Hare.Geometry.Point _PtZ, Vector[] _Tangents)
            {
                attr = attr_in;
                Tangent = _Tangents;
                Z_Norm = _PtZ - PtZ0;

                Z_Range = Z_Norm.Length();
                Z_dot = Z_Range * Z_Range;//Hare_math.Dot(Z_Norm, Z_Norm);
                Z_Norm/= Z_Range;
                Z_Range_2 = Z_Range / 2;
                Z_mid = (PtZ0 + _PtZ) / 2;
                Vector Bisector = (Tangent[0] + Tangent[1])/2;
                Bisector.Normalize();
                double BisectAngle = Math.Acos(Hare_math.Dot(Tangent[0], Bisector));
                if (BisectAngle == 0) BisectAngle = 1E-12;
                v = new double[2] { Math.PI / (2 * BisectAngle), Math.PI / (Utilities.Numerics.PiX2 - 2 * BisectAngle) };
                v_4pi = new double[2] { v[0] / (4 * Math.PI), v[1] / (4 * Math.PI) };
                v_2pi = new double[2] { v[0] / (2 * Math.PI), v[1] / (2 * Math.PI) };
                Normal[0] = Hare_math.Cross(_Tangents[0], Z_Norm);
                Normal[1] = Hare_math.Cross(_Tangents[1], Z_Norm*-1);

                if(Hare_math.Dot(Normal[0], Bisector) > 0)
                {
                    Normal[0] *= -1;
                    Normal[1] *= -1;
                }
                
                ////////////////////////////
                //VisCheck//
                Rhino.Geometry.Point3d pt = new Rhino.Geometry.Point3d(Z_mid.x, Z_mid.y, Z_mid.z);
                Rhino.RhinoDoc.ActiveDoc.Objects.AddLine(pt, pt + new Rhino.Geometry.Point3d(Normal[0].x, Normal[0].y, Normal[0].z));
                Rhino.RhinoDoc.ActiveDoc.Objects.AddLine(pt, pt + new Rhino.Geometry.Point3d(Normal[1].x, Normal[1].y, Normal[1].z));
                //Rhino.RhinoDoc.ActiveDoc.Objects.AddLine(pt, pt + new Rhino.Geometry.Point3d(Tangent[0].x, Tangent[0].y, Tangent[0].z));
                //Rhino.RhinoDoc.ActiveDoc.Objects.AddLine(pt, pt + new Rhino.Geometry.Point3d(Tangent[1].x, Tangent[1].y, Tangent[1].z));
                //////Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(new Rhino.Geometry.Point3d(Z_mid.x, Z_mid.y, Z_mid.z));
            }
 /// <summary>
 /// Gets the corners of far clipping plane rectangle.
 /// 4 points are returned in the order of bottom left, bottom right,
 /// top left, top right.
 /// </summary>
 /// <returns>
 /// Four corner points on success.
 /// Empty array if viewport is not valid.
 /// </returns>
 public Rhino.Geometry.Point3d[] GetFarPlaneCorners()
 {
   Rhino.Geometry.Point3d leftBottom = new Rhino.Geometry.Point3d();
   Rhino.Geometry.Point3d rightBottom = new Rhino.Geometry.Point3d();
   Rhino.Geometry.Point3d leftTop = new Rhino.Geometry.Point3d();
   Rhino.Geometry.Point3d rightTop = new Rhino.Geometry.Point3d();
   IntPtr pConstThis = ConstPointer();
   if (!UnsafeNativeMethods.ON_Viewport_GetNearFarRect(pConstThis, false, ref leftBottom, ref rightBottom, ref leftTop, ref rightTop))
     return new Rhino.Geometry.Point3d[0];
   return new Rhino.Geometry.Point3d[] { leftBottom, rightBottom, leftTop, rightTop };
 }
 /// <summary>
 /// Gets location and vectors of this camera.
 /// </summary>
 /// <param name="location">An out parameter that will be filled with a point during the call.</param>
 /// <param name="cameraX">An out parameter that will be filled with the X vector during the call.</param>
 /// <param name="cameraY">An out parameter that will be filled with the Y vector during the call.</param>
 /// <param name="cameraZ">An out parameter that will be filled with the Z vector during the call.</param>
 /// <returns>true if current camera orientation is valid; otherwise false.</returns>
 public bool GetCameraFrame(out Rhino.Geometry.Point3d location,  out Rhino.Geometry.Vector3d cameraX, out Rhino.Geometry.Vector3d cameraY, out Rhino.Geometry.Vector3d cameraZ)
 {
   location = new Rhino.Geometry.Point3d(0, 0, 0);
   cameraX = new Rhino.Geometry.Vector3d(0, 0, 0);
   cameraY = new Rhino.Geometry.Vector3d(0, 0, 0);
   cameraZ = new Rhino.Geometry.Vector3d(0, 0, 0);
   IntPtr pConstThis = ConstPointer();
   return UnsafeNativeMethods.ON_Viewport_GetCameraFrame(pConstThis, ref location, ref cameraX, ref cameraY, ref cameraZ);
 }
 /// <summary> Add a user determined point object and add point in Rhino space </summary>
 /// <returns> Rhino Point 3D </returns>
 public Rhino.Commands.Result selectPoint()
 {
     Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
     gp.SetCommandPrompt("Drawing plane origin");
     gp.Get();
     org = gp.Point();
     mRhinoDoc.Objects.AddPoint(org);
     mRhinoDoc.Views.Redraw();
     return Rhino.Commands.Result.Success;
 }
Exemple #35
0
    protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
    {
        init();
            _listSrf = new List<Surface>();
            _listCrv = new List<Curve>();
            listPnt = new List<Point3d>();
            List<string> crvTypes = new List<string>();
            List<string> pntHeights = new List<string>();
            if (!DA.GetDataList(0, _listSrf)) { return; }
            if (!DA.GetDataList(1, _listCrv)) { return; }
            if (!DA.GetDataList(2, crvTypes)) { return; }
            if (!DA.GetDataList(3, listPnt)) { listPnt.Clear(); }
            if (!DA.GetData(4, ref globalC)) { return; }

            if (_listCrv.Count != crvTypes.Count) { AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "need types for curves"); return; }

            listSlice = new Dictionary<string, slice>();
            listSlice2 = new Dictionary<string, slice2>();
            listRange = new Dictionary<string, range>();
            listRangeOpen = new Dictionary<string, range>();
            listRangeLeaf = new Dictionary<string, range>();
            listLeaf = new List<leaf>();
            listBranch = new List<branch>();
            listNode=new List<node>();
            myControlBox.clearSliders();
            for (int i = 0; i < _listCrv.Count; i++)
            {
                var branch = new branch();
                branch.crv = _listCrv[i] as NurbsCurve;
                branch.N = branch.crv.Points.Count;
                branch.dom = branch.crv.Domain;
                branch.Dim= branch.crv.Order;
                branch.dDim = branch.crv.Order - 1;
                branch.nElem = branch.N - branch.dDim;
                branch.scaleT = (branch.dom.T1 - branch.dom.T0) / branch.nElem;
                branch.originT = branch.dom.T0;
                if(crvTypes[i].StartsWith("reinforce"))
                {
                    branch.branchType = branch.type.reinforce;
                    var key=crvTypes[i].Replace("reinforce","");
                    branch.sliceKey=key;
                    try{
                        branch.slice=listSlice[key];
                        branch.slice.sliceType = slice.type.fr;
                        branch.slice.lB.Add(branch);
                    }
                    catch (KeyNotFoundException e){
                        listSlice[key]=new slice();
                        branch.slice=listSlice[key];
                        branch.slice.sliceType=slice.type.fr;
                        branch.slice.lB.Add(branch);
                    }
                }
                else if(crvTypes[i].StartsWith("kink"))
                {
                    branch.branchType = branch.type.kink;
                    var key = crvTypes[i].Replace("kink", "");
                    if (key == "") key = "kink"; else key = "kink:" + key;
                    branch.sliceKey = key;
                    try
                    {
                        branch.range = listRange[key];
                        branch.range.rangeType = range.type.lo;
                        branch.range.lb = 0;
                        branch.range.ub = 0;
                        branch.range.lB.Add(branch);

                    }
                    catch (KeyNotFoundException)
                    {
                        listRange[key] = new range();
                        branch.range = listRange[key];
                        branch.range.rangeType = range.type.lo;
                        branch.range.lb = 0;
                        branch.range.ub = 0;
                        branch.range.lB.Add(branch);
                        var adjuster = myControlBox.addRangeSetter(key, (th,sw, lb, ub) =>
                        {
                            if (listRange[key].firstPathDone)
                            {
                                th.setMeasured(listRange[key].lastMin,listRange[key].lastMax);
                            }
                            foreach (var _branch in listRange[key].lB)
                            {
                                if (sw == 0)
                                {
                                    _branch.range.rangeType = range.type.lo;
                                    _branch.range.lb = lb;
                                    _branch.range.ub = 0d;
                                }
                                if (sw == 2)
                                {
                                    _branch.range.rangeType = range.type.ra;
                                    _branch.range.lb = lb;
                                    _branch.range.ub = ub;
                                }
                            }
                        }
                         );
                    }

                }else if(crvTypes[i].StartsWith("open"))
                {
                    branch.branchType = branch.type.open;
                    var key = crvTypes[i].Replace("open", "");
                    if (key == "") key = "open"; else key = "open:" + key;
                    branch.sliceKey = key;
                    try
                    {
                        branch.slice = listSlice[key];
                        branch.slice.sliceType = slice.type.fr;
                        branch.slice.lB.Add(branch);
                    }
                    catch (KeyNotFoundException e)
                    {
                        listSlice[key] = new slice();
                        branch.slice = listSlice[key];
                        branch.slice.sliceType = slice.type.fr;
                        branch.slice.lB.Add(branch);
                    }
                    try
                    {
                        branch.range = listRangeOpen[key];
                        branch.range.rangeType = range.type.lo;
                        branch.range.lb = 0;
                        branch.range.ub = 0;
                        branch.range.lB.Add(branch);
                    }
                    catch (KeyNotFoundException)
                    {
                        listRangeOpen[key] = new range();
                        branch.range = listRangeOpen[key];
                        branch.range.rangeType = range.type.lo;
                        branch.range.lb = 0;
                        branch.range.ub = 0;
                        branch.range.lB.Add(branch);
                        var adjuster = myControlBox.addRangeSetter(key, (th,sw, lb, ub) =>
                        {
                            if (listRangeOpen[key].firstPathDone)
                            {
                                th.setMeasured(listRangeOpen[key].lastMin,listRangeOpen[key].lastMax);
                            }
                            foreach (var _branch in listRangeOpen[key].lB)
                            {
                                if (sw == 0)
                                {
                                    _branch.range.rangeType = range.type.lo;
                                    _branch.range.lb = lb;
                                    _branch.range.ub = 0d;
                                }
                                if (sw == 2)
                                {
                                    _branch.range.rangeType = range.type.ra;
                                    _branch.range.lb = lb;
                                    _branch.range.ub = ub;
                                }
                            }
                        }
                            );
                    }
                }
                else if (crvTypes[i].StartsWith("fix"))
                {
                    branch.branchType = branch.type.fix;
                    var key = crvTypes[i].Replace("fix", "");
                    branch.sliceKey = key;
                    try
                    {
                        branch.slice2 = listSlice2[key];
                    }
                    catch (KeyNotFoundException e)
                    {
                        listSlice2[key] = new slice2();
                        branch.slice2 = listSlice2[key];

                        var slider = myControlBox.addSliderVert(0, 1, 200, 100);
                        slider.Converter = (val) =>
                            {
                                double height = val / 10d - 10d;
                                branch.slice2.height = height;
                                this.ExpirePreview(true);
                                return height;
                            };
                    }
                }else{
                        AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "type should be either of reinforce, kink, fix, or open");
                }
                listBranch.Add(branch);
            }

            for(int i=0;i<_listSrf.Count;i++)
            {
                var srf = _listSrf[i];
                var leaf=new leaf();
                listLeaf.Add(leaf);
                leaf.srf = srf as NurbsSurface;
                leaf.nU = leaf.srf.Points.CountU;
                leaf.nV = leaf.srf.Points.CountV;
                leaf.domU = leaf.srf.Domain(0);
                leaf.domV = leaf.srf.Domain(1);
                leaf.uDim = leaf.srf.OrderU;
                leaf.vDim = leaf.srf.OrderV;
                leaf.uDdim = leaf.srf.OrderU - 1;
                leaf.vDdim = leaf.srf.OrderV - 1;
                leaf.nUelem = leaf.nU - leaf.uDdim;
                leaf.nVelem = leaf.nV - leaf.vDdim;
                leaf.scaleU = (leaf.domU.T1 - leaf.domU.T0) / leaf.nUelem;
                leaf.scaleV = (leaf.domV.T1 - leaf.domV.T0) / leaf.nVelem;
                leaf.originU = leaf.domU.T0;
                leaf.originV = leaf.domV.T0;
                var domainU = leaf.srf.Domain(0);
                var domainV = leaf.srf.Domain(1);
                //Find corresponding curve
                //(0,0)->(1,0)
                var curve = leaf.srf.IsoCurve(0, domainV.T0) as NurbsCurve;
                leaf.flip[0] = findCurve(leaf,ref leaf.branch[0], listBranch, curve);//bottom
                //(1,0)->(1,1)
                curve = leaf.srf.IsoCurve(1, domainU.T1) as NurbsCurve;
                leaf.flip[1] = findCurve(leaf, ref leaf.branch[1], listBranch, curve);//right
                //(1,1)->(0,1)
                curve = leaf.srf.IsoCurve(0, domainV.T1) as NurbsCurve;
                leaf.flip[2] = findCurve(leaf, ref leaf.branch[2], listBranch, curve);//top
                //(0,1)->(0,0)
                curve = leaf.srf.IsoCurve(1, domainU.T0) as NurbsCurve;
                leaf.flip[3] = findCurve(leaf, ref leaf.branch[3], listBranch, curve);//left

                var key = "leaf";
                try
                {
                    leaf.range = listRangeLeaf[key];
                    leaf.range.rangeType = range.type.lo;
                    leaf.range.lb = 0;
                    leaf.range.ub = 0;
                    leaf.range.lL.Add(leaf);
                }
                catch (KeyNotFoundException)
                {
                    listRangeLeaf[key] = new range();
                    leaf.range = listRangeLeaf[key];
                    leaf.range.rangeType = range.type.lo;
                    leaf.range.lb = 0;
                    leaf.range.ub = 0;
                    leaf.range.lL.Add(leaf);
                    var adjuster = myControlBox.addRangeSetter(key, (th, sw, lb, ub) =>
                    {
                        if (listRangeLeaf[key].firstPathDone)
                        {
                            th.setMeasured(listRangeLeaf[key].lastMin, listRangeLeaf[key].lastMax);
                        }
                        foreach (var _leaf in listRangeLeaf[key].lL)
                        {
                            if (sw == 0)
                            {
                                _leaf.range.rangeType = range.type.lo;
                                _leaf.range.lb = lb;
                                _leaf.range.ub = 0d;
                            }
                            if (sw == 2)
                            {
                                _leaf.range.rangeType = range.type.ra;
                                _leaf.range.lb = lb;
                                _leaf.range.ub = ub;
                            }
                        }
                    }
                     );
                }

            }
            // Connect nodes
            foreach (var leaf in listLeaf)
            {
                leaf.globalIndex = new int[leaf.srf.Points.CountU * leaf.srf.Points.CountV];
                for (int j = 0; j < leaf.srf.Points.CountV; j++)
                {
                    for (int i = 0; i < leaf.srf.Points.CountU; i++)
                    {
                        var P = leaf.srf.Points.GetControlPoint(i, j).Location;
                        bool flag = false;
                        foreach (var node in listNode)
                        {
                            if (node.compare(P))
                            {
                                flag = true;
                                node.N++;
                                node.shareL.Add(leaf);
                                node.numberL.Add(i + j * leaf.nU);
                                leaf.globalIndex[i + j * leaf.nU] = listNode.IndexOf(node);
                                break;
                            }
                        }
                        if (!flag)
                        {
                            var newNode = new node();
                            listNode.Add(newNode);
                            newNode.N = 1;
                            newNode.x = P.X;
                            newNode.y = P.Y;
                            newNode.z = P.Z;
                            newNode.shareL.Add(leaf);
                            newNode.numberL.Add(i + j * leaf.nU);
                            leaf.globalIndex[i + j * leaf.nU] = listNode.IndexOf(newNode);
                        }
                    }
                }
            }
            foreach (var branch in listBranch)
            {
                branch.globalIndex = new int[branch.crv.Points.Count];
                for (int i = 0; i < branch.crv.Points.Count; i++)
                {
                    var P = branch.crv.Points[i].Location;
                    bool flag = false;
                    foreach (var node in listNode)
                    {
                        if (node.compare(P))
                        {
                            flag = true;
                            node.N++;
                            node.shareB.Add(branch);
                            node.numberB.Add(i);
                            if (branch.branchType == branch.type.fix)
                            {
                                node.nodeType = node.type.fx;
                            }
                            branch.globalIndex[i] = listNode.IndexOf(node);
                            break;
                        }
                    }
                    if (!flag)
                    {
                        var newNode = new node();
                        listNode.Add(newNode);
                        newNode.N = 1;
                        newNode.shareB.Add(branch);
                        newNode.numberB.Add(i);
                        newNode.x = P.X;
                        newNode.y = P.Y;
                        newNode.z = P.Z;
                        if (branch.branchType == branch.type.fix)
                        {
                            newNode.nodeType = node.type.fx;
                        }
                        branch.globalIndex[i] = listNode.IndexOf(newNode);
                    }
                }
            }
            //multiqudric surface
            var A=new Rhino.Geometry.Matrix(listPnt.Count,listPnt.Count);
            var z=new Rhino.Geometry.Matrix(listPnt.Count,1);
            for(int i=0;i<listPnt.Count;i++)
            {
                for(int j=0;j<listPnt.Count;j++)
                {
                    var pi=listPnt[i];
                    var pj=listPnt[j];
                    A[i,j]=quadFunc(pi.X,pj.X,pi.Y,pj.Y);
                    z[i,0]=pi.Z;
                }
            }
            A.Invert(0.0);  //this parameter should be 0.0
            var c=A*z;
            globalCoeff=new double[listPnt.Count];
            for(int i=0;i<listPnt.Count;i++)
            {
                globalCoeff[i]=c[i,0];
            }
            targetSrf=new List<Point3d>();
            globalFunc=(xi,yi)=>{
                double Z=0;
                for(int j=0;j<listPnt.Count;j++)
                {
                    Z=Z+globalCoeff[j]*quadFunc(xi,listPnt[j].X,yi,listPnt[j].Y);
                }
                return Z;
                };
            foreach (var leaf in listLeaf)
            {
                var domU = leaf.domU;
                var domV = leaf.domV;
                for (double i = 0; i <= 1.0; i += 0.05)
                {
                    for (double j = 0; j < 1.0; j += 0.05)
                    {
                        double u = domU[0] + i * (domU[1] - domU[0]);
                        double v = domV[0] + j * (domV[1] - domV[0]);
                        Rhino.Geometry.Point3d P;
                        Rhino.Geometry.Vector3d[] V;
                        leaf.srf.Evaluate(u, v, 0, out P, out V);
                        var newP = new Rhino.Geometry.Point3d(P.X, P.Y, globalFunc(P.X, P.Y));
                        targetSrf.Add(newP);
                    }
                }
            }
    }