コード例 #1
0
        static public bool CreateSections(Rhino.RhinoDoc doc, Rhino.Geometry.GeometryBase geo, Rhino.Geometry.Surface surfaceB, Rhino.Geometry.Curve curve, double interval, ref List <PlanePoint> points)
        {
            Rhino.Geometry.Interval domain = curve.Domain;  // fixed issue
            for (double t = domain.T0; t < domain.T1; t += interval)
            {
                Rhino.Geometry.Point3d  pt        = curve.PointAt(t);
                Rhino.Geometry.Vector3d tangent   = curve.TangentAt(t);
                Rhino.Geometry.Vector3d curvature = curve.CurvatureAt(t);
                Rhino.Geometry.Plane    plane     = new Rhino.Geometry.Plane();
                curve.FrameAt(t, out plane);

                doc.Objects.AddPoint(pt);
                curvature = curvature * 10.0;
                Rhino.Geometry.Line line = new Rhino.Geometry.Line(pt, curvature);
                doc.Objects.AddLine(line);
                RhinoApp.WriteLine("Curve at {0}", t);

                Rhino.Geometry.Vector3d normal = new Rhino.Geometry.Vector3d();

                bool ret = false;
                if (geo is Rhino.Geometry.Brep)
                {
                    Rhino.Geometry.Brep brepA = (Rhino.Geometry.Brep)geo;
                    ret = GetNormalVector(brepA, pt, ref normal);
                    RhinoApp.WriteLine("   Added Brep point at ({0}, {0}, {0})", pt.X, pt.Y, pt.Z);
                }
                else if (geo is Rhino.Geometry.Surface)
                {
                    Rhino.Geometry.Surface surfaceA = (Rhino.Geometry.Surface)geo;
                    ret = GetNormalVector(surfaceA, pt, ref normal);
                    RhinoApp.WriteLine("   Added surface point at ({0}, {0}, {0})", pt.X, pt.Y, pt.Z);
                }

                if (ret)
                {
                    Rhino.Geometry.Vector3d ucoord = CrossProduct(tangent, normal);
                    Rhino.Geometry.Plane    plane2 = new Rhino.Geometry.Plane(pt, ucoord, tangent); // normal);
                    double[] parameters            = plane2.GetPlaneEquation();

                    PlanePoint PlanePoint = new PlanePoint();
                    PlanePoint.pt        = pt;
                    PlanePoint.A         = parameters[0];
                    PlanePoint.B         = parameters[1];
                    PlanePoint.C         = parameters[2];
                    PlanePoint.D         = parameters[3];
                    PlanePoint.curvature = curvature;
                    points.Add(PlanePoint);

                    Rhino.Geometry.Interval     Interval1    = new Rhino.Geometry.Interval(-0.1, -0.1);
                    Rhino.Geometry.Interval     Interval2    = new Rhino.Geometry.Interval(0.1, 0.1);
                    Rhino.Geometry.PlaneSurface PlaneSurface = new Rhino.Geometry.PlaneSurface(plane2, Interval1, Interval2);
                    doc.Objects.AddSurface(PlaneSurface);
                }
            }
            return(true);
        }
コード例 #2
0
        public bool Plane(int index, ref Rhino.Geometry.PlaneSurface plane)
        {
            Rhino.Geometry.Point3d  origin = new Rhino.Geometry.Point3d();
            Rhino.Geometry.Vector3d xaxis = new Rhino.Geometry.Vector3d();
            Rhino.Geometry.Vector3d yaxis = new Rhino.Geometry.Vector3d();
            double minX = 0.0, maxX = 0.0;
            double minY = 0.0, maxY = 0.0;

            if (UnsafeNativeMethods.Rdk_CustomMeshes_Plane(ConstPointer(), index, ref origin, ref xaxis, ref yaxis, ref minX, ref maxX, ref minY, ref maxY))
            {
                plane = new Rhino.Geometry.PlaneSurface(new Rhino.Geometry.Plane(origin, xaxis, yaxis),
                                                        new Rhino.Geometry.Interval(minX, maxX),
                                                        new Rhino.Geometry.Interval(minY, maxY));
                return(true);
            }
            return(false);
        }
コード例 #3
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.Geometry.Point3d[] corners;
            Result rc = Rhino.Input.RhinoGet.GetRectangle(out corners);

            if (rc != Result.Success)
            {
                return(rc);
            }

            Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(corners[0], corners[1], corners[2]);

            Rhino.Geometry.PlaneSurface plane_surface = new Rhino.Geometry.PlaneSurface(
                plane,
                new Rhino.Geometry.Interval(0, corners[0].DistanceTo(corners[1])),
                new Rhino.Geometry.Interval(0, corners[1].DistanceTo(corners[2]))
                );

            rc = Result.Cancel;
            if (plane_surface.IsValid)
            {
                string layer_name = doc.Layers.GetUnusedLayerName(true);
                rc = Rhino.Input.RhinoGet.GetString("Name of layer to create", true, ref layer_name);
                if (rc == Result.Success && !string.IsNullOrEmpty(layer_name))
                {
                    int layer_index = doc.Layers.FindByFullPath(layer_name, true);
                    if (-1 == layer_index)
                    {
                        layer_index = doc.Layers.Add(layer_name, System.Drawing.Color.Black);
                    }

                    if (layer_index >= 0)
                    {
                        Rhino.DocObjects.ObjectAttributes attribs = doc.CreateDefaultAttributes();
                        attribs.LayerIndex = layer_index;
                        attribs.Name       = layer_name;
                        doc.Objects.AddSurface(plane_surface, attribs);
                        doc.Views.Redraw();
                        rc = Result.Success;
                    }
                }
            }

            return(rc);
        }
コード例 #4
0
ファイル: Hill.cs プロジェクト: mikity-mikity/RicecookerV3
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            List <GH_hill> listHill = new List <GH_hill>();
            int            uMax = 0, vMax = 0;
            double         size = 0.0;

            if (!DA.GetDataList(0, listHill))
            {
                return;
            }
            if (!DA.GetData(1, ref size))
            {
                return;
            }
            if (!DA.GetData(2, ref uMax))
            {
                return;
            }
            if (!DA.GetData(3, ref vMax))
            {
                return;
            }
            double ContourInterval = 0.01 * listHill[0].Value.h;
            double seaLevel        = 30.0 * ContourInterval;

            double c      = size / uMax;
            double otherc = size / vMax;

            if (c > otherc)
            {
                c = otherc;
            }
            double maxX = c * uMax / 2d;
            double maxY = c * vMax / 2d;

            GH_function newFunction = new GH_function();

            newFunction.Value      = new function();
            newFunction.Value.Func = new _function((xValue, yValue) => {
                res f          = new res();
                double z       = -seaLevel;
                double zDiff_X = 0;
                double zDiff_Y = 0;
                double dx      = 0;
                double dy      = 0;
                for (int hill = 0; hill < listHill.Count; hill++)
                {
                    dx = xValue - listHill[hill].Value.x;
                    dy = yValue - listHill[hill].Value.y;
                    double expThingy = listHill[hill].Value.h * Math.Exp(-(dx * dx + dy * dy) / (listHill[hill].Value.size * listHill[hill].Value.size));
                    z       += expThingy;
                    zDiff_X -= dx * expThingy / (listHill[hill].Value.size * listHill[hill].Value.size);
                    zDiff_Y -= dy * expThingy / (listHill[hill].Value.size * listHill[hill].Value.size);
                }
                f.z      = z;
                f.zDiffX = zDiff_X;
                f.zDiffY = zDiff_Y;

                return(f);
            });
            Rhino.Geometry.PointCloud pc = new Rhino.Geometry.PointCloud();

            for (int i = 0; i <= uMax * 4; i++)
            {
                for (int j = 0; j <= vMax * 4; j++)
                {
                    double x = -maxX + (c / 4d) * i;
                    double y = -maxY + (c / 4d) * j;
                    pc.Add(new Rhino.Geometry.Point3d(x, y, newFunction.Value.Func(x, y).z));
                }
            }
            Rhino.Geometry.Plane        plane     = new Rhino.Geometry.Plane(new Rhino.Geometry.Point3d(0, 0, 0), new Rhino.Geometry.Vector3d(1.0, 0, 0), new Rhino.Geometry.Vector3d(0.0, 1.0, 0));
            Rhino.Geometry.PlaneSurface planeSurf = new Rhino.Geometry.PlaneSurface(plane, new Rhino.Geometry.Interval(-size / 2d * 1.2d, size / 2d * 1.2d), new Rhino.Geometry.Interval(-size / 2d * 1.2d, size / 2d * 1.2d));
            DA.SetDataList(0, pc.GetPoints().ToList());
            DA.SetData(1, planeSurf);
            newFunction.size            = size;
            newFunction.uMax            = uMax;
            newFunction.vMax            = vMax;
            newFunction.maxX            = maxX;
            newFunction.maxY            = maxY;
            newFunction.c               = c;
            newFunction.seaLevel        = seaLevel;
            newFunction.ContourInterval = ContourInterval;
            newFunction.a               = c * (Math.Sqrt(7.0) - 1.0) / 6.0;
            newFunction.bsin            = c / 4.0;
            newFunction.bcos            = c * (4.0 - Math.Sqrt(7.0)) / 12.0;
            DA.SetData(2, newFunction);
        }
コード例 #5
0
 public void Add(Rhino.Geometry.PlaneSurface plane, RenderMaterial material)
 {
     UnsafeNativeMethods.Rdk_CustomMeshes_AddPlane(NonConstPointer(), plane.ConstPointer(), material.ConstPointer());
 }
コード例 #6
0
    public bool Plane(int index, ref Rhino.Geometry.PlaneSurface plane)
    {
      Rhino.Geometry.Point3d origin = new Rhino.Geometry.Point3d();
      Rhino.Geometry.Vector3d xaxis = new Rhino.Geometry.Vector3d();
      Rhino.Geometry.Vector3d yaxis = new Rhino.Geometry.Vector3d();
      double minX = 0.0, maxX = 0.0;
      double minY = 0.0, maxY = 0.0;

      if (UnsafeNativeMethods.Rdk_CustomMeshes_Plane(ConstPointer(), index, ref origin, ref xaxis, ref yaxis, ref minX, ref maxX, ref minY, ref maxY))
      {
        plane = new Rhino.Geometry.PlaneSurface(new Rhino.Geometry.Plane(origin, xaxis, yaxis),
                                                        new Rhino.Geometry.Interval(minX, maxX),
                                                        new Rhino.Geometry.Interval(minY, maxY));
        return true;
      }
      return false;
    }