コード例 #1
0
 public double areaTri(Point3d p1, Point3d p2, Point3d p3)
 {
     double a = p1.DistanceTo(p2);
     double b = p1.DistanceTo(p3);
     double c = p2.DistanceTo(p3);
     double p = (a + b + c) / 2;
     return Math.Sqrt(p * (p - a) * (p - b) * (p - c));
 }
コード例 #2
0
 public double[] ComputeWeight(Point3d p1, Point3d p2, Point3d p3, Vector3d v)
 {
     Vector3d N = new Plane(p1, p2, p3).Normal;
     if (N.IsParallelTo(v) == -1)
     {
         double[] ds = new Double[3]; return ds;
     }
     Vector3d y2 = Vector3d.CrossProduct(v, N);
     v = Vector3d.CrossProduct(y2, N);
     double t = p1.DistanceTo(p2) + p2.DistanceTo(p3) + p3.DistanceTo(p1);
     v.Unitize(); v *= t;
     Point3d cen = (p1 + p2 + p3) / 3;
     Line l1 = new Line(cen - v, cen + v);
     Point3d P1 = l1.ClosestPoint(p1, true);
     Point3d P2 = l1.ClosestPoint(p2, true);
     Point3d P3 = l1.ClosestPoint(p3, true);
     double t1 = (P1.DistanceTo(l1.From)) / l1.Length;
     double t2 = (P2.DistanceTo(l1.From)) / l1.Length;
     double t3 = (P3.DistanceTo(l1.From)) / l1.Length;
     if ((t1 < t2) && (t2 < t3))
     {
         double[] ds = { 0, (t2 - t1) / (t3 - t1), 1 }; return ds;
     }
     else if (t1 < t3 && t3 < t2)
     {
         double[] ds = { 0, 1, (t3 - t1) / (t2 - t1) }; return ds;
     }
     ////
     else if (t2 < t1 && t1 < t3)
     {
         double[] ds = { (t1 - t2) / (t3 - t2), 0, 1 }; return ds;
     }
     else if (t2 < t3 && t3 < t1)
     {
         double[] ds = { 1, 0, (t3 - t2) / (t1 - t2) }; return ds;
     }
     ////
     else if (t3 < t1 && t1 < t2)
     {
         double[] ds = { (t1 - t3) / (t2 - t3), 1, 0 }; return ds;
     }
     else if (t3 < t2 && t2 < t1)
     {
         double[] ds = { 1, (t2 - t3) / (t1 - t3), 0 }; return ds;
     }
     else
     {
         double[] ds = new Double[3]; return ds;
     }
 }
コード例 #3
0
ファイル: remesher.cs プロジェクト: samuto/MeshMachine
        public double WeightedCombo(Point3d Pos, List<Point3d> SizePoints, List<double> Sizes, int Falloff, double BVal, double BWeight)
        {
            double WeightedSize = 0, WeightSum = 0;
            double[] Weighting = new double[SizePoints.Count];

            for (int j = 0; j < SizePoints.Count; j++)
            {
                Weighting[j] = Math.Pow(Pos.DistanceTo(SizePoints[j]), -1.0 * Falloff);
                WeightSum += Weighting[j];
            }

            WeightSum += BWeight;
            WeightedSize += BWeight * (1.0 / WeightSum) * BVal;
            for (int j = 0; j < SizePoints.Count; j++)
            {
                WeightedSize += Weighting[j] * (1.0 / WeightSum) * Sizes[j];
            }
            return WeightedSize;
        }
コード例 #4
0
ファイル: FOV.cs プロジェクト: Esrup/Antflow
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Point3d     person       = new Point3d(0, 0, 0);
            int         angle        = 0;
            Vector3d    direction    = new Vector3d(0, 0, 0);
            double      viewDistance = 0;
            List <Mesh> obstacles    = new List <Mesh>();


            List <Ray3d>   viewRays = new List <Ray3d>();
            List <Point3d> Rayhits  = new List <Point3d>();
            int            fovfree  = 0;

            Mesh meshes = new Mesh();



            DA.GetData(0, ref person);
            DA.GetData(1, ref direction);
            DA.GetData(2, ref viewDistance);
            DA.GetData(3, ref angle);
            DA.GetDataList(4, obstacles);

            int viewRes = angle;

            foreach (Mesh mesh in obstacles)
            {
                meshes.Append(mesh);
            }



            direction.Z = 0;


            direction.Rotate(Rhino.RhinoMath.ToRadians(angle / 2), new Vector3d(0, 0, 1));
            Line viewAngleA = new Line(person, direction, viewDistance);

            direction.Rotate(-Rhino.RhinoMath.ToRadians(angle / 2) * 2, new Vector3d(0, 0, 1));
            Line viewAngleB = new Line(person, direction, viewDistance);

            List <Line> Liness = new List <Line>();

            Liness.Add(viewAngleA);
            Liness.Add(viewAngleB);

            for (int i = 0; i < viewRes + 2; i++)
            {
                if (i > 1)
                {
                    direction.Rotate(Rhino.RhinoMath.ToRadians((angle / viewRes)), new Vector3d(0, 0, 1));
                }

                Ray3d  ray  = new Ray3d(person, direction);
                double rayT = Rhino.Geometry.Intersect.Intersection.MeshRay(meshes, ray);

                Vector3d newvec = Rhino.Geometry.Vector3d.Multiply(direction, viewDistance);

                if (rayT > 0)
                {
                    if (person.DistanceTo(ray.PointAt(rayT)) < viewDistance)
                    {
                        Rayhits.Add(ray.PointAt(rayT));
                    }
                    else
                    {
                        Rayhits.Add(new Point3d(newvec.X + person.X, newvec.Y + person.Y, person.Z));
                        fovfree = fovfree + 1;
                    }
                }
                else
                {
                    Rayhits.Add(new Point3d(newvec.X + person.X, newvec.Y + person.Y, person.Z));
                    fovfree = fovfree + 1;
                }
            }

            Mesh viewMesh = new Mesh();

            viewMesh.Vertices.UseDoublePrecisionVertices = true;

            //Make mesh from hitspoints
            viewMesh.Vertices.Add(new Point3f((float)person.X, (float)person.Y, (float)person.Z));
            viewMesh.VertexColors.Add(System.Drawing.Color.Ivory);

            for (int i = 0; i < Rayhits.Count; i++)
            {
                viewMesh.Vertices.Add(new Point3f((float)Rayhits[i].X, (float)Rayhits[i].Y, (float)Rayhits[i].Z));
                viewMesh.VertexColors.Add(System.Drawing.Color.Ivory);
            }
            for (int i = 0; i < (viewRes + 2); i++)
            {
                viewMesh.Faces.AddFace(0, i, i + 1);
            }


            viewMesh.Faces.RemoveAt(0);



            DA.SetData(0, viewMesh);
            DA.SetData(1, fovfree);
        }
コード例 #5
0
 /// <summary>
 /// Initializes a new ellipse from a center point and the two semiaxes intersections.
 /// </summary>
 /// <param name="center">A center for the ellipse. The avarage of the foci.</param>
 /// <param name="second">The intersection of the ellipse X axis with the ellipse itself.</param>
 /// <param name="third">A point that determines the radius along the Y semiaxis.
 /// <para>If the point is at right angle with the (center - second point) vector,
 /// it will be the intersection of the ellipse Y axis with the ellipse itself.</para>
 /// </param>
 public Ellipse(Point3d center, Point3d second, Point3d third)
 {
     m_plane   = new Plane(center, second, third);
     m_radius1 = center.DistanceTo(second);
     m_radius2 = center.DistanceTo(third);
 }
コード例 #6
0
 public double DistanceTo(Point3d testPoint, bool limitToFiniteSegment, out Point3d pointOnLine)
 {
     pointOnLine = ClosestPoint(testPoint, limitToFiniteSegment);
     return(pointOnLine.DistanceTo(testPoint));
 }
コード例 #7
0
ファイル: PCXTools.cs プロジェクト: 11o9/TuringAndCorbusier
        /// <summary>
        /// 반시계 방향 기준으로 경계 안에 그릴 수 있는 최장의 선을 반환합니다. 기준점이 경계를 벗어나는 경우는 PCXStrict와 동일합니다.
        /// </summary>
        public static Line PCXLongest(Point3d basePt, Polyline boundary, Vector3d direction)
        {
            double  onCurveTolerance  = 0.5;
            double  samePtTolerance   = 0.005;
            double  parallelTolerance = 0.005;
            Point3d longestEnd        = basePt;


            //Get all crossing points.
            List <Point3d> allCrossPts = GetAllCrossPoints(basePt, boundary, direction, onCurveTolerance);

            allCrossPts.Sort((a, b) => (basePt.DistanceTo(a).CompareTo(basePt.DistanceTo(b))));

            //Set compare points.
            List <Point3d> boundaryPt = new List <Point3d>(boundary);

            if (boundary.IsClosed)
            {
                boundaryPt.RemoveAt(boundaryPt.Count - 1);
            }


            //Find end point of longest line.
            foreach (Point3d i in allCrossPts)
            {
                longestEnd = i;

                //seive1: Remove same as basePt.
                if (i.DistanceTo(basePt) < samePtTolerance)
                {
                    continue;
                }


                //seive2: End if not vertex.
                int  vertexIndex = boundaryPt.FindIndex(n => n.DistanceTo(i) < samePtTolerance);
                bool isVertex    = vertexIndex != -1;

                if (!isVertex)
                {
                    break;
                }


                //seive3: End if not concave(& anti-parallel).
                Vector3d  toPre  = boundaryPt[(boundaryPt.Count + vertexIndex - 1) % boundaryPt.Count] - boundaryPt[vertexIndex];
                Vector3d  toPost = boundaryPt[(boundaryPt.Count + vertexIndex + 1) % boundaryPt.Count] - boundaryPt[vertexIndex];
                Convexity cnv    = VectorTools.CheckConvexity(toPre, toPost, parallelTolerance);

                if (cnv == Convexity.Convex || cnv == Convexity.Parallel)
                {
                    break;
                }


                //seive4: Continue if not between.
                if (!VectorTools.IsBetweenVector(toPre, toPost, -direction))
                {
                    continue;
                }


                //seive5: End if pre or post is not parallel to direction.
                bool isPreDirParallel  = Math.Abs(toPre * direction / (toPre.Length * direction.Length)) > 1 - parallelTolerance;
                bool isPostDirParallel = Math.Abs(toPost * direction / (toPost.Length * direction.Length)) > 1 - parallelTolerance;

                if (isPreDirParallel || isPostDirParallel)
                {
                    continue;
                }


                //seive6: Continue if passable.
                Vector3d perpToDir = direction;
                perpToDir.Rotate(Math.PI / 2, Vector3d.ZAxis);

                double preDirDot  = toPre * perpToDir;
                double postDirDot = toPost * perpToDir;

                if (preDirDot * postDirDot > 0)
                {
                    continue;
                }

                break;
            }

            return(new Line(basePt, longestEnd));
        }
コード例 #8
0
 private bool CursorHasMoved()
 {
     return(_secondPoint.DistanceTo(_prevPoint) > 1e-6);
 }
コード例 #9
0
 /// <summary>
 /// Initializes a new ellipse from a center point and the two semiaxes intersections.
 /// </summary>
 /// <param name="center">A center for the ellipse. The avarage of the foci.</param>
 /// <param name="second">The intersection of the ellipse X axis with the ellipse itself.</param>
 /// <param name="third">A point that determines the radius along the Y semiaxis.
 /// <para>If the point is at right angle with the (center - second point) vector,
 /// it will be the intersection of the ellipse Y axis with the ellipse itself.</para>
 /// </param>
 public Ellipse(Point3d center, Point3d second, Point3d third)
 {
   m_plane = new Plane(center, second, third);
   m_radius1 = center.DistanceTo(second);
   m_radius2 = center.DistanceTo(third);
 }
コード例 #10
0
 private bool checkIfOnLine(Point3d pt1, Point3d pt2, Point3d pttested)
 {
     double num = pttested.DistanceTo(pt1);
     double num2 = pttested.DistanceTo(pt2);
     double num3 = pt1.DistanceTo(pt2);
     return ((num + num2) > num3);
 }
コード例 #11
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            int year = 2017;
            //int tasks = 1;
            //if (this.mt) tasks = Environment.ProcessorCount;
            int             tasks   = Environment.ProcessorCount;
            ParallelOptions paropts = new ParallelOptions {
                MaxDegreeOfParallelism = tasks
            };
            //ParallelOptions paropts_1cpu = new ParallelOptions { MaxDegreeOfParallelism = 1 };


            //////////////////////////////////////////////////////////////////////////////////////////
            /// INPUTS
            int reclvl = 0;

            if (!DA.GetData(0, ref reclvl))
            {
                return;
            }

            bool drawviewfactors = false;

            if (!DA.GetData(1, ref drawviewfactors))
            {
                drawviewfactors = false;
            }

            bool drawcumskymatrix = false;

            if (!DA.GetData(2, ref drawcumskymatrix))
            {
                drawcumskymatrix = false;
            }

            bool draw_sunpath = true;

            if (!DA.GetData(3, ref draw_sunpath))
            {
                draw_sunpath = true;
            }

            bool draw_solarvec = true;

            if (!DA.GetData(4, ref draw_solarvec))
            {
                draw_solarvec = true;
            }

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

            if (!DA.GetDataList(5, hoy))
            {
                return;
            }

            List <double> loc = new List <double>();

            if (!DA.GetDataList(6, loc))
            {
                return;
            }
            double longitude = loc[0];
            double latitude  = loc[1];

            List <double> dni = new List <double>();
            List <double> dhi = new List <double>();

            DA.GetDataList(7, dni);
            DA.GetDataList(8, dhi);

            double domesize = 1.2;

            if (!DA.GetData(9, ref domesize))
            {
                domesize = 1.2;
            }

            List <Mesh> context = new List <Mesh>();

            DA.GetDataList(10, context);

            Point3d sp = new Point3d();

            if (!DA.GetData(11, ref sp))
            {
                return;
            }


            //////////////////////////////////////////////////////////////////////////////////////////
            /// size of skydome
            Point3d anchor = sp;
            Point3d bb_furthest_point;    // max distance to furthest corner of context
            double  bb_max_distance = double.MinValue;

            if (context.Count > 0)
            {
                Mesh context_joined = new Mesh();
                foreach (Mesh msh in context)
                {
                    context_joined.Append(msh);
                }
                BoundingBox bb_context = context_joined.GetBoundingBox(false);
                if (bb_context.IsDegenerate(-1.0) == 4)
                {
                    bb_furthest_point = new Point3d(sp.X + 1.0, sp.Y + 1.0, sp.Z + 1.0);
                }
                else
                {
                    Point3d[] _pts     = bb_context.GetCorners();
                    int       _p_index = 0;
                    for (int i = 0; i < _pts.Length; i++)
                    {
                        double _d = sp.DistanceTo(_pts[i]);
                        if (_d > bb_max_distance)
                        {
                            bb_max_distance = _d;
                            _p_index        = i;
                        }
                    }
                    bb_furthest_point = _pts[_p_index];
                }
            }
            else
            {
                bb_furthest_point = new Point3d(sp.X + 1.0, sp.Y + 1.0, sp.Z + 1.0);
            }
            Vector3d vec_sp = bb_furthest_point - sp;

            vec_sp = Vector3d.Multiply(vec_sp, domesize);
            double vec_sp_len = vec_sp.Length;


            //////////////////////////////////////////////////////////////////////////////////////////
            /// SKYDOME
            /// View factors and/or Cumulative SkyMatrix
            SkyDome dome = new SkyDome(reclvl);

            // create 2 meshes, one with obstructed views (make it black transparent), and one unobstructed (regular GH_Mesh color)
            Mesh meshObstructed = new Mesh();

            foreach (double[] p in dome.VertexVectorsSphere)
            {
                Vector3d vec = new Vector3d(p[0], p[1], p[2]);
                vec = Vector3d.Multiply(vec_sp_len, vec);
                meshObstructed.Vertices.Add(vec + sp);
            }
            foreach (int[] f in dome.Faces)
            {
                meshObstructed.Faces.AddFace(f[0], f[1], f[2]);
            }
            meshObstructed.UnifyNormals();

            if (drawviewfactors)
            {
                List <Vector3d> vec_sky_list = new List <Vector3d>();
                List <int>      vec_int      = new List <int>();
                for (int i = 0; i < meshObstructed.Vertices.Count; i++)
                {
                    Vector3d testvec = meshObstructed.Vertices[i] - sp;
                    if (testvec.Z >= 0.0)
                    {
                        vec_sky_list.Add(testvec);
                        vec_int.Add(i);
                    }
                }
                Color[] colors = new Color[meshObstructed.Vertices.Count];
                for (int i = 0; i < meshObstructed.Vertices.Count; i++)
                {
                    colors[i] = Color.FromArgb(100, 255, 255, 255);  //alpha not working
                }
                meshObstructed.VertexColors.SetColors(colors);
                Vector3d[] vec_sky = vec_sky_list.ToArray();
                bool[]     shadow  = new bool[vec_sky_list.Count];
                if (context.Count > 0)
                {
                    CShadow.CalcShadowMT(sp, new Vector3d(0, 0, 1), 0.001, vec_sky, context.ToArray(), ref shadow, paropts);
                }

                int j = 0;
                foreach (int i in vec_int)
                {
                    Color c = new Color();
                    if (shadow[j])
                    {
                        // Custom material, DisplayMaterial (rhinostyle) rendering material. and make in override DrawViewportMesh
                        c = Color.FromArgb(100, 0, 0, 0);   //alpha not working
                        meshObstructed.VertexColors.SetColor(i, c);
                        _vectorsObstructed.Add(i);
                    }
                    j++;
                }
            }
            else if (drawcumskymatrix)
            {
                // https://www.sciencedirect.com/science/article/pii/S0038092X04001161
                // http://alexandria.tue.nl/openaccess/635611/p1153final.pdf
                // Solarmodel.dll needs new function to compute cumulative sky view matrix (requires obstruction check from drawviewfactors
                // 1. calc perez diffuse for each hour. use that value (hor, circum, dome) and assign it to each mesh face
                // 2. DNI is computed directly onto SP
                // 3. visualize colored dome for diff only.
                // 4. add text to sensorpoint, stating annual irradiation (DNI plus diff)
                //
                // cumskymatrix seperate component!! coz it can be re-used for several sensor points
                // matrix inversion as in robinson stone to compute irradiation on all sensor points with refl.?
                //
                // needs a separate component that uses cumskymatrix on a number of SPs and visualizes that analysis surface.
                //... or use this component, output the sensorpoints, give it to a surface and make surface evaluate with the points, and recolor that surface

                if (dni.Count == 8760 && dhi.Count == 8760)     // only continue, if solar irradiance time series are provided
                {
                    //Rhino.RhinoApp.WriteLine("Leggo!");
                    //Context.cWeatherdata weather;
                    //weather.DHI = dhi;
                    //weather.DNI = dni;
                    //weather.Snow = new List<double>();
                    //double[] beta = new double[1] { beta_in };
                    //double[] psi = new double[1] { psi_in };
                    //Sensorpoints.p3d[] coord = new Sensorpoints.p3d[1];   //dummy variables. will not be used in this simplified simulation
                    //coord[0].X = 0;
                    //coord[0].Y = 0;
                    //coord[0].Z = 0;
                    //Sensorpoints.v3d[] normal = new Sensorpoints.v3d[1];   //dummy variables. will not be used in this simplified simulation
                    //normal[0].X = 0;
                    //normal[0].Y = 1;
                    //normal[0].Z = 0;


                    //double[] albedo = new double[8760];
                    //for (int t = 0; t < 8760; t++)
                    //{
                    //    albedo[t] = albedo1;
                    //}

                    //Console.WriteLine("Calculating irradiation...");
                    //Sensorpoints p = new Sensorpoints(beta, psi, coord, normal, reclvl);
                    //p.SetSimpleSkyMT(beta, paropts);
                    //p.SetSimpleGroundReflectionMT(beta, albedo, weather, sunvectors.ToArray(), paropts);
                    //p.CalcIrradiationMT(weather, sunvectors.ToArray(), paropts);

                    // hold on... i need a new function in SolarModel for CumSkyMatrix
                }
                else
                {
                    Rhino.RhinoApp.WriteLine("No data for Direct Normal Irradiance and Diffuse Horizontal Irradiance provided... Please provide 8760 time series for each.");
                }
            }

            if (drawviewfactors || drawcumskymatrix)
            {
                //_colouredMesh.Add(meshObstructed);
                _viewFactors = meshObstructed;
            }

            //////////////////////////////////////////////////////////////////////////////////////////
            /// Solar Vectors
            List <Sphere>    spheres  = new List <Sphere>();
            double           fontsize = vec_sp_len / 50.0;
            List <SunVector> sunvectors_list;

            SunVector.Create8760SunVectors(out sunvectors_list, longitude, latitude, year);
            int count = 0;

            if (draw_solarvec)
            {
                foreach (int h in hoy)
                {
                    Vector3d vec = new Vector3d(sunvectors_list[h].udtCoordXYZ.x, sunvectors_list[h].udtCoordXYZ.y, sunvectors_list[h].udtCoordXYZ.z);
                    vec = Vector3d.Multiply(vec_sp_len, vec);
                    Point3d solarpoint = new Point3d(Point3d.Add(sp, vec));
                    Line    ln         = new Line(sp, solarpoint);
                    ln.Flip();
                    _solar_vectors.Add(ln);
                    if (sunvectors_list[h].udtCoordXYZ.z < 0)
                    {
                        _night_time.Add(true);
                    }
                    else
                    {
                        _night_time.Add(false);
                    }

                    int    year_now  = sunvectors_list[h].udtTime.iYear;
                    int    month_now = sunvectors_list[h].udtTime.iMonth;
                    int    day_now   = sunvectors_list[h].udtTime.iDay;
                    double hour_now  = sunvectors_list[h].udtTime.dHours;
                    string hour_now2 = Convert.ToString(hour_now);
                    if (hour_now < 10)
                    {
                        hour_now2 = "0" + Convert.ToString(hour_now);
                    }
                    string strval = Convert.ToString(year_now) + "/ " + Convert.ToString(month_now) + "/ " + Convert.ToString(day_now) + "/ " + hour_now2 + ":00";
                    Plane  pl     = new Plane(ln.From, new Vector3d(-1, 0, 0));
                    //Plane pl = new Plane(ln.From, vec);
                    var te = Rhino.RhinoDoc.ActiveDoc.Objects.AddText(strval, pl, fontsize, "Baskerville", false, false);
                    Rhino.DocObjects.TextObject txt = Rhino.RhinoDoc.ActiveDoc.Objects.Find(te) as Rhino.DocObjects.TextObject;
                    _txt.Add(new List <Curve>());
                    if (txt != null)
                    {
                        var     tt = txt.Geometry as Rhino.Geometry.TextEntity;
                        Curve[] A  = tt.Explode();

                        foreach (Curve crv in A)
                        {
                            _txt[count].Add(crv);
                        }
                    }
                    count++;
                    Rhino.RhinoDoc.ActiveDoc.Objects.Delete(te, true);

                    Sphere sph = new Sphere(ln.From, vec_sp_len / 30.0);
                    spheres.Add(sph);
                }
            }


            //////////////////////////////////////////////////////////////////////////////////////////
            /// SUN PATH
            /// !!! wierd sun paths at extreme longitudes -> time shift... +/- UCT
            // draw solar paths: curves that connect each month, but for the same hour
            if (draw_sunpath)
            {
                for (int hod = 0; hod < 24; hod++)
                {
                    List <Point3d> pts = new List <Point3d>();
                    for (int d = 0; d < 365; d++)
                    {
                        int      h   = hod + 24 * d;
                        Vector3d vec = new Vector3d(sunvectors_list[h].udtCoordXYZ.x, sunvectors_list[h].udtCoordXYZ.y, sunvectors_list[h].udtCoordXYZ.z);
                        vec = Vector3d.Multiply(vec_sp_len, vec);
                        if (vec.Z > 0)
                        {
                            Point3d solarpoint = new Point3d(Point3d.Add(sp, vec));
                            pts.Add(solarpoint);
                        }
                    }
                    if (pts.Count > 0)
                    {
                        PolylineCurve crv = new PolylineCurve(pts);
                        _sun_paths.Add(crv);
                    }
                }

                // draw solar paths; curves that connects each hour, but for the same month
                int interv = 365 / 12;
                for (int m = 0; m < 12; m++)
                {
                    List <Point3d> pts = new List <Point3d>();
                    for (int hod = 0; hod < 24; hod++)
                    {
                        int      h   = hod + ((m * interv + interv / 2) * 24);
                        Vector3d vec = new Vector3d(sunvectors_list[h].udtCoordXYZ.x, sunvectors_list[h].udtCoordXYZ.y, sunvectors_list[h].udtCoordXYZ.z);
                        vec = Vector3d.Multiply(vec_sp_len, vec);
                        if (vec.Z > 0)
                        {
                            Point3d solarpoint = new Point3d(Point3d.Add(sp, vec));
                            pts.Add(solarpoint);
                        }
                    }
                    if (pts.Count > 0)
                    {
                        PolylineCurve crv = new PolylineCurve(pts);
                        _sun_paths.Add(crv);
                    }
                }
            }


            //////////////////////////////////////////////////////////////////////////////////////////
            /// OUTPUT
            DA.SetData(0, _viewFactors);        // this mesh needs to be colored according to view factor or cumulative sky matrix
            DA.SetDataList(1, _solar_vectors);
            DA.SetDataList(2, _sun_paths);
            DA.SetDataList(3, spheres);
        }
コード例 #12
0
 public override bool Contains(Point3d pt)
 {
   foreach (Brep[] borderWalls in borderWallsArray)
   {
     foreach (Brep brep in borderWalls)
     {
       if (pt.DistanceTo(brep.ClosestPoint(pt)) < Constants.AbsoluteTolerance)
       {
         return false;
       }
     }
   }
   return true;
 }
コード例 #13
0
 /*
  *  Gets the wrapped point that is closest to the relativePoint.
  */
 public override Point3d WrapPoint(Point3d relativePoint, Point3d point)
 {
   Point3d wrappedPoint = point;
   double minDistance = Double.MaxValue;
   for (double x = -Width; x <= Width; x += Width)
   {
     for (double y = -Height; y <= Height; y += Height)
     {
       Point3d potentialPoint = new Point3d(point.X + x, point.Y + y, point.Z);
       double distance = relativePoint.DistanceTo(potentialPoint);
       if (distance < minDistance)
       {
         minDistance = distance;
         wrappedPoint = potentialPoint;
       }
     }
   }
   return wrappedPoint;
 }
コード例 #14
0
        public override void OnSkeletonFrameReady(
          object sender, SkeletonFrameReadyEventArgs e
        )
        {
            Point3d pt = new Point3d();
            if (!Finished)
            {
                using (SkeletonFrame s = e.OpenSkeletonFrame())
                {
                    if (s != null)
                    {
                        Skeleton[] skels = new Skeleton[s.SkeletonArrayLength];
                        s.CopySkeletonDataTo(skels);

                        foreach (Skeleton data in skels)
                        {
                            if (
                              data.TrackingState == SkeletonTrackingState.Tracked
                            )
                            {
                                leftHip =
                                  PointFromVector(
                                    data.Joints[JointType.HipLeft].Position, false
                                  );
                                leftHand =
                                  PointFromVector(
                                    data.Joints[JointType.HandLeft].Position, false
                                  );
                                Point3d rightHand =
                                  PointFromVector(
                                    data.Joints[JointType.HandRight].Position, false
                                  );

                                if (
                                  leftHand.DistanceTo(Point3d.Origin) > 0 &&
                                  rightHand.DistanceTo(Point3d.Origin) > 0 &&
                                  leftHand.DistanceTo(rightHand) < 0.03)
                                {
                                    // Hands are less than 3cm from each other

                                    _drawing = false;
                                    _resizing = false;
                                    _isRotate = false;
                                    _changeaxis = false;
                                    _resizebool = 0;
                                    Finished = true;
                                }
                                else
                                {
                                    // Hands are within 10cm of each other vertically
                                    // and both hands are above the waist, so we resize
                                    // the profile radius


                                    _resizing = (leftHand.Z > leftHip.Z &&
                                       rightHand.Z > leftHip.Z &&
                                       Math.Abs(leftHand.Z - rightHand.Z) < 0.5);

                                    _changeaxis = (leftHand.Z > leftHip.Z &&
                                           rightHand.Z > leftHip.Z &&
                                           Math.Abs(leftHand.Z - rightHand.Z) < 0.5);



                                    // If the left hand is below the waist, we draw
                                    _isRotate = (leftHand.Z < leftHip.Z);
                                    _drawing = false;
                                }

                                //_resizing = true;

                                if (ct == 0)
                                {
                                    pt = rightHand;
                                    ct = 1;
                                }
                                if (_resizing)
                                {
                                    // If resizing, set some data to help draw
                                    // a sphere where we're resizing

                                    Vector3d vec = (leftHand - rightHand) / 2;
                                    _resizeLocation = pt + vec;
                                    _profSide = vec.Length / (Math.Sqrt(3));
                                    vRot = rightHand.GetVectorTo(leftHand); //new Point3d(-3, 4, 0).GetVectorTo(new Point3d(-3, -4, 0)); //rightHand.GetVectorTo(leftHand);
                                }

                                //       if (_changeaxis)
                                //     {
                                //        vRot = rightHand.GetVectorTo(leftHand);
                                //  }

                                //if (_isRotate)
                                // {
                                //     cube.WorldDraw(draw);
                                // }

                                if (_drawing)
                                {
                                    // If we have at least one prior vertex...

                                    if (_vertices.Count > 0)
                                    {
                                        // ... check whether we're a certain distance
                                        // away from the last one before adding it (this
                                        // smooths off the jitters of adding every point)

                                        Point3d lastVert =
                                          _vertices[_vertices.Count - 1];
                                        if (
                                          lastVert.DistanceTo(rightHand) > _profSide * 4
                                        )
                                        {
                                            // Add the new vertex to our list

                                            _vertices.Add(rightHand);
                                        }
                                    }
                                    else
                                    {
                                        // Add the first vertex to our list

                                        _vertices.Add(rightHand);
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }
コード例 #15
0
 public override Point3d WrapPoint(Point3d relativePoint, Point3d point)
 {
   Point3d wrappedPoint = point;
   bool wrapped;
   wrappedPoint = WrapPoint(point, out wrapped);
   if (wrapped)
   {
     if (relativePoint.DistanceTo(wrappedPoint) < relativePoint.DistanceTo(point))
     {
       return wrappedPoint;
     }
     else 
     {
       return point;
     }
   }
   double minDistance = Double.MaxValue;
   for (double x = -Width; x <= Width; x += Width)
   {
     for (double y = -Height; y <= Height; y += Height)
     {
       for (double z = -Depth; z <= Depth; z += Depth)
       {
         Point3d potentialPoint = new Point3d(point.X + x, point.Y + y, point.Z + z);
         double distance = relativePoint.DistanceTo(potentialPoint);
         if (distance < minDistance)
         {
           minDistance = distance;
           wrappedPoint = potentialPoint;
         }
       }
     }
   }
   return wrappedPoint;
 }
コード例 #16
0
    // Are two points within a certain distance?

    private static bool CloseTo(
      Point3d first, Point3d second, double dist = 0.1
    )
    {
      return first.DistanceTo(second) < dist;
    }
コード例 #17
0
        /// <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)
        {
            bool ignoreSelfIntersecting = false; // set to True if you don't want to output curves where width < 0, which creates a self-intersecting curve
            int  inCt = 0;                       // count the number of required parameters that are receiving data

            Point3d       PtA        = new Point3d();
            Point3d       PtB        = new Point3d();
            Plane         refPlane   = new Plane();
            double        W          = 0.0;
            double        width      = double.NaN;
            double        length     = 0.0;
            double        height     = 0.0;
            double        angle      = 0.0;
            double        m          = 0.0;
            List <double> multiple_m = new List <double>();
            bool          flip_H     = false; // if height is negative, this flag will be set
            bool          flip_A     = false; // if angle is negative, this flag will be set

            double E = 0.0;
            double I = 0.0;

            if (!DA.GetData(0, ref PtA))
            {
                return;
            }

            if (!DA.GetData(2, ref refPlane))
            {
                refPlane        = Plane.WorldXY;
                refPlane.Origin = PtA;
            }
            // Points to be in refPlane
            if (Math.Round(refPlane.DistanceTo(PtA), Defined.ROUNDTO) != 0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Point A is not on the base plane");
                return;
            }
            if (DA.GetData(1, ref PtB))
            {
                // Points to be in refPlane
                if (Math.Round(refPlane.DistanceTo(PtB), Defined.ROUNDTO) != 0)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Point B is not on the base plane");
                    return;
                }
                Line AtoB = new Line(PtA, PtB);
                if (AtoB.Length != 0 & !AtoB.Direction.IsPerpendicularTo(refPlane.YAxis))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "The line between PtA and PtB is not perpendicular to the Y-axis of the specified plane");
                    return;
                }
                inCt++;
                if (DA.GetData(4, ref W))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Width W will override the distance between PtA and PtB. If you do not want this to happen, disconnect PtB or Width.");
                }
                W = PtA.DistanceTo(PtB);  // get the width (distance) between PtA and PtB

                Point3d refPtB;
                if (refPlane.RemapToPlaneSpace(PtB, out refPtB))
                {
                    if (refPtB.X < 0)
                    {
                        W = -W;  // check if PtB is to the left of PtA...if so, width is negative
                    }
                }
                width = W;
            }

            if (DA.GetData(3, ref length))
            {
                inCt++;
            }
            if (DA.GetData(4, ref W))
            {
                inCt++;
            }
            if (DA.GetData(5, ref height))
            {
                inCt++;
            }
            if (DA.GetData(6, ref angle))
            {
                inCt++;
            }

            if (inCt > 2)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "More parameters set than are required (out of length, width, height, angle). Only using the first two valid ones.");
            }

            if (DA.GetData(3, ref length))
            {
                if (length <= 0.0)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Length cannot be negative or zero");
                    return;
                }
                if (DA.GetData(4, ref W))
                {
                    if (W > length)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Width is greater than length");
                        return;
                    }
                    if (W == length)
                    {
                        height = 0;
                        m      = 0;
                        angle  = 0;
                        width  = W;
                    }
                    else
                    {
                        m      = SolveMFromLengthWidth(length, W);
                        height = Cal_H(length, m); // L * Sqrt(m) / K(m)
                        angle  = Cal_A(m);         // Acos(1 - 2 * m)
                        width  = W;
                    }
                }
                else if (W != double.NaN)
                {
                    if (W > length)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Width is greater than length");
                        return;
                    }
                    if (W == length)
                    {
                        height = 0;
                        m      = 0;
                        angle  = 0;
                    }
                    else
                    {
                        m      = SolveMFromLengthWidth(length, W);
                        height = Cal_H(length, m); // L * Sqrt(m) / K(m)
                        angle  = Cal_A(m);         // Acos(1 - 2 * m)
                    }
                    width = W;
                }
                else if (DA.GetData(5, ref height))
                {
                    if (Math.Abs(height / length) > Defined.MAX_HL_RATIO)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Height not possible with given length");
                        return;
                    }
                    if (height < 0)
                    {
                        height = -height;  // if height is negative, set it to positive (for the calculations) but flip the reference plane about its x-axis
                        refPlane.Transform(Transform.Mirror(new Plane(refPlane.Origin, refPlane.XAxis, refPlane.ZAxis)));
                        flip_A = true;
                        flip_H = true;
                    }
                    if (height == 0)
                    {
                        width = length;
                        angle = 0;
                    }
                    else
                    {
                        multiple_m = SolveMFromLengthHeight(length, height);  // note that it's possible for two values of m to be found if height is close to max height
                        if (multiple_m.Count == 1)
                        {
                            m     = multiple_m.ElementAt(0);
                            width = Cal_W(length, m); // L * (2 * E(m) / K(m) - 1)
                            angle = Cal_A(m);         // Acos(1 - 2 * m)
                        }
                    }
                }
                else if (DA.GetData(6, ref angle))
                {
                    if (angle < 0)
                    {
                        angle = -angle;  // if angle is negative, set it to positive (for the calculations) but flip the reference plane about its x-axis
                        refPlane.Transform(Transform.Mirror(new Plane(refPlane.Origin, refPlane.XAxis, refPlane.ZAxis)));
                        flip_A = true;
                        flip_H = true;
                    }
                    m = Cal_M(angle);  // (1 - Cos(a)) / 2
                    if (angle == 0)
                    {
                        width  = length;
                        height = 0;
                    }
                    else
                    {
                        width  = Cal_W(length, m); // L * (2 * E(m) / K(m) - 1)
                        height = Cal_H(length, m); // L * Sqrt(m) / K(m)
                    }
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Need to specify one more parameter in addition to length");
                    return;
                }
            }
            else if (DA.GetData(4, ref W))
            {
                if (DA.GetData(5, ref height))
                {
                    if (height < 0)
                    {
                        height = -height;  // if height is negative, set it to positive (for the calculations) but flip the reference plane about its x-axis
                        refPlane.Transform(Transform.Mirror(new Plane(refPlane.Origin, refPlane.XAxis, refPlane.ZAxis)));
                        flip_A = true;
                        flip_H = true;
                    }
                    if (height == 0)
                    {
                        length = W;
                        angle  = 0;
                    }
                    else
                    {
                        m      = SolveMFromWidthHeight(W, height);
                        length = Cal_L(height, m); // h * K(m) / Sqrt(m)
                        angle  = Cal_A(m);         // Acos(1 - 2 * m)
                    }
                }
                else if (DA.GetData(6, ref angle))
                {
                    if (W == 0)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Curve not possible with width = 0 and an angle as inputs");
                        return;
                    }
                    if (angle < 0)
                    {
                        angle = -angle;  // if angle is negative, set it to positive (for the calculations) but flip the reference plane about its x-axis
                        refPlane.Transform(Transform.Mirror(new Plane(refPlane.Origin, refPlane.XAxis, refPlane.ZAxis)));
                        flip_A = true;
                        flip_H = true;
                    }
                    m = Cal_M(angle);  // (1 - Cos(a)) / 2
                    if (angle == 0)
                    {
                        length = W;
                        height = 0;
                    }
                    else
                    {
                        length = W / (2 * EllipticE(m) / EllipticK(m) - 1);
                        if (length < 0)
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Curve not possible at specified width and angle (calculated length is negative)");
                            return;
                        }
                        height = Cal_H(length, m);  // L * Sqrt(m) / K(m)
                    }
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Need to specify one more parameter in addition to width (Wid)");
                    return;
                }
                width = W;
            }
            else if (width != double.NaN)
            {
                if (DA.GetData(5, ref height))
                {
                    if (height < 0)
                    {
                        height = -height;  // if height is negative, set it to positive (for the calculations) but flip the reference plane about its x-axis
                        refPlane.Transform(Transform.Mirror(new Plane(refPlane.Origin, refPlane.XAxis, refPlane.ZAxis)));
                        flip_A = true;
                        flip_H = true;
                    }
                    if (height == 0)
                    {
                        length = width;
                        angle  = 0;
                    }
                    else
                    {
                        m      = SolveMFromWidthHeight(width, height);
                        length = Cal_L(height, m); // h * K(m) / Sqrt(m)
                        angle  = Cal_A(m);         // Acos(1 - 2 * m)
                    }
                }
                else if (DA.GetData(6, ref angle))
                {
                    if (width == 0)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Curve not possible with width = 0 and an angle as inputs");
                        return;
                    }
                    if (angle < 0)
                    {
                        angle = -angle;  // if angle is negative, set it to positive (for the calculations) but flip the reference plane about its x-axis
                        refPlane.Transform(Transform.Mirror(new Plane(refPlane.Origin, refPlane.XAxis, refPlane.ZAxis)));
                        flip_A = true;
                        flip_H = true;
                    }
                    m = Cal_M(angle);  // (1 - Cos(a)) / 2
                    if (angle == 0)
                    {
                        length = width;
                        height = 0;
                    }
                    else
                    {
                        length = width / (2 * EllipticE(m) / EllipticK(m) - 1);
                        if (length < 0)
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Curve not possible at specified width and angle (calculated length is negative)");
                            return;
                        }
                        height = Cal_H(length, m);  // L * Sqrt(m) / K(m)
                    }
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Need to specify one more parameter in addition to PtA and PtB");
                    return;
                }
            }
            else if (DA.GetData(5, ref height))
            {
                if (DA.GetData(6, ref angle))
                {
                    if (height < 0)
                    {
                        height = -height;  // if height is negative, set it to positive (for the calculations) but flip the reference plane about its x-axis
                        refPlane.Transform(Transform.Mirror(new Plane(refPlane.Origin, refPlane.XAxis, refPlane.ZAxis)));
                        flip_H = true;
                        flip_A = true;
                    }
                    if (height == 0)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Height can't = 0 if only height and angle are specified");
                        return;
                    }
                    else
                    {
                        if (angle < 0)
                        {
                            angle = -angle;  // if angle is negative, set it to positive (for the calculations) but flip the reference plane about its x-axis
                            refPlane.Transform(Transform.Mirror(new Plane(refPlane.Origin, refPlane.XAxis, refPlane.ZAxis)));
                            flip_A = !flip_A;
                            flip_H = !flip_H;
                        }
                        m = Cal_M(angle);  // (1 - Cos(a)) / 2
                        if (angle == 0)
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Angle can't = 0 if only height and angle are specified");
                            return;
                        }
                        else
                        {
                            length = Cal_L(height, m); // h * K(m) / Sqrt(m)
                            width  = Cal_W(length, m); // L * (2 * E(m) / K(m) - 1)
                        }
                    }
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Need to specify one more parameter in addition to height");
                    return;
                }
            }
            else if (DA.GetData(6, ref angle))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Need to specify one more parameter in addition to angle");
                return;
            }
            else
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Need to specify two of the four parameters: length, width (or PtB), height, and angle");
                return;
            }

            if (m > Defined.M_MAX)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Form of curve not solvable with current algorithm and given inputs");
                return;
            }

            refPlane.Origin = refPlane.PointAt(width / (double)2, 0, 0);  // adjust the origin of the reference plane so that the curve is centered about the y-axis (start of the curve is at x = -width/2)

            DA.GetData(7, ref E);

            if (multiple_m.Count > 1)
            {
                DataTree <Point3d> multi_pts = new DataTree <Point3d>();
                List <Curve>       multi_crv = new List <Curve>();
                List <Point3d>     tmp_pts = new List <Point3d>();
                List <double>      multi_W = new List <double>(), multi_A = new List <double>(), multi_F = new List <double>();
                int j = 0;  // used for creating a new branch (GH_Path) for storing pts which is itself a list of points

                foreach (double m_val in multiple_m)
                {
                    width = Cal_W(length, m_val); // length * (2 * EllipticE(m_val) / EllipticK(m_val) - 1)

                    if (width < 0 & ignoreSelfIntersecting)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "One curve is self-intersecting. To enable these, set ignoreSelfIntersecting to False");
                        continue;
                    }

                    if (m_val >= Defined.M_SKETCHY)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Accuracy of the curve whose width = " + Math.Round(width, 4) + " is not guaranteed");
                    }

                    angle           = Cal_A(m_val);                              // Math.Asin(2 * m_val - 1)
                    refPlane.Origin = refPlane.PointAt(width / (double)2, 0, 0); // adjust the origin of the reference plane so that the curve is centered about the y-axis (start of the curve is at x = -width/2)

                    tmp_pts = FindBendForm(length, width, m_val, angle, refPlane);
                    multi_pts.AddRange(tmp_pts, new GH_Path(j));
                    multi_crv.Add(MakeCurve(tmp_pts, angle, refPlane));

                    multi_W.Add(width);
                    if (flip_A)
                    {
                        angle = -angle;
                    }
                    multi_A.Add(angle);

                    E = E * Math.Pow(10, 9);                                                  // Young's modulus input E is in GPa, so we convert to Pa here (= N/m^2)
                    multi_F.Add(Math.Pow(EllipticK(m_val), 2) * E * I / Math.Pow(length, 2)); // from reference {4} pg. 79

                    j += 1;
                    refPlane.Origin = PtA;  // reset the reference plane origin to PtA for the next m_val
                }

                // assign the outputs
                DA.SetDataTree(0, multi_pts);
                DA.SetDataList(1, multi_crv);
                DA.SetData(2, length);
                DA.SetDataList(3, multi_W);
                if (flip_H)
                {
                    height = -height;
                }
                DA.SetData(4, height);
                DA.SetDataList(5, multi_A);
                DA.SetDataList(6, multi_F);
            }
            else
            {
                if (m >= Defined.M_SKETCHY)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Accuracy of the curve at these parameters is not guaranteed");
                }

                if (width < 0 & ignoreSelfIntersecting)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Curve is self-intersecting. To enable these, set ignoreSelfIntersecting to False");
                    return;
                }

                DataTree <Point3d> multi_pts = new DataTree <Point3d>();
                List <Point3d>     pts       = FindBendForm(length, width, m, angle, refPlane);
                multi_pts.AddRange(pts, new GH_Path(0));
                DA.SetDataTree(0, multi_pts);

                List <Curve> multi_crv = new List <Curve>();
                multi_crv.Add(MakeCurve(pts, angle, refPlane));
                DA.SetDataList(1, multi_crv);
                DA.SetData(2, length);
                List <double> multi_W = new List <double>()
                {
                    width
                };
                DA.SetDataList(3, multi_W);
                if (flip_H)
                {
                    height = -height;
                }
                DA.SetData(4, height);
                if (flip_A)
                {
                    angle = -angle;
                }
                List <double> multi_A = new List <double>()
                {
                    angle
                };
                DA.SetDataList(5, multi_A);

                E = E * Math.Pow(10, 9);                                            // Young's modulus input E is in GPa, so we convert to Pa here (= N/m^2)
                double F = Math.Pow(EllipticK(m), 2) * E * I / Math.Pow(length, 2); // from reference {4} pg. 79. Note: the critical buckling (that makes the rod/wire start to bend) can be found at height=0 (width=length)

                List <double> multi_F = new List <double>()
                {
                    F
                };
                DA.SetDataList(6, multi_F);
            }
        }
コード例 #18
0
ファイル: Lattice.cs プロジェクト: smor/intralattice
        /// <summary>
        /// Trims strut with known intersection point, returning  the trimmed LineCurve which is inside the space.
        /// </summary>
        public LineCurve AddTrimmedStrut(LatticeNode node1, LatticeNode node2, Point3d intersectionPt, double minLength, double maxLength)
        {

            LineCurve testStrut = new LineCurve(new Line(node1.Point3d, node2.Point3d), 0, 1);  // set line, with curve parameter domain [0,1]

            if (node1.IsInside)
            {
                double trimmedLength = intersectionPt.DistanceTo(node1.Point3d);
                if (trimmedLength > minLength && trimmedLength < maxLength)
                {
                    Nodes.Add(new LatticeNode(intersectionPt, LatticeNodeState.Boundary));
                    return new LineCurve(node1.Point3d, intersectionPt);
                }
                else
                {
                    node1.State = LatticeNodeState.Boundary;
                }
            }
            
            if (node2.IsInside)
            {
                double trimmedLength = intersectionPt.DistanceTo(node2.Point3d);
                if (trimmedLength > minLength && trimmedLength < maxLength)
                {
                    Nodes.Add(new LatticeNode(intersectionPt, LatticeNodeState.Boundary));
                    return new LineCurve(node2.Point3d, intersectionPt);
                }
                else
                {
                    node2.State = LatticeNodeState.Boundary;
                }
            }

            return null;
        }
コード例 #19
0
        private void ChaseEnemy()
        {
            if (dead)
            {
                return;
            }
            switch (m_chaseState)
            {
            case ChaseState.IDLE:
            {
                UpdateActive = false;
                return;
            }

            case ChaseState.CHASING_ENEMY:
            {
                Creature target = m_targetID == 0 ? null : (Creature)World.Instance.GetEntity(m_targetID);
                if (target == null)
                {
                    StartBackToHome();
                    return;
                }
                // the distance to target
                float distance = (float)Position.DistanceTo(target.Position);
                if (distance > LongDistance)
                {
                    // too far away, I cannot catch up my target, so I give up
                    StartBackToHome();
                    return;
                }

                if (m_targetPos.DistanceTo(target.Position) > DistanceEpsilon)
                {
                    // the target is moving
                    // target deviate path which I calculate last time, so I must re-calculate
                    if (!FindPath(target.Position, m_routeSteps))
                    {
                        StartBackToHome();
                        return;
                    }
                    m_targetPos = target.Position;
                    SendMove(MoveState.BEGIN, Position, m_targetID);
                    return;
                }

                if (distance < DistanceEpsilon)
                {
                    // reach the destination
                    m_routeSteps.Clear();
                }

                if (m_routeSteps.Count == 0)
                {
                    this.Position = target.Position;
                    SendMove(MoveState.END, target.Position, m_targetID);
                    m_chaseState = ChaseState.ATTACKING;
                }
                else
                {
                    Point3d pos = m_routeSteps.First.Value;
                    m_routeSteps.RemoveFirst();
                    SendMove(MoveState.STEP, pos, m_targetID);
                }
            }
                return;

            case ChaseState.BACK_TO_HOME:
            {
                if (m_routeSteps.Count == 0)
                {
                    m_chaseState = ChaseState.IDLE;
                    Position     = V3ToPoint3d(DefaultData.pos);
                    SendMove(MoveState.END, Position);
                }
                else
                {
                    Point3d pos = m_routeSteps.First.Value;
                    m_routeSteps.RemoveFirst();
                    SendMove(MoveState.STEP, pos);
                }
            }
                return;

            case ChaseState.ATTACKING:
            {
                Creature target = m_targetID == 0 ? null : (Creature)World.Instance.GetEntity(m_targetID);
                if (target == null || target.currentHP == 0)
                {
                    StartBackToHome();
                    return;
                }

                if (Position.DistanceTo(target.Position) < DistanceEpsilon)
                {
                    OnAttack(target);
                    target.OnHit(this, 1);
                }
                else
                {
                    m_chaseState = ChaseState.CHASING_ENEMY;
                    if (!FindPath(target.Position, m_routeSteps))
                    {
                        StartBackToHome();
                        return;
                    }

                    m_targetPos = target.Position;
                    SendMove(MoveState.BEGIN, Position, m_targetID);
                }
            }
                return;
            }
        }
コード例 #20
0
            public override bool shoot(Point3d Start, Vector3d Dir, int Random, out double u, out double v, out int Srf_ID, out List<Point3d> X_PT, out List<double> t, out List<int> Code)
            {
                S_Origin = new Point3d(Start);
                Srf_ID = 0;

                while (true)
                {
                    Point3d[] P = Rhino.Geometry.Intersect.Intersection.RayShoot(new Ray3d(S_Origin, Dir), BrepList, 1);

                    if (P == null) { X_PT = new List<Point3d> { default(Point3d) }; u = 0; v = 0; t = new List<double> { 0 }; Code = new List<int> { 0 }; return false; }

                    Voxels.PointIsInVoxel(P[0], ref XVoxel, ref YVoxel, ref ZVoxel);
                    try
                    {
                        SurfaceIndex = Voxels.VoxelList(XVoxel, YVoxel, ZVoxel);
                    }
                    catch (Exception)
                    {
                        //Rare floating point error on some computers... abandon the ray and start the next...
                        //Explanation: This would never happen on my IBM T43P laptop, but happened 
                        //consistently millions of function calls into the calculation on my 
                        //ASUS K8N-DL based desktop computer. I believe it has something to do with some quirk of that system.
                        //This try...catch statement is here in case this ever manifests on any user's computer. 
                        //It is rare enough that this should not affect the accuracy of the calculation.
                        t = new List<double> { 0.0f };
                        X_PT = new List<Point3d> { default(Point3d) };
                        u = 0;
                        v = 0;
                        Code = new List<int> { 0 };
                        return false;
                    }

                    Point3d CP;
                    Vector3d N;
                    ComponentIndex CI;
                    double MD = 0.0001;

                    foreach (int index in SurfaceIndex)
                    {
                        if (BrepList[index].ClosestPoint(P[0], out CP, out CI, out u, out v, MD, out N) && (CI.ComponentIndexType == ComponentIndexType.BrepFace))
                        {
                            if ((Math.Abs(P[0].X - CP.X) < 0.0001) && (Math.Abs(P[0].Y - CP.Y) < 0.0001) && (Math.Abs(P[0].Z - CP.Z) < 0.0001))
                            {
                                Srf_ID = index;
                                X_PT = new List<Point3d> {P[0]};
                                t = new List<double> {(double)(S_Origin.DistanceTo(X_PT[0]))};
                                Code = new List<int>() { 0 };
                                return true;
                            }
                        }
                    }
                    S_Origin = new Point3d(P[0]);
                }
            }
コード例 #21
0
ファイル: Line.cs プロジェクト: susannnwu/Triceratops
        /// <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)
        {
            // Declate variables
            Curve           curve    = null;
            string          name     = "";
            MaterialWrapper material = null;

            // Reference the inputs
            DA.GetData(0, ref curve);
            DA.GetData(1, ref name);
            DA.GetData(2, ref material);

            // Throw error message if curve cannot be converted to a polyline
            if (!curve.IsPolyline())
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input must be polyine, curves are not allowed.");
                return;
            }

            // Convert curve to polyline
            Polyline polyline = null;

            curve.TryGetPolyline(out polyline);

            // Fill a list with the polyline's point coordinates
            List <double> array = new List <double>();

            for (int i = 0; i < polyline.Count; i++)
            {
                // Get point values
                var px = polyline.X[i];
                var py = polyline.Y[i];
                var pz = polyline.Z[i];

                // Add point values to array
                array.Add(Math.Round(px, 3) * -1);
                array.Add(Math.Round(pz, 3));
                array.Add(Math.Round(py, 3));
            }

            //Build the position object
            dynamic position = new ExpandoObject();

            position.itemSize   = 3;
            position.type       = "Float32Array";
            position.array      = array;
            position.normalized = false;

            // Build the attribute object
            dynamic attributes = new ExpandoObject();

            attributes.position = position;

            // If LineDashedMaterial is used, add the lineDistance attribute
            if (material != null && string.Equals(material.Material.type, "LineDashedMaterial"))
            {
                // Create list to populate with lineDistances
                List <double> lineDistances = new List <double>();
                Point3d       previousPt    = new Point3d();

                // Loop over vertices and measure the distance from start to each vertex
                for (int i = 0; i < polyline.Count; i++)
                {
                    // Get point values
                    var px = polyline.X[i];
                    var py = polyline.Y[i];
                    var pz = polyline.Z[i];

                    // Distance to previous point
                    Point3d pt = new Point3d(px, py, pz);
                    if (i == 0)
                    {
                        lineDistances.Add(0);
                    }
                    else
                    {
                        lineDistances.Add(pt.DistanceTo(previousPt) + lineDistances[i - 1]);
                    }
                    previousPt = pt;
                }

                // Build the lineDistance object
                dynamic lineDistance = new ExpandoObject();
                lineDistance.type     = "Float32Array";
                lineDistance.array    = lineDistances;
                lineDistance.count    = polyline.Count;
                lineDistance.itemSize = 1;

                // Add the lineDistance object to the attributes object
                attributes.lineDistance = lineDistance;
            }

            // Build the data object
            dynamic data = new ExpandoObject();

            data.attributes = attributes;

            // Build the geometry object
            dynamic geometry = new ExpandoObject();

            geometry.uuid = Guid.NewGuid();
            geometry.type = "BufferGeometry";
            geometry.data = data;

            // Build the child object
            dynamic child = new ExpandoObject();

            child.uuid = Guid.NewGuid();
            if (name.Length > 0)
            {
                child.name = name;
            }
            child.type     = "Line";
            child.geometry = geometry.uuid;
            if (material != null)
            {
                child.material = material.Material.uuid;
            }
            child.matrix = new List <double> {
                1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1
            };

            // Fill the children list
            List <dynamic> children = new List <dynamic>();

            children.Add(child);

            // Wrap the objects in a wrapper object
            GeometryWrapper wrapper = null;

            if (material != null)
            {
                wrapper = new GeometryWrapper(geometry, child, material.Material);
            }
            else
            {
                wrapper = new GeometryWrapper(geometry, child, null);
            }

            // Serialize wrapper object
            string JSON = JsonConvert.SerializeObject(wrapper);

            // Set outputs
            DA.SetData(0, JSON);
            DA.SetData(1, wrapper);
        }
コード例 #22
0
ファイル: Graph.cs プロジェクト: airmay/CAM
 public static Point3d GetClosestPoint(this Curve curve, Point3d point) => point.DistanceTo(curve.StartPoint) <= point.DistanceTo(curve.EndPoint) ? curve.StartPoint : curve.EndPoint;
コード例 #23
0
 /// <summary>
 /// 微调湿接缝宽度--初次布板湿接缝递增或递减,现将其调匀
 /// </summary>
 private List<Point3d> AdjustSjfW(Point3d start, Point3d end, int segCount, List<double> adjustSjfW)
 {
     double seglength = start.DistanceTo(end) / segCount;
     Vector3d vect = start.GetVectorTo(end).GetNormal();
     List<Point3d> res = new List<Point3d>();
     double dist = 0;
     for (int i = 1; i < segCount; i++)
     {
         dist += (seglength + adjustSjfW[i - 1]);
         res.Add(start + vect.MultiplyBy(dist));
     }
     return res;
 }
コード例 #24
0
ファイル: Zoom.cs プロジェクト: ef5tech/MyCAD
        public static void Use(Point3d pMin, Point3d pMax, Point3d pCenter, double dFactor)
        {
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDB = acDoc.Database;

            int nCurVport = System.Convert.ToInt32(Application.GetSystemVariable("CVPORT"));

            if (acCurDB.TileMode == true) //model space
            {
                if (pMin.Equals(new Point3d()) == true && pMax.Equals(new Point3d()) == true)
                {
                    pMin = acCurDB.Extmin; //Get the extends of model space
                    pMax = acCurDB.Extmax;
                }
            }
            else
            {
                if (nCurVport == 1) //paper space
                {
                    if (pMin.Equals(new Point3d()) == true && pMax.Equals(new Point3d()) == true)
                    {
                        pMin = acCurDB.Pextmin; //Get the extends of paper space
                        pMax = acCurDB.Pextmax;
                    }
                }
                else
                {
                    if (pMin.Equals(new Point3d()) == true && pMax.Equals(new Point3d()) == true)
                    {
                        pMin = acCurDB.Extmin; //Get the extends of model space
                        pMax = acCurDB.Extmax;
                    }
                }
            }
            using (Transaction acTrans = acCurDB.TransactionManager.StartTransaction())
            {
                using (ViewTableRecord acView = acDoc.Editor.GetCurrentView())
                {
                    Extents3d eExtents;

                    Matrix3d matWCStoDCS;
                    matWCStoDCS = Matrix3d.PlaneToWorld(acView.ViewDirection);
                    matWCStoDCS = Matrix3d.Displacement(acView.Target - Point3d.Origin) * matWCStoDCS;
                    matWCStoDCS = Matrix3d.Rotation(-acView.ViewTwist, acView.ViewDirection, acView.Target) * matWCStoDCS;

                    if (pCenter.DistanceTo(Point3d.Origin) != 0)
                    {
                        pMin = new Point3d(pCenter.X - (acView.Width / 2), pCenter.Y - (acView.Height / 2), 0);
                        pMax = new Point3d((acView.Width / 2) + pCenter.X, (acView.Height / 2) + pCenter.Y, 0);
                    }
                    using (Line acLine = new Line(pMin, pMax))
                    {
                        eExtents = new Extents3d(acLine.Bounds.Value.MinPoint, acLine.Bounds.Value.MaxPoint);
                    }
                    double dViewRatio;
                    dViewRatio = (acView.Width / acView.Height);

                    matWCStoDCS = matWCStoDCS.Inverse();
                    eExtents.TransformBy(matWCStoDCS);

                    double  dWidth;
                    double  dHeight;
                    Point2d pNewCentPt;

                    if (pCenter.DistanceTo(Point3d.Origin) != 0)
                    {
                        dWidth  = acView.Width;
                        dHeight = acView.Height;

                        if (dFactor == 0)
                        {
                            pCenter = pCenter.TransformBy(matWCStoDCS);
                        }
                        pNewCentPt = new Point2d(pCenter.X, pCenter.Y);
                    }
                    else
                    {
                        dWidth  = eExtents.MaxPoint.X - eExtents.MinPoint.X;
                        dHeight = eExtents.MaxPoint.Y - eExtents.MinPoint.Y;

                        pNewCentPt = new Point2d((eExtents.MaxPoint.X + eExtents.MinPoint.X) * 0.5, (eExtents.MaxPoint.Y + eExtents.MinPoint.Y) * 0.5);
                    }
                    if (dWidth > (dHeight * dViewRatio))
                    {
                        dHeight = dWidth / dViewRatio;
                    }
                    if (dFactor != 0)
                    {
                        acView.Height = dHeight * dFactor;
                        acView.Width  = dWidth * dFactor;
                    }
                    acView.CenterPoint = pNewCentPt;
                    acDoc.Editor.SetCurrentView(acView);
                }
                acTrans.Commit();
            }
        }
コード例 #25
0
        public double DistanceTo(Point3d testPoint, bool limitToFiniteSegment)
        {
            Point3d pp = ClosestPoint(testPoint, limitToFiniteSegment);

            return(pp.DistanceTo(testPoint));
        }
コード例 #26
0
        public static Polyline[] OffsetPolyline(Polyline c0, Polyline c1, double toolr = 10, bool notch = false)
        {
            if (toolr == 0)
            {
                return new Polyline[] { c0, c1 }
            }
            ;

            if (c0.Count == 2)
            {
                return new Polyline[] { c0, c1 }
            }
            ;


            Transform transform = OrientTo2D(c0);

            Polyline ply0 = new Polyline(c0);
            Polyline ply1 = new Polyline(c1);

            bool closed = c0[0].DistanceToSquared(c0[c0.Count - 1]) < 0.001;

            if (!closed)
            {
                ply0.Close();

                ply1.Close();
            }

            ply0.Transform(transform);
            ply1.Transform(transform);

            Transform inverse; transform.TryGetInverse(out inverse);


            Plane ply0Plane = ply0.plane();
            Plane ply1Plane = ply1.plane();

            Polyline pl0Offset = new Polyline();
            Polyline pl1Offset = new Polyline();

            string orient = (IsClockwiseClosedPolylineOnXYPlane(ply0)) ? "CounterClockwise" : "Clockwise";


            if (ply0.IsValid && ply1.IsValid)
            {
                Point3d[] vrts  = ply0.ToArray();
                Point3d[] uvrts = ply1.ToArray();

                Plane notPairingPlane;
                Plane.FitPlaneToPoints(vrts, out notPairingPlane);

                //int k = 1;
                //int infeed = 1;
                //Rhino.RhinoApp.WriteLine(k.ToString());
                //ncc.Add("(start infeed no" + k.ToString() + ")");
                for (int i = 0; i != vrts.Length - 1; i++) // iterate segments
                {
                    Point3d p0  = vrts[i];                 //#always
                    Point3d p0u = uvrts[i];
                    Point3d p2b = new Point3d();
                    Point3d p1b = new Point3d();
                    Point3d p1  = new Point3d();
                    Point3d p2  = new Point3d();
                    Point3d p1u = new Point3d();

                    if (i == 0)
                    {
                        p2b = vrts[vrts.Length - 3];
                        p1b = vrts[vrts.Length - 2];
                        p1  = vrts[i + 1];
                        p2  = vrts[i + 2];
                        p1u = uvrts[i + 1];
                    }
                    else if (i == 1)
                    {
                        p2b = vrts[vrts.Length - 2];
                        p1b = vrts[i - 1];
                        p1  = vrts[i + 1];
                        p2  = vrts[i + 2];
                        p1u = uvrts[i + 1];
                    }
                    else if (i == vrts.Length - 2)
                    {
                        p2b = vrts[i - 2];
                        p1b = vrts[i - 1];
                        p1  = vrts[0];
                        p2  = vrts[1];
                        p1u = uvrts[0];
                    }
                    else if (i == vrts.Length - 3)
                    {
                        p2b = vrts[i - 2];
                        p1b = vrts[i - 1];
                        p1  = vrts[i + 1];
                        p2  = vrts[0];
                        p1u = uvrts[i + 1];
                    }
                    else
                    {
                        p2b = vrts[i - 2];
                        p1b = vrts[i - 1];
                        p1  = vrts[i + 1];
                        p2  = vrts[i + 2];
                        p1u = uvrts[i + 1];
                    }

                    // ## DET TOOLPATH

                    Vector3d n1b = Rhino.Geometry.Vector3d.CrossProduct(p1b - p0, p0u - p0);        //#Srf Normal (last)
                    Vector3d n0  = Rhino.Geometry.Vector3d.CrossProduct(p0 - p1, p0u - p0);         //#Srf Normal (current)
                    Vector3d n1  = Rhino.Geometry.Vector3d.CrossProduct(p2 - p1, p1u - p1);         //#Srf Normal (next)
                    n1b.Unitize();
                    n1b *= toolr * -1;
                    n0.Unitize();
                    n0 *= toolr;
                    n1.Unitize();
                    n1 *= toolr;



                    Plane pl0 = new Plane(p0, (n1b + n0) / 2);                         //# ext bisector plane last/current
                    Plane pl1 = new Plane(p1, ((n0 + n1) / 2));                        //# ext bisector plane current/next



                    Line ln0 = new Line(p0 + (n0 * -1), p1 + (n0 * -1));                                     //# toolpath Line

                    double pm0;
                    double pm1;
                    Rhino.Geometry.Intersect.Intersection.LinePlane(ln0, pl0, out pm0);
                    Rhino.Geometry.Intersect.Intersection.LinePlane(ln0, pl1, out pm1);
                    Point3d pt0 = ln0.PointAt(pm0);                                                 //# intersection with Plane 0
                    Point3d pt1 = ln0.PointAt(pm1);                                                 //# intersection with Plane 1



                    Point3d pt6   = new Point3d();
                    bool    boolN = false;

                    Vector3d n44 = p1u - p1;
                    n44.Unitize();
                    Point3d ptXX = pt1 + n44 * 45;

                    Line XXA = new Line(p1, p1u);

                    Point3d  ptC = XXA.ClosestPoint(pt1, false);
                    double   l0  = ptC.DistanceTo(pt1) - toolr;                                     //# offset dist
                    Vector3d nnn = ptC - pt1;
                    nnn.Unitize();
                    Point3d pt3 = pt1 + nnn * l0;
                    Point3d pt4 = pt3 + (p1u - p1);
                    Line    ln1 = new Line(pt3, pt4);                                              //# cylinder axis

                    //## IDENTIFY INSIDE CORNERS
                    Vector3d r1l = p2b - p1b;                                 //# last back
                    Vector3d r1n = p0 - p1b;                                  //# last front
                    Vector3d al  = p1b - p0;                                  //# current back
                    Vector3d an  = p1 - p0;                                   //# current front
                    Vector3d bl  = p0 - p1;                                   //# next back
                    Vector3d bn  = p2 - p1;                                   //# next front
                    r1l.Unitize();
                    r1n.Unitize();
                    al.Unitize();
                    an.Unitize();
                    bl.Unitize();
                    bn.Unitize();

                    Vector3d cpr1 = Vector3d.CrossProduct(r1l, r1n);                           //# +- look 1 back
                    Vector3d cp0  = Vector3d.CrossProduct(al, an);                             //# +- look current
                    Vector3d cp1  = Vector3d.CrossProduct(bl, bn);                             //# +- look 1 ahead


                    if (orient == "Clockwise")
                    {
                        if (cpr1.Z < 0 && cp0.Z < 0 && cp1.Z > 0)     //# --+
                        {
                            boolN = true;
                        }
                        else if (cpr1.Z < 0 && cp0.Z > 0 && cp1.Z > 0)   //# -++
                        {
                            boolN = true;
                        }
                        else if (cpr1.Z > 0 && cp0.Z < 0 && cp1.Z > 0)       //# +-+
                        {
                            boolN = true;
                        }
                    }
                    else if (orient == "CounterClockwise")
                    {
                        if (cp0.Z > 0)       //# +-+
                        {
                            boolN = true;
                        }
                    }



                    Point3d[] pts = { pt0, pt1, pt1 + (p1u - p1), pt0 + (p0u - p0) };

                    //Vector3d nh0 = ((pts[3] - pts[0]) / infeed) * (k - 1);
                    //Vector3d nh1 = ((pts[2] - pts[1]) / infeed) * (k - 1);

                    Point3d p21 = pts[1]; //+ nh1;  // infeed pts
                    Point3d p30 = pts[0]; //+ nh0;



                    int IPDtemp = 3;                                                                        // division for sim mach
                    if (Math.Abs(pts[0].DistanceTo(pts[1])) <= Math.Abs(pts[3].DistanceTo(pts[2])) + 0.5 && Math.Abs(pts[0].DistanceTo(pts[1])) >= Math.Abs(pts[3].DistanceTo(pts[2])) - 0.5)
                    {
                        IPDtemp = 1;                                                                        // simple cut
                    }

                    // List<Point3d> ptsl = IBOIS.Utilities.GeometryProcessing.DividePoints(pts[0], pts[1], IPDtemp);
                    // List<Point3d> ptsm = IBOIS.Utilities.GeometryProcessing.DividePoints(p30, p21, IPDtemp);
                    //List<Point3d> ptsu = IBOIS.Utilities.GeometryProcessing.DividePoints(pts[3], pts[2], IPDtemp);

                    //  Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(pts[0]);



                    //Rhino.RhinoDoc.ActiveDoc.Objects.AddLine(new Line(p30,p21));
                    //      Rhino.RhinoDoc.ActiveDoc.Objects.AddLine(new Line(pts[0], pts[1]));
                    //        Rhino.RhinoDoc.ActiveDoc.Objects.AddLine(new Line(pts[3], pts[2]));

                    //Rhino.RhinoDoc.ActiveDoc.Objects.AddLine(new Line(pts[0], pts[3]));
                    double t;
                    Line   line = new Line(pts[0], pts[3]);
                    Rhino.Geometry.Intersect.Intersection.LinePlane(line, ply0Plane, out t);
                    pl0Offset.Add(line.PointAt(t));
                    Rhino.Geometry.Intersect.Intersection.LinePlane(line, ply1Plane, out t);
                    pl1Offset.Add(line.PointAt(t));
                }
            }



            //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(pl0Offset);

            if (notch)
            {
                //notches
                List <Line> notches = DrillingHoleForConvexCorners(ply0, ply1, -toolr);

                //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(pl0Offset);
                //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(pl1Offset);

                int counter = 0;
                for (int i = 0; i < notches.Count; i++)
                {
                    if ((!closed) && (i == 0 || i == (notches.Count - 1)))
                    {
                        continue;
                    }
                    if (notches[i] == Line.Unset)
                    {
                        continue;
                    }

                    //Rhino.RhinoDoc.ActiveDoc.Objects.AddLine(notches[i]);

                    pl0Offset.Insert(i + 1 + counter, notches[i].From);//i+1 because after point
                    pl1Offset.Insert(i + 1 + counter, notches[i].To);
                    counter++;
                    pl0Offset.Insert(i + 1 + counter, pl0Offset[i - 1 + counter]);
                    pl1Offset.Insert(i + 1 + counter, pl1Offset[i - 1 + counter]);
                    counter++;
                }
            }

            if (closed)
            {
                pl0Offset.Close();
                pl1Offset.Close();
            }

            pl0Offset.Transform(inverse);
            pl1Offset.Transform(inverse);
            return(new Polyline[] { pl0Offset, pl1Offset });
        }
コード例 #27
0
        public override void OnSkeletonFrameReady(
            object sender, SkeletonFrameReadyEventArgs e
            )
        {
            if (!Finished)
            {
                using (SkeletonFrame s = e.OpenSkeletonFrame())
                {
                    if (s != null)
                    {
                        Skeleton[] skels = new Skeleton[s.SkeletonArrayLength];
                        s.CopySkeletonDataTo(skels);

                        foreach (Skeleton data in skels)
                        {
                            if (
                                data.TrackingState == SkeletonTrackingState.Tracked
                                )
                            {
                                Point3d leftHip =
                                    PointFromVector(
                                        data.Joints[JointType.HipLeft].Position, false
                                        );
                                Point3d leftHand =
                                    PointFromVector(
                                        data.Joints[JointType.HandLeft].Position, false
                                        );
                                Point3d rightHand =
                                    PointFromVector(
                                        data.Joints[JointType.HandRight].Position, false
                                        );

                                if (
                                    leftHand.DistanceTo(Point3d.Origin) > 0 &&
                                    rightHand.DistanceTo(Point3d.Origin) > 0 &&
                                    leftHand.DistanceTo(rightHand) < 0.03)
                                {
                                    // Hands are less than 3cm from each other

                                    _drawing  = false;
                                    _resizing = false;
                                    Finished  = true;
                                }
                                else
                                {
                                    // Hands are within 10cm of each other vertically
                                    // and both hands are above the waist, so we resize
                                    // the profile radius

                                    _resizing =
                                        (leftHand.Z > leftHip.Z &&
                                         rightHand.Z > leftHip.Z &&
                                         Math.Abs(leftHand.Z - rightHand.Z) < 0.1);

                                    // If the left hand is below the waist, we draw

                                    _drawing = (leftHand.Z < leftHip.Z);
                                }

                                if (_resizing)
                                {
                                    // If resizing, set some data to help draw
                                    // a sphere where we're resizing

                                    Vector3d vec = (leftHand - rightHand) / 2;
                                    _resizeLocation = rightHand + vec;
                                    _profRad        = vec.Length;
                                }

                                if (_drawing)
                                {
                                    // If we have at least one prior vertex...

                                    if (_vertices.Count > 0)
                                    {
                                        // ... check whether we're a certain distance
                                        // away from the last one before adding it (this
                                        // smooths off the jitters of adding every point)

                                        Point3d lastVert =
                                            _vertices[_vertices.Count - 1];
                                        if (
                                            lastVert.DistanceTo(rightHand) > _profRad * 4
                                            )
                                        {
                                            // Add the new vertex to our list

                                            _vertices.Add(rightHand);
                                        }
                                    }
                                    else
                                    {
                                        // Add the first vertex to our list

                                        _vertices.Add(rightHand);
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }
コード例 #28
0
        public void CaculateAm()
        {
            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                int[]   f      = vs.IndicesFromFace(i);
                Point3d p1     = vs[f[0]];
                Point3d p2     = vs[f[1]];
                Point3d p3     = vs[f[2]];
                Circle  circle = new Circle(p1, p2, p3);
                double  a      = p1.DistanceTo(p2);
                double  b      = p1.DistanceTo(p3);
                double  c      = p2.DistanceTo(p3);
                // Print(f.Length.ToString());
                // Print(a.ToString() + "/" + b.ToString() + "/" + c.ToString());
                Point3d ci   = new Point3d();
                int     sign = 0;
                if (c >= a && c >= b)
                {
                    if ((c * c) < (a * a + b * b))
                    {
                        ci = circle.Center;
                    }
                    else
                    {
                        ci = (p2 + p3) / 2; sign = 1;
                    }
                }
                else if (a >= c && a >= b)
                {
                    if ((a * a) < (c * c + b * b))
                    {
                        ci = circle.Center;
                    }
                    else
                    {
                        ci = (p2 + p1) / 2; sign = 2;
                    }
                }
                else if (b >= a && b >= c)
                {
                    if ((b * b) < (a * a + c * c))
                    {
                        ci = circle.Center;
                    }
                    else
                    {
                        ci = (p1 + p3) / 2; sign = 3;
                    }
                }
                else
                { //Print("error");
                }

                Point3d p1p2 = (p1 + p2) / 2;
                Point3d p1p3 = (p1 + p3) / 2;
                Point3d p2p3 = (p3 + p2) / 2;

                if (sign == 0)
                {
                    ps[f[0]].Am += areaTri(ci, p1, p1p2) + areaTri(ci, p1, p1p3);
                    ps[f[1]].Am += areaTri(ci, p2, p1p2) + areaTri(ci, p2, p2p3);
                    ps[f[2]].Am += areaTri(ci, p3, p1p3) + areaTri(ci, p3, p2p3);
                }
                else if (sign == 1)
                {
                    ps[f[1]].Am += areaTri(ci, p2, p1p2);
                    ps[f[2]].Am += areaTri(ci, p3, p1p3);
                    ps[f[0]].Am += areaTri(ci, p1, p1p2) + areaTri(ci, p1, p1p3);
                }
                else if (sign == 2)
                {
                    ps[f[1]].Am += areaTri(ci, p2, p2p3);
                    ps[f[0]].Am += areaTri(ci, p1, p1p3);
                    ps[f[2]].Am += areaTri(ci, p3, p1p3) + areaTri(ci, p3, p2p3);
                }
                else if (sign == 3)
                {
                    ps[f[0]].Am += areaTri(ci, p1, p1p2);
                    ps[f[2]].Am += areaTri(ci, p3, p2p3);
                    ps[f[1]].Am += areaTri(ci, p2, p1p2) + areaTri(ci, p2, p2p3);
                }
                else
                {// Print("error");
                }
                //////////////////
                ps[f[0]].KG += Vector3d.VectorAngle(p2 - p1, p3 - p1);
                ps[f[1]].KG += Vector3d.VectorAngle(p1 - p2, p3 - p2);
                ps[f[2]].KG += Vector3d.VectorAngle(p2 - p3, p1 - p3);
                /////////////////
            }
            for (int i = 0; i < el.Count; i++)
            {
                int[] f = el.GetConnectedFaces(i);
                if (f.Length == 2)
                {
                    ///////////////
                    int pi1 = el.GetTopologyVertices(i).I;
                    int pi2 = el.GetTopologyVertices(i).J;
                    int pf1 = 0; int pf2 = 0;

                    int[] vi1 = vs.IndicesFromFace(f[0]);
                    for (int j = 0; j < 3; j++)
                    {
                        if (vi1[j] != pi1 && vi1[j] != pi2)
                        {
                            pf1 = vi1[j]; break;
                        }
                    }
                    int[] vi2 = vs.IndicesFromFace(f[1]);
                    for (int j = 0; j < 3; j++)
                    {
                        if (vi2[j] != pi1 && vi2[j] != pi2)
                        {
                            pf2 = vi2[j]; break;
                        }
                    }
                    double ang1 = Vector3d.VectorAngle(vs[pi1] - vs[pf1], vs[pi2] - vs[pf1]);
                    double ang2 = Vector3d.VectorAngle(vs[pi1] - vs[pf2], vs[pi2] - vs[pf2]);
                    if (ang1 == Math.PI / 2)
                    {
                        ang1 = 0;
                    }
                    else
                    {
                        ang1 = 1 / Math.Tan(ang1);
                    }
                    if (ang2 == Math.PI / 2)
                    {
                        ang2 = 0;
                    }
                    else
                    {
                        ang2 = 1 / Math.Tan(ang2);
                    }
                    double total = ang1 + ang2;
                    double t1    = Vector3d.Multiply(ps[pi1].n, (vs[pi1] - vs[pi2]));
                    double t2    = Vector3d.Multiply(ps[pi2].n, (vs[pi2] - vs[pi1]));
                    ps[pi1].KH += t1 * total;
                    ps[pi2].KH += t2 * total;
                    ////////////////
                }
            }
        }
コード例 #29
0
        protected override SamplerStatus Sampler(JigPrompts prompts)
        {
            int           num;
            SamplerStatus samplerStatus;
            int           num2;
            object        obj;

            try
            {
                ProjectData.ClearProjectError();
                num = 2;
                PromptPointResult promptPointResult = prompts.AcquirePoint(new JigPromptPointOptions("\r\n请指定下一点:")
                {
                    Cursor       = 2,
                    BasePoint    = this.point3d_0,
                    UseBasePoint = true
                });
                Point3d value = promptPointResult.Value;
                if (value != this.point3d_1)
                {
                    checked
                    {
                        if (this.bool_0)
                        {
                            this.double_0 = value.DistanceTo(this.point3d_0);
                            this.short_0  = (short)Math.Round(this.double_0 / 6.0);
                            this.double_2 = value.GetVectorTo(this.point3d_0).AngleOnPlane(new Plane());
                            this.point2d_0..ctor(this.point3d_0.X, this.point3d_0.Y);
                            this.jipAtgRsh..ctor(value.X, value.Y);
                        }
                        else
                        {
                            this.short_0 = (short)Math.Round(value.DistanceTo(this.point3d_0));
                            if ((double)this.short_0 >= this.double_0)
                            {
                                this.short_0 = (short)Math.Round(this.double_0);
                            }
                            else if ((double)this.short_0 <= this.double_0 / 6.0)
                            {
                                this.short_0 = (short)Math.Round(this.double_0 / 6.0);
                            }
                        }
                    }
                    Point2d point2dAngle  = CAD.GetPoint2dAngle(this.jipAtgRsh, (double)this.short_0 / 6.0, this.double_2 * 180.0 / 3.1415926535897931 - 90.0);
                    Point2d point2dAngle2 = CAD.GetPoint2dAngle(this.jipAtgRsh, (double)this.short_0 / 3.0, this.double_2 * 180.0 / 3.1415926535897931 - 90.0);
                    Point2d point2dAngle3 = CAD.GetPoint2dAngle(this.jipAtgRsh, (double)this.short_0 / 3.0, this.double_2 * 180.0 / 3.1415926535897931 + 180.0);
                    Point2d point2dAngle4 = CAD.GetPoint2dAngle(this.jipAtgRsh, (double)this.short_0 / 3.0, this.double_2 * 180.0 / 3.1415926535897931 + 90.0);
                    Point2d point2dAngle5 = CAD.GetPoint2dAngle(this.jipAtgRsh, (double)this.short_0 / 6.0, this.double_2 * 180.0 / 3.1415926535897931 + 90.0);
                    this.polyline_0 = new Polyline();
                    this.polyline_0.AddVertexAt(0, this.point2d_0, 0.0, 0.0, 0.0);
                    this.polyline_0.AddVertexAt(1, point2dAngle, 0.0, 0.0, 0.0);
                    this.polyline_0.AddVertexAt(2, point2dAngle2, 0.0, 0.0, 0.0);
                    this.polyline_0.AddVertexAt(3, point2dAngle3, 0.0, 0.0, 0.0);
                    this.polyline_0.AddVertexAt(4, point2dAngle4, 0.0, 0.0, 0.0);
                    this.polyline_0.AddVertexAt(5, point2dAngle5, 0.0, 0.0, 0.0);
                    this.polyline_0.Closed = true;
                    this.polyline_0.Layer  = "注释";
                    this.entity_0[0]       = this.polyline_0;
                    this.point3d_1         = value;
                    samplerStatus          = 0;
                    goto IL_431;
                }
                samplerStatus = 1;
                goto IL_431;
IL_3E9:
                num2 = -1;
                @switch(ICSharpCode.Decompiler.ILAst.ILLabel[], num);
IL_3FE:
                goto IL_426;
IL_400:
                samplerStatus = 1;
                goto IL_431;
            }
            catch when(endfilter(obj is Exception & num != 0 & num2 == 0))
            {
                Exception ex = (Exception)obj2;

                goto IL_3E9;
            }
IL_426:
            throw ProjectData.CreateProjectError(-2146828237);
IL_431:
            SamplerStatus result = samplerStatus;

            if (num2 != 0)
            {
                ProjectData.ClearProjectError();
            }
            return(result);
        }
コード例 #30
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <double> node  = new List <double>();
            List <double> nodeX = new List <double>();
            List <double> nodeY = new List <double>();
            List <double> nodeZ = new List <double>();

            List <double> nodeNum     = new List <double>();
            List <double> stressesTen = new List <double>();
            List <double> stressesCom = new List <double>();
            List <double> nx          = new List <double>();
            List <double> ny          = new List <double>();

            List <Fiber> Fibers = new List <Fiber>();

            Surface Srf4Nodes = null;

            DA.GetDataList("X", nodeX);
            DA.GetDataList("Y", nodeY);
            DA.GetDataList("Z", nodeZ);
            DA.GetDataList("Node", node);           // small

            DA.GetDataList("Node Number", nodeNum); // big (duplicate)
            DA.GetDataList("Nodal Tension Stress", stressesTen);
            DA.GetDataList("Nodal Compression Stress", stressesCom);
            DA.GetDataList("Nodal Force Nx", nx);
            DA.GetDataList("Nodal Force Ny", ny);

            DA.GetDataList("Custom Fibers", Fibers);
            DA.GetData("Surface", ref Srf4Nodes);

            // SoFiNode: structure info assambly
            List <SoFiNode> SoFiNodesOnSrf = new List <SoFiNode>();

            for (int i = 0; i < nodeX.Count; i++)
            {
                SoFiNode inode = new SoFiNode(node[i], nodeX[i], nodeY[i], nodeZ[i]);
                double   u;
                double   v;
                Srf4Nodes.ClosestPoint(inode.Node, out u, out v);
                Point3d closestPt = Srf4Nodes.PointAt(u, v);

                if (closestPt.DistanceTo(inode.Node) < 0.01)  // on surface
                {
                    SoFiNodesOnSrf.Add(inode);
                }
            }
            // so far the sofiNodes have no structure info

            // ====================== structure info big list ===================================
            // node number, compression stress, tension stress, force in  local x, force in local y

            List <NodalStructureInfo> NodalStructureInfo = new List <NodalStructureInfo>();

            for (int i = 0; i < nodeNum.Count; i++)
            {
                NodalStructureInfo inodal = new NodalStructureInfo(nodeNum[i], stressesTen[i], stressesCom[i], nx[i], ny[i]);
                NodalStructureInfo.Add(inodal);
            }
            // ==================================================================================

            // abandom the nodes not on the srf
            // list.RemoveAll(item => !list2.Contains(item))
            List <double> nodeNumOnSrf = SoFiNodesOnSrf.Select(o => o.NodeNum).ToList();

            NodalStructureInfo.RemoveAll(o => !nodeNumOnSrf.Contains(o.NodeNum)); // remove structure info not on srf
            List <NodalStructureInfo> CondensedNodalStructureInfo = new List <RP1516.NodalStructureInfo>();

            for (int i = 0; i < SoFiNodesOnSrf.Count; i++)
            {
                double iNodeNumber = SoFiNodesOnSrf[i].NodeNum;
                List <NodalStructureInfo> iNodalinfo = NodalStructureInfo.Where(o => o.NodeNum == iNodeNumber).ToList();
                double iNodeCount = iNodalinfo.Count();

                // Com
                double iComStress = iNodalinfo
                                    .Select(o => o.StressCom).ToList().Sum()
                                    / iNodeCount;

                // Ten
                double iTenStress = iNodalinfo
                                    .Select(o => o.StressTen).ToList().Sum()
                                    / iNodeCount;

                // NX
                double iNX = iNodalinfo
                             .Select(o => o.Nx).ToList().Sum()
                             / iNodeCount;

                // NY
                double iNY = iNodalinfo
                             .Select(o => o.Ny).ToList().Sum()
                             / iNodeCount;

                NodalStructureInfo.Except(iNodalinfo);

                SoFiNodesOnSrf[i].StressCom = iComStress;
                SoFiNodesOnSrf[i].StressTen = iTenStress;
                SoFiNodesOnSrf[i].Nx        = iNX;
                SoFiNodesOnSrf[i].Ny        = iNY;
            }
            //List<NodalStructureInfo> CondensedNodalStructureInfo = Utils.CheckDuplicate(NodalStructureInfo);

            // SoFiNode.InfoRead(SoFiNodesOnSrf, CondensedNodalStructureInfo);

            // calculate structure significance
            Fibers.ForEach(o => o.StrutureValue(SoFiNodesOnSrf));

            List <Fiber> CriticleFibers = Fibers
                                          .OrderByDescending(o => o.StructureFactor)
                                          //.Take((int)(Fibers.Count * 0.2))
                                          .ToList();

            // Output
            DA.SetDataList("SoFiNodes", SoFiNodesOnSrf);
            DA.SetDataList("Node Positions", SoFiNodesOnSrf.Select(o => o.Node).ToList());
            DA.SetDataList("Node Number", SoFiNodesOnSrf.Select(o => o.NodeNum).ToList());
            DA.SetDataList("Info Number", CondensedNodalStructureInfo.Select(o => o.NodeNum).ToList());
            DA.SetDataList("Criticle Fibers", CriticleFibers.Select(o => o.FiberCrv).ToList());
            DA.SetDataList("Value", SoFiNodesOnSrf.Select(o => o.StressCom).ToList());
        }
コード例 #31
0
        /// <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)
        {
            Line lineA  = new Line();
            Line lineB  = new Line();
            int  number = 0;

            if (!DA.GetData(0, ref lineA))
            {
                return;
            }
            if (!DA.GetData(1, ref lineB))
            {
                return;
            }
            if (!DA.GetData(2, ref number))
            {
                return;
            }
            double t1 = 0;
            double t2 = 0;

            Rhino.Geometry.Intersect.Intersection.LineLine(lineA, lineB, out t1, out t2);
            Point3d pt1 = lineA.PointAt(t1);
            Point3d pt2 = lineB.PointAt(t2);

            if (number <= 1)
            {
                return;
            }
            if (pt1.DistanceTo(pt2) > 0.0000000001)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "指定的两条直线不共面");
                ///////////////////////////////
                return;
            }
            Point3d start1 = lineA.From;
            Point3d end1   = lineA.To;

            if (lineA.To.DistanceTo(pt1) > lineA.From.DistanceTo(pt1))
            {
                end1   = lineA.From;
                start1 = lineA.To;
            }
            Point3d start2 = lineB.From;
            Point3d end2   = lineB.To;

            if (lineB.To.DistanceTo(pt1) > lineB.From.DistanceTo(pt1))
            {
                end2   = lineB.From;
                start2 = lineB.To;
            }
            Vector3d v1      = Point3d.Subtract(start1, pt1);
            Vector3d v2      = Point3d.Subtract(start2, pt2);
            double   angle   = Vector3d.VectorAngle(v1, v2);
            double   sgement = angle / number;
            ////////////////////////////////////////////////////////////////////等分
            double radius = pt1.DistanceTo(start1);///圆弧半径

            if (radius < pt1.DistanceTo(start2))
            {
                radius = pt1.DistanceTo(start2);
            }
            Plane pln = new Plane(pt1, v1, v2);
            Arc   arc = new Arc(pln, radius, angle);

            Point3d[] pts;
            arc.ToNurbsCurve().DivideByCount(number, false, out pts);///等分点
            ///////////////////////////////////////////////////////////////////////////
            Line        line1   = new Line(start1, start2);
            Line        line2   = new Line(end1, end2);
            List <Line> collect = new List <Line>();

            foreach (Point3d ppp in pts)
            {
                collect.Add(new Line(pt1, ppp));
            }
            ////////////////////////////////////////////////////////////////////
            List <Line> last = new List <Line>();

            for (int i = 0; i < collect.Count; i++)
            {
                Point3d start = pt1;
                if (Rhino.Geometry.Intersect.Intersection.CurveCurve(lineA.ToNurbsCurve(), lineB.ToNurbsCurve(), 0, 0).Count == 0)////输入的两条直线无交点
                {
                    if (Rhino.Geometry.Intersect.Intersection.CurveCurve(line2.ToNurbsCurve(), collect[i].ToNurbsCurve(), 0, 0).Count == 0)
                    {
                        start = pt1;
                    }
                    else
                    {
                        start = Rhino.Geometry.Intersect.Intersection.CurveCurve(line2.ToNurbsCurve(), collect[i].ToNurbsCurve(), 0, 0)[0].PointA;
                    }
                }
                Point3d end = Rhino.Geometry.Intersect.Intersection.CurveCurve(line1.ToNurbsCurve(), collect[i].ToNurbsCurve(), 0, 0)[0].PointA;
                last.Add(new Line(start, end));
            }
            DA.SetDataList(0, last);
        }
コード例 #32
0
        /// <summary>
        /// Cuts the curve between perp indexes.
        /// </summary>
        /// <returns>The curve between perp indexes.</returns>
        /// <param name="g">The green component.</param>
        /// <param name="perpGs">Perp gs.</param>
        /// <param name="index1">Index1.</param>
        /// <param name="index2">Index2.</param>
        public Curve CutCurveBetweenPerpIndexes(Curve g, List <Curve> perpGs, int index1, int index2)
        {
            Curve tempG = g.DuplicateCurve();

            tempG.Domain = new Interval(0, 1);

            CurveIntersections curveInt  = Intersection.CurveCurve(tempG, perpGs[index1], 0.0001, 0.0001);
            CurveIntersections curveInt2 = Intersection.CurveCurve(tempG, perpGs[index2], 0.0001, 0.0001);

            double t1 = tempG.Domain.T0;
            double t2 = tempG.Domain.T1;

            if (curveInt.Count != 0)
            {
                t1 = curveInt[0].ParameterA;
            }
            if (curveInt2.Count != 0)
            {
                t2 = curveInt2[0].ParameterA;
            }

            double tMid;

            if (t1 > t2)
            {
                double temp = t1;
                t1 = t2;
                t2 = temp;
            }
            tMid = (t2 + t1) / 2;

            Point3d midPoint = tempG.PointAt(tMid);

            if (curveInt.Count != 0 && t1 > tempG.Domain.T0)
            {
                Curve[] splitCurves = tempG.Split(t1);
                if (splitCurves != null)
                {
                    foreach (Curve crv in splitCurves)
                    {
                        double closestT;
                        crv.ClosestPoint(midPoint, out closestT);

                        double distance = midPoint.DistanceTo(crv.PointAt(closestT));
                        if (distance < 0.001)
                        {
                            tempG = crv;
                        }
                    }
                }
            }

            tempG.Domain = new Interval(0, 1);
            t2           = tempG.Domain.T1;
            curveInt2    = Intersection.CurveCurve(tempG, perpGs[index2], 0.0001, 0.0001);
            if (curveInt2.Count != 0)
            {
                t2 = curveInt2[0].ParameterA;
            }

            if (curveInt2.Count != 0 && t2 < tempG.Domain.T1 && t2 > 0)
            {
                Curve[] splitCurves = tempG.Split(t2);
                if (splitCurves != null)
                {
                    foreach (Curve crv in splitCurves)
                    {
                        double closestT;
                        crv.ClosestPoint(midPoint, out closestT);

                        double distance = midPoint.DistanceTo(crv.PointAt(closestT));
                        if (distance < 0.001)
                        {
                            tempG = crv;
                        }
                    }
                }
            }


            return(tempG);
        }
コード例 #33
0
        /// <summary>
        /// The internal Zoom() method (credit: AutoCAD .NET Developer's Guide).
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <param name="center"></param>
        /// <param name="factor"></param>
        internal static void Zoom(Point3d min, Point3d max, Point3d center, double factor)
        {
            // Get the current document and database
            var document = Application.DocumentManager.MdiActiveDocument;
            var database = document.Database;

            int currentViewport = Convert.ToInt32(Application.GetSystemVariable("CVPORT"));

            // Get the extents of the current space no points
            // or only a center point is provided
            // Check to see if Model space is current
            if (database.TileMode)
            {
                if (min.Equals(new Point3d()) && max.Equals(new Point3d()))
                {
                    min = database.Extmin;
                    max = database.Extmax;
                }
            }
            else
            {
                // Check to see if Paper space is current
                if (currentViewport == 1)
                {
                    // Get the extents of Paper space
                    if (min.Equals(new Point3d()) && max.Equals(new Point3d()))
                    {
                        min = database.Pextmin;
                        max = database.Pextmax;
                    }
                }
                else
                {
                    // Get the extents of Model space
                    if (min.Equals(new Point3d()) && max.Equals(new Point3d()))
                    {
                        min = database.Extmin;
                        max = database.Extmax;
                    }
                }
            }

            // Start a transaction
            using (var trans = database.TransactionManager.StartTransaction())
            {
                // Get the current view
                using (var currentView = document.Editor.GetCurrentView())
                {
                    Extents3d extents;

                    // Translate WCS coordinates to DCS
                    var matWCS2DCS = Matrix3d.PlaneToWorld(currentView.ViewDirection);
                    matWCS2DCS = Matrix3d.Displacement(currentView.Target - Point3d.Origin) * matWCS2DCS;
                    matWCS2DCS = Matrix3d.Rotation(
                        angle: -currentView.ViewTwist,
                        axis: currentView.ViewDirection,
                        center: currentView.Target) * matWCS2DCS;

                    // If a center point is specified, define the min and max
                    // point of the extents
                    // for Center and Scale modes
                    if (center.DistanceTo(Point3d.Origin) != 0)
                    {
                        min = new Point3d(center.X - (currentView.Width / 2), center.Y - (currentView.Height / 2), 0);
                        max = new Point3d((currentView.Width / 2) + center.X, (currentView.Height / 2) + center.Y, 0);
                    }

                    // Create an extents object using a line
                    using (Line line = new Line(min, max))
                    {
                        extents = new Extents3d(line.Bounds.Value.MinPoint, line.Bounds.Value.MaxPoint);
                    }

                    // Calculate the ratio between the width and height of the current view
                    double viewRatio = currentView.Width / currentView.Height;

                    // Tranform the extents of the view
                    matWCS2DCS = matWCS2DCS.Inverse();
                    extents.TransformBy(matWCS2DCS);

                    double  width;
                    double  height;
                    Point2d newCenter;

                    // Check to see if a center point was provided (Center and Scale modes)
                    if (center.DistanceTo(Point3d.Origin) != 0)
                    {
                        width  = currentView.Width;
                        height = currentView.Height;

                        if (factor == 0)
                        {
                            center = center.TransformBy(matWCS2DCS);
                        }

                        newCenter = new Point2d(center.X, center.Y);
                    }
                    else // Working in Window, Extents and Limits mode
                    {
                        // Calculate the new width and height of the current view
                        width  = extents.MaxPoint.X - extents.MinPoint.X;
                        height = extents.MaxPoint.Y - extents.MinPoint.Y;

                        // Get the center of the view
                        newCenter = new Point2d(
                            ((extents.MaxPoint.X + extents.MinPoint.X) * 0.5),
                            ((extents.MaxPoint.Y + extents.MinPoint.Y) * 0.5));
                    }

                    // Check to see if the new width fits in current window
                    if (width > (height * viewRatio))
                    {
                        height = width / viewRatio;
                    }

                    // Resize and scale the view
                    if (factor != 0)
                    {
                        currentView.Height = height * factor;
                        currentView.Width  = width * factor;
                    }

                    // Set the center of the view
                    currentView.CenterPoint = newCenter;

                    // Set the current view
                    document.Editor.SetCurrentView(currentView);
                }

                // Commit the changes
                trans.Commit();
            }
        }
コード例 #34
0
        public void ComputeDesiredVelocity(List <FlockAgent> neighbours)
        {
            // First, reset the desired velocity to 0
            desiredVelocity = new Vector3d(0.0, 0.0, 0.0);
            var bounceMultiplier = 30;

            // ===============================================================================
            // Pull the agent back if it gets out of the bounding box
            // ===============================================================================

            //double boundingBoxSize = 30.0;

            //if (Position.X < FlockSystem.Min.X)
            //    desiredVelocity += new Vector3d((FlockSystem.Max.X - Position.X) * bounceMultiplier, FlockSystem.Min.Y, FlockSystem.Min.Z);

            //else if (Position.X > FlockSystem.Max.X)
            //    desiredVelocity += new Vector3d(-Position.X * bounceMultiplier, FlockSystem.Min.Y, FlockSystem.Min.Z);


            //if (Position.Y < FlockSystem.Min.Y)
            //    desiredVelocity += new Vector3d(FlockSystem.Min.X, (FlockSystem.Max.Y - Position.Y) * bounceMultiplier, FlockSystem.Min.Z);

            //else if (Position.Y > FlockSystem.Max.Y)
            //    desiredVelocity += new Vector3d(FlockSystem.Min.X, (-Position.Y) * bounceMultiplier, FlockSystem.Min.Z);


            //if (Position.Z < FlockSystem.Min.Z)
            //desiredVelocity += new Vector3d(FlockSystem.Min.X, FlockSystem.Min.Y, FlockSystem.Max.Z - Position.Z);

            //else if (Position.Z > FlockSystem.Max.Z)
            //    desiredVelocity += new Vector3d(FlockSystem.Min.X, FlockSystem.Min.Y, -Position.Z);

            if (!FlockSystem.Brep.IsPointInside(Position, 0.01, false))
            {
                desiredVelocity += new Vector3d(-Position.X * bounceMultiplier, -Position.Y * bounceMultiplier, -Position.Z * bounceMultiplier);
            }


            // ===============================================================================
            // If there are no neighbours nearby, the agent will maintain its veloctiy,
            // else it will perform the "alignment", "cohension" and "separation" behaviours
            // ===============================================================================

            if (neighbours.Count == 0)
            {
                desiredVelocity += Velocity; // maintain the current velocity
            }
            else
            {
                // -------------------------------------------------------------------------------
                // "Alignment" behavior
                // -------------------------------------------------------------------------------

                Vector3d alignment = Vector3d.Zero;

                foreach (FlockAgent neighbour in neighbours)
                {
                    alignment += neighbour.Velocity;
                }

                // We divide by the number of neighbours to actually get their average velocity
                alignment /= neighbours.Count;

                desiredVelocity += FlockSystem.AlignmentStrength * alignment;


                // -------------------------------------------------------------------------------
                // "Cohesion" behavior
                // -------------------------------------------------------------------------------

                Point3d centre = Point3d.Origin;

                foreach (FlockAgent neighbour in neighbours)
                {
                    centre += neighbour.Position;
                }

                // We divide by the number of neighbours to actually get their centre of mass
                centre /= neighbours.Count;

                Vector3d cohesion = centre - Position;

                desiredVelocity += FlockSystem.CohesionStrength * cohesion;


                // -------------------------------------------------------------------------------
                // "Separation" behavior
                // -------------------------------------------------------------------------------

                Vector3d separation = Vector3d.Zero;

                foreach (FlockAgent neighbour in neighbours)
                {
                    double distanceToNeighbour = Position.DistanceTo(neighbour.Position);

                    if (distanceToNeighbour < FlockSystem.SeparationDistance)
                    {
                        Vector3d getAway = Position - neighbour.Position;

                        /* We scale the getAway vector by inverse of distanceToNeighbour to make
                         * the getAway vector bigger as the agent gets closer to its neighbour */
                        separation += getAway / (getAway.Length * distanceToNeighbour);
                    }
                }

                desiredVelocity += FlockSystem.SeparationStrength * separation;
            }


            // ===============================================================================
            // Avoiding the obstacles (repellers)
            // ===============================================================================

            foreach (Circle repeller in FlockSystem.Repellers)
            {
                double distanceToRepeller = Position.DistanceTo(repeller.Center);

                Vector3d repulsion = Position - repeller.Center;

                // Repulstion gets stronger as the agent gets closer to the repeller
                repulsion /= (repulsion.Length * distanceToRepeller);

                // Repulsion strength is also proportional to the radius of the repeller circle/sphere
                // This allows the user to tweak the repulsion strength by tweaking the radius
                repulsion *= 30.0 * repeller.Radius;

                desiredVelocity += repulsion;
            }
        }
コード例 #35
0
        public bool subdivideBlocks(urbanModel model, int minPlotDepth, int maxPlotWidth)
        {
            //check dimensions, find shorter dim, validate if it needs to be subdivided, (if minPLotDepth can be achieved, depth > minPlotDepth * 2)
            //if so subdivide halfway, then into smaller plots based on maxPlot width

            foreach (block itBlock in model.blocks)
            {
                Brep itSrf = itBlock.blockSrf;                                         // to get itBlock surface as Brep (use class or object outside this class urbSim, by accessing from and assigning to fields / properties / attributes)
                itBlock.plots = new List <plot>();                                     //so this is where plots are linked to block; plots assigned to block object, not to model object

                Curve[] blockBorderCrvs = itSrf.DuplicateNakedEdgeCurves(true, false); //border curves of each itBlock

                List <Curve> splitLines = new List <Curve>();

                itSrf.Faces[0].SetDomain(0, new Interval(0, 1)); //reparameterise surface U and V, so domains 0 - 1
                itSrf.Faces[0].SetDomain(1, new Interval(0, 1));

                Point3d pt1 = itSrf.Faces[0].PointAt(0, 0);
                Point3d pt2 = itSrf.Faces[0].PointAt(0, 1);
                Point3d pt3 = itSrf.Faces[0].PointAt(1, 1);
                Point3d pt4 = itSrf.Faces[0].PointAt(1, 0);

                double length = pt1.DistanceTo(pt2);
                double width  = pt1.DistanceTo(pt4);

                Point3d sdPt1 = new Point3d();
                Point3d sdPt2 = new Point3d();

                if (length > width)
                {
                    if (width > (minPlotDepth * 2)) //suitable for subdivision
                    {
                        //create a subdividing line
                        sdPt1 = itSrf.Faces[0].PointAt(0.5, 0); //
                        sdPt2 = itSrf.Faces[0].PointAt(0.5, 1);
                    }
                }
                else //if width is wider
                {
                    if (length > (minPlotDepth * 2))
                    {
                        sdPt1 = itSrf.Faces[0].PointAt(0, 0.5);
                        sdPt2 = itSrf.Faces[0].PointAt(1, 0.5);
                    }
                }

                Line  subDLine = new Line(sdPt1, sdPt2);
                Curve subDCrv  = subDLine.ToNurbsCurve();

                splitLines.Add(subDCrv);

                double crvLength = subDCrv.GetLength();
                double noPlots   = Math.Floor(crvLength / maxPlotWidth);

                for (int t = 0; t < noPlots; t++)
                {
                    double tVal = t * 1 / noPlots; //t is 0, 0.2, 0.4 ... 1

                    Plane perpFrm;

                    Point3d evalPt = subDCrv.PointAtNormalizedLength(tVal);
                    subDCrv.PerpendicularFrameAt(tVal, out perpFrm);

                    //inpCrv.PerpendicularFrameAt(t, out perpFrm) 'out perpFrm' assigns to the variable perpFrm

                    Point3d ptPer2Up   = Point3d.Add(evalPt, perpFrm.XAxis);
                    Point3d ptPer2Down = Point3d.Add(evalPt, -perpFrm.XAxis);

                    //Draw a line perpendicular
                    Line ln1 = new Line(evalPt, ptPer2Up);
                    Line ln2 = new Line(evalPt, ptPer2Down);

                    Curve lnExt1 = ln1.ToNurbsCurve().ExtendByLine(CurveEnd.End, blockBorderCrvs); //lnExt extended to all border curves in inObst (4 boundaries plus new lnExt)
                    Curve lnExt2 = ln2.ToNurbsCurve().ExtendByLine(CurveEnd.End, blockBorderCrvs);

                    splitLines.Add(lnExt1);
                    splitLines.Add(lnExt2);
                }

                Brep plotPolySurface = itSrf.Faces[0].Split(splitLines, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);  //split face using 3D trimming curves

                foreach (BrepFace itBF in plotPolySurface.Faces)
                {
                    Brep itPlot = itBF.DuplicateFace(false);           // a collection of Brep faces
                    itPlot.Faces.ShrinkFaces();
                    itBlock.plots.Add(new plot(itPlot, itBlock.type)); //plots assigned to block object as list of Breps // this syntax, for assigning to a list outside of this class and into urbSim.block.plots
                    //itBlock.type takes integer value from 'block' object and assigns same value to 'plot' object
                    //RhinoDoc.ActiveDoc.Objects.AddBrep(itPlot);
                }
            }

            return(true);
        }
コード例 #36
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <Curve> C_ = NGonsCore.Clipper.DataAccessHelper.FetchList <Curve>(DA, "Curves");

            double         T = NGonsCore.Clipper.DataAccessHelper.Fetch <double>(DA, "Tolerance");
            List <Point3d> P = NGonsCore.Clipper.DataAccessHelper.FetchList <Point3d>(DA, "Points");

            List <Curve> curves = new List <Curve>();

            if (P.Count > 0)
            {
                for (int i = 0; i < C_.Count; i++)
                {
                    Curve      C     = C_[i].DuplicateCurve();
                    PointCloud cloud = new PointCloud(P);

                    double tol = (T == 0.0) ? C.GetLength() * 0.5 : T;

                    Point3d p0 = cloud.PointAt(cloud.ClosestPoint(C.PointAtStart));
                    Point3d p1 = cloud.PointAt(cloud.ClosestPoint(C.PointAtEnd));

                    if (p0.DistanceTo(C.PointAtStart) < tol)
                    {
                        C.SetStartPoint(p0);
                    }

                    if (p1.DistanceTo(C.PointAtEnd) < tol)
                    {
                        C.SetEndPoint(p1);
                    }
                    curves.Add(C);
                }
            }
            else
            {
                PointCloud cloud = new PointCloud();
                double     tol   = (T == 0.0) ? 0.01 : T;
                base.Message = tol.ToString();

                //Add start and end point to pointcloud with incrementing nornal if point already exists
                for (int i = 0; i < C_.Count; i++)
                {
                    if (i == 0)
                    {
                        cloud.Add(C_[i].PointAtStart, new Vector3d(0, 0, 1));
                        cloud.Add(C_[i].PointAtEnd, new Vector3d(0, 0, 1));
                    }
                    else
                    {
                        int  cp0   = cloud.ClosestPoint(C_[i].PointAtStart);
                        bool flag0 = cloud.PointAt(cp0).DistanceToSquared(C_[i].PointAtStart) < tol;
                        if (flag0)
                        {
                            cloud[cp0].Normal = new Vector3d(0, 0, cloud[cp0].Normal.Z + 1);
                        }
                        else
                        {
                            cloud.Add(C_[i].PointAtStart, new Vector3d(0, 0, 1));
                        }

                        int  cp1   = cloud.ClosestPoint(C_[i].PointAtEnd);
                        bool flag1 = cloud.PointAt(cp1).DistanceToSquared(C_[i].PointAtEnd) < tol;
                        if (flag1)
                        {
                            cloud[cp1].Normal = new Vector3d(0, 0, cloud[cp1].Normal.Z + 1);
                        }
                        else
                        {
                            cloud.Add(C_[i].PointAtEnd, new Vector3d(0, 0, 1));
                        }
                    }
                }//for

                //List<Curve> curves = new List<Curve>();
                for (int i = 0; i < C_.Count; i++)
                {
                    //Print(cloud[cloud.ClosestPoint(C[i].PointAtStart)].Normal.Z.ToString() + " " + cloud[cloud.ClosestPoint(C[i].PointAtEnd)].Normal.Z.ToString());
                    int  a     = cloud.ClosestPoint(C_[i].PointAtStart);
                    int  b     = cloud.ClosestPoint(C_[i].PointAtEnd);
                    bool flag0 = cloud[a].Normal.Z != 1;
                    bool flag1 = cloud[b].Normal.Z != 1;

                    Curve c = C_[i].DuplicateCurve();
                    if (flag0)
                    {
                        c.SetStartPoint(cloud[a].Location);
                    }
                    if (flag1)
                    {
                        c.SetEndPoint(cloud[b].Location);
                    }
                    curves.Add(c);
                }
            }


            DA.SetDataList(0, curves);
        }
コード例 #37
0
ファイル: CraneLibrary.cs プロジェクト: KaiSut0/Crane020
        public CMesh(Mesh _mesh, List <Line> M, List <Line> V, List <Line> T)
        {
            this.mesh = _mesh.DuplicateMesh();
            this.mesh.FaceNormals.ComputeFaceNormals();
            this.orig_faces = _mesh.Faces;
            var tri = this.InsertTriangulate();

            var edges = mesh.TopologyEdges;
            var verts = mesh.TopologyVertices;

            this.edgeInfo = new List <Char>();
            for (int i = 0; i < edges.Count; i++)
            {
                if (edges.IsNgonInterior(i))
                {
                    edgeInfo.Add('T');
                }
                else
                {
                    edgeInfo.Add('U');
                }
            }

            foreach (Line m in M)
            {
                Point3d a = m.From;
                Point3d b = m.To;

                int found      = 0;
                int vertsCount = verts.Count;
                int j          = 0;
                int fromIndex  = -1;
                int toIndex    = -1;
                while (found != 2 && j < vertsCount)
                {
                    Point3d p = verts[j];

                    if (p.DistanceTo(a) < 0.1)
                    {
                        fromIndex = j;
                        found++;
                    }
                    else if (p.DistanceTo(b) < 0.1)
                    {
                        toIndex = j;
                        found++;
                    }
                    j++;
                }
                int ind = edges.GetEdgeIndex(fromIndex, toIndex);
                if (ind != -1)
                {
                    edgeInfo[ind] = 'M';
                }
            }
            foreach (Line v in V)
            {
                Point3d a = v.From;
                Point3d b = v.To;

                int found      = 0;
                int vertsCount = verts.Count;
                int j          = 0;
                int fromIndex  = -1;
                int toIndex    = -1;
                while (found != 2 && j < vertsCount)
                {
                    Point3d p = verts[j];

                    if (p.DistanceTo(a) < 0.1)
                    {
                        fromIndex = j;
                        found++;
                    }
                    else if (p.DistanceTo(b) < 0.1)
                    {
                        toIndex = j;
                        found++;
                    }
                    j++;
                }
                int ind = edges.GetEdgeIndex(fromIndex, toIndex);
                if (ind != -1)
                {
                    edgeInfo[ind] = 'V';
                }
            }
            if (tri.Count != 0)
            {
                foreach (List <int> v in tri)
                {
                    int ind = edges.GetEdgeIndex(v[0], v[1]);
                    if (ind != -1)
                    {
                        this.edgeInfo[ind] = 'T';
                    }
                }
            }

            foreach (Line t in T)
            {
                Point3d a = t.From;
                Point3d b = t.To;

                int found      = 0;
                int vertsCount = verts.Count;
                int j          = 0;
                int fromIndex  = -1;
                int toIndex    = -1;
                while (found != 2 && j < vertsCount)
                {
                    Point3d p = verts[j];

                    if (p.DistanceTo(a) < 0.1)
                    {
                        fromIndex = j;
                        found++;
                    }
                    else if (p.DistanceTo(b) < 0.1)
                    {
                        toIndex = j;
                        found++;
                    }
                    j++;
                }
                int ind = edges.GetEdgeIndex(fromIndex, toIndex);
                if (ind != -1)
                {
                    edgeInfo[ind] = 'T';
                }
            }

            List <bool> naked = new List <bool>(_mesh.GetNakedEdgePointStatus());

            for (int i = 0; i < mesh.TopologyEdges.Count; i++)
            {
                if (edges.GetConnectedFaces(i).Count() == 1)
                {
                    this.edgeInfo[i] = 'B';
                }
            }
            GetMeshFundamentalInfo();
            GetTriangulatedFacePairBasicInfo(this);
            GetMountainFacePairBasicInfo(this);
            GetValleyFacePairBasicInfo(this);
            this.inner_edge_assignment = GetInnerEdgeAssignment();
        }
コード例 #38
0
        public static bool IsEatable(Point3d food)
        {
            //find closest particle to food
            double closest_distance = double.MaxValue;
            Particle p_closest = null;

            /// GET KEY-ZONES FOR FOOD (0/+/- X,Y,Z)
            /// FOR EACH ZONES - IF EXISTS, FIND CLOSEST PARTICLE

            List<string> zones = GetZones(food);
            foreach (string zone_id in zones)
            {
                List<Particle> zone;
                if (Zones.TryGetValue(zone_id, out zone))
                {
                    for (int i = 0; i < zone.Count(); i++)
                    {
                        double actual_distance = food.DistanceTo(zone[i].Position);
                        if (actual_distance < closest_distance)
                        {
                            p_closest = zone[i];
                            closest_distance = actual_distance;
                            //if (closest_distance < infuence_distance * 0.2)
                                //continue;
                        }
                    }
                }
            }

            //===: closest particle is particle with index x in the field
            /// STORE AS A LINK TO THE PARTICLE - THEN TARGET FOOD

            //if food is too close - eat it, otherwise target it
            if (closest_distance <= eatable_distance)
                return true;
            else
            {
                if (closest_distance <= infuence_distance)
                {
                    p_closest.TargetFood(food, infuence_distance - closest_distance); //(infuence_distance - closest_distance) as factor
                    Temp.Add(p_closest);
                }
                //prepare to move
                return false;
            }
        }
コード例 #39
0
ファイル: StaticFunctions.cs プロジェクト: KaVisscher/MiStrAn
        public static Mesh CullMesh(Mesh input, double tol, out int[] culledFaces)
        {
            if (tol == 0)
            {
                return(CullMeshExact(input, out culledFaces));
            }

            Mesh           output    = new Mesh();
            List <Point3d> culledPts = new List <Point3d>();

            int[]      indexMap     = new int[input.Vertices.Count];
            List <int> _culledFaces = new List <int>();

            for (int i = 0; i < input.Vertices.Count; i++)
            {
                Point3d inputPt = input.Vertices[i];
                int     index   = -1;
                for (int j = 0; j < culledPts.Count; j++)
                {
                    if (inputPt.DistanceTo(culledPts[j]) < tol)
                    {
                        index = j;
                        break;
                    }
                }

                if (index != -1)
                {
                    indexMap[i] = index;
                }
                else
                {
                    culledPts.Add(inputPt);
                    indexMap[i] = culledPts.Count - 1;
                }
            }


            output.Vertices.AddVertices(culledPts);

            for (int i = 0; i < input.Faces.Count; i++)
            {
                MeshFace face = new MeshFace();
                face.A = indexMap[input.Faces[i].A];
                face.B = indexMap[input.Faces[i].B];
                face.C = indexMap[input.Faces[i].C];
                face.D = indexMap[input.Faces[i].D];

                double area = GetFaceArea(output, face);

                if (area > 1e-5)
                {
                    output.Faces.AddFace(face);
                }
                else
                {
                    _culledFaces.Add(i);
                }
            }

            culledFaces = _culledFaces.ToArray();
            return(output);
        }
コード例 #40
0
 private bool CursorHasMoved()
 {
     return(_currentPoint.DistanceTo(_prevPoint) > 1e-3);
 }
コード例 #41
0
        private (List <List <Point3d> >, List <List <int> >, List <List <Line> >, List <List <Brep> >, List <Node>, List <Element>, List <Point3d>) CreateMesh(Point3d[] cornerNodes, int u, int v, int w)
        {
            //Output-lists
            List <List <int> >     globalConnectivity = new List <List <int> >();
            List <List <Point3d> > hexPoints          = new List <List <Point3d> >();
            List <List <Line> >    edgeMesh           = new List <List <Line> >();
            List <List <Brep> >    surfacesMesh       = new List <List <Brep> >();
            List <Node>            nodes        = new List <Node>();
            List <Element>         elements     = new List <Element>();
            List <Point3d>         globalPoints = new List <Point3d>();

            //Distances in w-direction after dividing in w elements
            double lz1 = (cornerNodes[0].DistanceTo(cornerNodes[4])) / w;
            double lz2 = (cornerNodes[1].DistanceTo(cornerNodes[5])) / w;
            double lz3 = (cornerNodes[2].DistanceTo(cornerNodes[6])) / w;
            double lz4 = (cornerNodes[3].DistanceTo(cornerNodes[7])) / w;

            Vector3d vec_z1 = (cornerNodes[4] - cornerNodes[0]) / (cornerNodes[0].DistanceTo(cornerNodes[4]));
            Vector3d vec_z2 = (cornerNodes[5] - cornerNodes[1]) / (cornerNodes[1].DistanceTo(cornerNodes[5]));
            Vector3d vec_z3 = (cornerNodes[6] - cornerNodes[2]) / (cornerNodes[2].DistanceTo(cornerNodes[6]));
            Vector3d vec_z4 = (cornerNodes[7] - cornerNodes[3]) / (cornerNodes[3].DistanceTo(cornerNodes[7]));

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

            for (int i = 0; i <= w; i++)
            {
                //Creating points in w-direction
                Point3d p1_w = new Point3d(cornerNodes[0].X + lz1 * i * vec_z1.X, cornerNodes[0].Y + lz1 * vec_z1.Y * i, cornerNodes[0].Z + lz1 * vec_z1.Z * i);
                Point3d p2_w = new Point3d(cornerNodes[1].X + lz2 * i * vec_z2.X, cornerNodes[1].Y + lz2 * vec_z2.Y * i, cornerNodes[1].Z + lz2 * vec_z2.Z * i);

                Point3d p3_w = new Point3d(cornerNodes[2].X + lz3 * i * vec_z3.X, cornerNodes[2].Y + lz3 * vec_z3.Y * i, cornerNodes[2].Z + lz3 * vec_z3.Z * i);
                Point3d p4_w = new Point3d(cornerNodes[3].X + lz4 * i * vec_z4.X, cornerNodes[3].Y + lz4 * vec_z4.Y * i, cornerNodes[3].Z + lz4 * vec_z4.Z * i);

                Vector3d vecV1 = (p4_w - p1_w) / (p1_w.DistanceTo(p4_w));
                Vector3d vecV2 = (p3_w - p2_w) / (p2_w.DistanceTo(p3_w));

                Double length_v1 = p1_w.DistanceTo(p4_w) / v;
                Double length_v2 = p2_w.DistanceTo(p3_w) / v;

                for (int j = 0; j <= v; j++)
                {
                    //Creating points in v-direction
                    Point3d p1_v = new Point3d(p1_w.X + length_v1 * j * vecV1.X, p1_w.Y + length_v1 * j * vecV1.Y, p1_w.Z + length_v1 * j * vecV1.Z);
                    Point3d p2_v = new Point3d(p2_w.X + length_v2 * j * vecV2.X, p2_w.Y + length_v2 * j * vecV2.Y, p2_w.Z + length_v2 * j * vecV2.Z);

                    Vector3d vec_u1 = (p2_v - p1_v) / (p1_v.DistanceTo(p2_v));

                    Double length_u1 = p1_v.DistanceTo(p2_v) / u;

                    for (int k = 0; k <= u; k++)
                    {
                        //Creating points in u-direction and adding them to the global nodes.
                        Point3d p1_u = new Point3d(p1_v.X + length_u1 * k * vec_u1.X, p1_v.Y + length_u1 * k * vec_u1.Y, p1_v.Z + length_u1 * k * vec_u1.Z);
                        globalPoints.Add(p1_u);

                        //Create node instance of point created
                        Node node = new Node(p1_u, globalPoints.IndexOf(p1_u));

                        SetNodePosition(node, p1_u, cornerNodes, i, j, k, u, v, w);
                        SetNodeSurface(node, i, j, k, u, v, w);
                        nodes.Add(node);
                    }
                }
            }

            // Putting together Hex elements:

            List <int> jumpOne = new List <int>(); // List with points where it must move in v-direction
            List <int> jumpUp  = new List <int>(); // List with points where it must move upwards w-direction


            //Finding indexes for jumping in v-direction
            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < v - 1; j++)
                {
                    jumpOne.Add((u - 1) + j * (u + 1) + (u + 1) * (v + 1) * i);
                }
            }

            //Finding indexes for jumping in w-direction
            for (int i = 0; i < w; i++)
            {
                jumpUp.Add((u + 1) * (v + 1) - (u + 1) - 2 + (u + 1) * (v + 1) * i);
            }

            int counter = 0;

            for (int i = 0; i < u * v * w; i++) // Creating u*v*w hexahedron having the 8 corner points
            {
                //Putting together 8 points to create hex
                List <Point3d> hex = new List <Point3d>()
                {
                    globalPoints[counter],
                    globalPoints[(u + 1) + (counter)],
                    globalPoints[(u + 1) + (counter + 1)],
                    globalPoints[counter + 1],
                    globalPoints[(u + 1) * (v + 1) + counter],
                    globalPoints[(u + 1) * (v + 1) + (u + 1) + (counter)],
                    globalPoints[(u + 1) * (v + 1) + (u + 1) + (counter + 1)],
                    globalPoints[(u + 1) * (v + 1) + (counter + 1)],
                };

                hexPoints.Add(hex);

                //Putting together 8 nodes to craete hex
                List <Node> hexNodes = new List <Node>()
                {
                    nodes[counter],
                    nodes[(u + 1) + (counter)],
                    nodes[(u + 1) + (counter + 1)],
                    nodes[counter + 1],
                    nodes[(u + 1) * (v + 1) + counter],
                    nodes[(u + 1) * (v + 1) + (u + 1) + (counter)],
                    nodes[(u + 1) * (v + 1) + (u + 1) + (counter + 1)],
                    nodes[(u + 1) * (v + 1) + (counter + 1)],
                };

                //Adding element number to each node which is part of the element
                nodes[counter].AddElementNr(i);
                nodes[(u + 1) + (counter)].AddElementNr(i);
                nodes[(u + 1) + (counter + 1)].AddElementNr(i);
                nodes[counter + 1].AddElementNr(i);
                nodes[(u + 1) * (v + 1) + counter].AddElementNr(i);
                nodes[(u + 1) * (v + 1) + (u + 1) + (counter)].AddElementNr(i);
                nodes[(u + 1) * (v + 1) + (u + 1) + (counter + 1)].AddElementNr(i);
                nodes[(u + 1) * (v + 1) + (counter + 1)].AddElementNr(i);

                List <Line> edgesElement    = CreateEdgesMesh(hex);
                List <Brep> surfacesElement = CreateSurfaceMesh(hex);

                edgeMesh.Add(edgesElement);
                surfacesMesh.Add(surfacesElement);

                //Showing the connectivity between local and global nodes
                List <int> connectivity = new List <int>()
                {
                    counter,
                    (u + 1) + (counter),
                    (u + 1) + (counter + 1),
                    counter + 1,
                    (u + 1) * (v + 1) + counter,
                    (u + 1) * (v + 1) + (u + 1) + (counter),
                    (u + 1) * (v + 1) + (u + 1) + (counter + 1),
                    (u + 1) * (v + 1) + (counter + 1),
                };

                Element element = new Element(hexNodes, i, connectivity);
                elements.Add(element);

                globalConnectivity.Add(connectivity);

                //Checking if we need to move to next row
                if (jumpOne.Contains(counter))
                {
                    counter += 1;
                }


                //Checking if we need to move to next level
                if (jumpUp.Contains(counter))
                {
                    counter += (u + 2);
                }

                counter++;
            }

            return(hexPoints, globalConnectivity, edgeMesh, surfacesMesh, nodes, elements, globalPoints);
        }
コード例 #42
0
        public static void Zoom(Point3d pMin, Point3d pMax, Point3d pCenter, double dFactor)
        {
            // Get the current document and database
            Document acDoc     = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb   = HostApplicationServices.WorkingDatabase;
            int      nCurVport = System.Convert.ToInt32(Application.GetSystemVariable("CVPORT"));

            // Get the extents of the current space no points
            // or only a center point is provided
            // Check to see if Model space is current
            if (acCurDb.TileMode == true)
            {
                if (pMin.Equals(new Point3d()) == true &&
                    pMax.Equals(new Point3d()) == true)
                {
                    pMin = acCurDb.Extmin;
                    pMax = acCurDb.Extmax;
                }
            }
            else
            {
                // Check to see if Paper space is current
                if (nCurVport == 1)
                {
                    // Get the extents of Paper space
                    if (pMin.Equals(new Point3d()) == true &&
                        pMax.Equals(new Point3d()) == true)
                    {
                        pMin = acCurDb.Pextmin;
                        pMax = acCurDb.Pextmax;
                    }
                }
                else
                {
                    // Get the extents of Model space
                    if (pMin.Equals(new Point3d()) == true &&
                        pMax.Equals(new Point3d()) == true)
                    {
                        pMin = acCurDb.Extmin;
                        pMax = acCurDb.Extmax;
                    }
                }
            }
            // Start a transaction
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Get the current view
                using (ViewTableRecord acView = acDoc.Editor.GetCurrentView())
                {
                    Extents3d eExtents;
                    // Translate WCS coordinates to DCS
                    Matrix3d matWCS2DCS;
                    matWCS2DCS = Matrix3d.PlaneToWorld(acView.ViewDirection);
                    matWCS2DCS = Matrix3d.Displacement(acView.Target - Point3d.Origin) * matWCS2DCS;
                    matWCS2DCS = Matrix3d.Rotation(-acView.ViewTwist,
                                                   acView.ViewDirection,
                                                   acView.Target) * matWCS2DCS;
                    // If a center point is specified, define the min and max
                    // point of the extents
                    // for Center and Scale modes
                    if (pCenter.DistanceTo(Point3d.Origin) != 0)
                    {
                        pMin = new Point3d(pCenter.X - (acView.Width / 2),
                                           pCenter.Y - (acView.Height / 2), 0);
                        pMax = new Point3d((acView.Width / 2) + pCenter.X,
                                           (acView.Height / 2) + pCenter.Y, 0);
                    }
                    // Create an extents object using a line
                    using (Line acLine = new Line(pMin, pMax))
                    {
                        eExtents = new Extents3d(acLine.GeometricExtents.MinPoint,
                                                 acLine.GeometricExtents.MaxPoint);
                    }
                    // Calculate the ratio between the width and height of the current view
                    double dViewRatio;
                    dViewRatio = (acView.Width / acView.Height);
                    // Tranform the extents of the view
                    matWCS2DCS = matWCS2DCS.Inverse();
                    eExtents.TransformBy(matWCS2DCS);
                    double  dWidth;
                    double  dHeight;
                    Point2d pNewCentPt;
                    // Check to see if a center point was provided (Center and Scale modes)
                    if (pCenter.DistanceTo(Point3d.Origin) != 0)
                    {
                        dWidth  = acView.Width;
                        dHeight = acView.Height;
                        if (dFactor == 0)
                        {
                            pCenter = pCenter.TransformBy(matWCS2DCS);
                        }
                        pNewCentPt = new Point2d(pCenter.X, pCenter.Y);
                    }
                    else                     // Working in Window, Extents and Limits mode
                    {
                        // Calculate the new width and height of the current view
                        dWidth  = eExtents.MaxPoint.X - eExtents.MinPoint.X;
                        dHeight = eExtents.MaxPoint.Y - eExtents.MinPoint.Y;
                        // Get the center of the view
                        pNewCentPt = new Point2d(((eExtents.MaxPoint.X + eExtents.MinPoint.X) * 0.5),
                                                 ((eExtents.MaxPoint.Y + eExtents.MinPoint.Y) * 0.5));
                    }
                    // Check to see if the new width fits in current window
                    if (dWidth > (dHeight * dViewRatio))
                    {
                        dHeight = dWidth / dViewRatio;
                    }
                    // Resize and scale the view
                    if (dFactor != 0)
                    {
                        acView.Height = dHeight * dFactor;
                        acView.Width  = dWidth * dFactor;
                    }
                    // Set the center of the view
                    acView.CenterPoint = pNewCentPt;
                    // Set the current view
                    acDoc.Editor.SetCurrentView(acView);
                }
                // Commit the changes
                acTrans.Commit();
            }
        }
コード例 #43
0
ファイル: graph2.cs プロジェクト: panhao4812/ClassLibrary1
    /// <summary>
    /// This procedure contains the user code. Input parameters are provided as regular arguments,
    /// Output parameters as ref arguments. You don't have to assign output parameters,
    /// they will have a default value.
    /// </summary>
    private void RunScript(List<Line> x, Point3d y, ref object A, ref object B, ref object C)
    {
        try
        {
          /////-------------------------------------------------------------------
          // <Custom additional code>
          List<IndexPair> id = new List<IndexPair>();
          List<Vertice> vs = new List<Vertice>();
          id.Add(new IndexPair(0, 1));
          ////////////////////////////////////////////////////
          vs.Add(new Vertice(x[0].From, 1));
          vs.Add(new Vertice(x[0].To, 0));
          for (int i = 1; i < x.Count; i++)
          {
        bool sign1 = true;
        bool sign2 = true;
        int a = 0, b = 0;
        for (int j = 0; j < vs.Count; j++)
        {
          if (vs[j].equalTo(x[i].From)) { sign1 = false; a = j; }
          if (vs[j].equalTo(x[i].To)) { sign2 = false; b = j; }
          if (!sign1 && !sign2) { break; }
        }
        if (sign1) { vs.Add(new Vertice(x[i].From)); a = vs.Count - 1; }
        if (sign2) { vs.Add(new Vertice(x[i].To)); b = vs.Count - 1; }
        vs[a].Add(b); vs[b].Add(a);
        id.Add(new IndexPair(a, b));
          }
          for (int j = 0; j < vs.Count; j++)
          {
        vs[j].cleanRefer();
          }

          id.Sort(CompareDinosByLength2);
          List<Line> output1 = new   List<Line>();
          for(int i = 0;i < id.Count;i++){
        output1.Add(new Line(vs[id[i].I].pos, vs[id[i].J].pos));
          }

          for (int j = 0; j < vs.Count; j++)
          {
        if (vs[j].refer.Count == 1) { vs[j].energe = 1; }
        if(y.DistanceTo(vs[j].pos) < 0.01){vs[j].energe = 0;signStart = j;}
          }
          for (int i = 0; i < 12; i++)
          {
        bool sign = true;
        for (int j = 0; j < vs.Count; j++)
        {
          if (Vertice.Spread(ref vs, j)) sign = false;
        }
        if (sign) break;
          }
          //////
          loop(ref vs, signStart);
          //////
          List<Point3d> out1 = new List<Point3d>();
          List<string> out2 = new List<string>();
           /*   for (int j = 0; j < id.Count; j++)
          {
        double e1 = vs[id[j].I].energe;
        double e2 = vs[id[j].J].energe;
        double t = e1;
        if(t > e2)t = e2;
        if(t > 50)t = 50;
        out2.Add(t);
        out1.Add((vs[id[j].I].pos + vs[id[j].J].pos) / 2);
          }
          */
         // vs.Sort(CompareDinosByLength);检测用,使用后id失效
          for (int j = 0; j < vs.Count; j++)
          {
        out2.Add(vs[j].Sequece.ToString());
        out1.Add(vs[j].pos);
          }

          A = out1; B = out2;C = output1;
          ////---------------------------------------------------------------------
        }
        catch (Exception ex)
        {
          Print(ex.ToString());
        }
    }
コード例 #44
0
 /// <summary>
 /// Constructor which takes Rhino point input.
 /// </summary>
 /// <param name="Center"></param>
 /// <param name="SrcCenter"></param>
 /// <param name="room"></param>
 /// <param name="RCT"></param>
 /// <param name="C_Sound_in"></param>
 /// <param name="SampleRate_in"></param>
 /// <param name="COTime_in"></param>
 public Spherical_Receiver(Point3d Center, Point3d SrcCenter, double[] Attenuation, double C_Sound_in, double rho, int SampleRate_in, double COTime_in)
 {
     D_Length = Center.DistanceTo(SrcCenter);
     Radius = 1;
     Radius2 = Radius * Radius;
     SampleRate = SampleRate_in;
     CO_Time = COTime_in;
     H_Origin = new Hare.Geometry.Point(Center.X, Center.Y, Center.Z);
     Sound_Speed = C_Sound_in;
     Rho_C = C_Sound_in * rho;
     Atten = new double[8];
     for (int o = 0; o < 8; o++) Atten[o] = Attenuation[o] * 2;
     SizeMod = 1 / Math.PI;
     Recs = new Directional_Histogram(SampleRate, CO_Time);
 }
コード例 #45
0
        internal static List <MeshData> SolidInfoForCollection(Document doc, Point3d camPos, ObjectIdCollection ids)
        {
            var sols = new List <MeshData>();

            using (var tr = doc.TransactionManager.StartOpenCloseTransaction())
            {
                foreach (ObjectId id in ids)
                {
                    Entity ent = tr.GetObject(id, OpenMode.ForRead) as Entity;

                    // Entity handle to name the Three.js objects
                    String hand = ent.Handle.ToString();
                    Autodesk.AutoCAD.Colors.EntityColor clr = ent.EntityColor;

                    // Entity color to use for the Three.js objects
                    long b, g, r;
                    if (ent.ColorIndex < 256)
                    {
                        System.Byte byt = System.Convert.ToByte(ent.ColorIndex);
                        int         rgb = Autodesk.AutoCAD.Colors.EntityColor.LookUpRgb(byt);
                        b = (rgb & 0xffL);
                        g = (rgb & 0xff00L) >> 8;
                        r = rgb >> 16;
                    }
                    else
                    {
                        b = 127;
                        g = 127;
                        r = 127;
                    }
                    String entColor = "0x" + String.Format("{0:X2}{1:X2}{2:X2}", r, g, b);

                    // Entity extents
                    Extents3d ext  = ent.GeometricExtents;
                    var       tmp  = ext.MinPoint + 0.5 * (ext.MaxPoint - ext.MinPoint);
                    Vector3d  dir  = ext.MaxPoint - ext.MinPoint;
                    var       mid  = new Point3d(ext.MinPoint.X, tmp.Y, tmp.Z);
                    var       dist = camPos.DistanceTo(mid);

                    if (id.ObjectClass.Name.Equals("AcDbSubDMesh"))
                    {
                        // Already a Mesh. Get the face info and clean it up
                        // a bit to export it as a THREE.Face3 which only has three vertices

                        var mesh = ent as SubDMesh;

                        Point3dCollection threeVertices = new Point3dCollection();
                        Autodesk.AutoCAD.Geometry.Int32Collection threeFaceInfo = new Autodesk.AutoCAD.Geometry.Int32Collection();

                        Point3dCollection vertices = mesh.Vertices;

                        int[] faceArr = mesh.FaceArray.ToArray();
                        int[] edgeArr = mesh.EdgeArray.ToArray();

                        Autodesk.AutoCAD.Geometry.Int32Collection faceVertices = new Autodesk.AutoCAD.Geometry.Int32Collection();

                        int verticesInFace = 0;
                        int facecnt        = 0;
                        for (int x = 0; x < faceArr.Length; facecnt++, x = x + verticesInFace + 1)
                        {
                            faceVertices.Clear();

                            verticesInFace = faceArr[x];
                            for (int y = x + 1; y <= x + verticesInFace; y++)
                            {
                                faceVertices.Add(faceArr[y]);
                            }

                            // Merging of mesh faces can result in faces with multiple vertices
                            // A simple collinearity check can help remove those redundant vertices
                            bool continueCollinearCheck = false;
                            do
                            {
                                continueCollinearCheck = false;
                                for (int index = 0; index < faceVertices.Count; index++)
                                {
                                    int v1 = index;
                                    int v2 = (index + 1) >= faceVertices.Count ? (index + 1) - faceVertices.Count : index + 1;
                                    int v3 = (index + 2) >= faceVertices.Count ? (index + 2) - faceVertices.Count : index + 2;

                                    // Check collinear
                                    Point3d p1 = vertices[faceVertices[v1]];
                                    Point3d p2 = vertices[faceVertices[v2]];
                                    Point3d p3 = vertices[faceVertices[v3]];

                                    Vector3d vec1 = p1 - p2;
                                    Vector3d vec2 = p2 - p3;
                                    if (vec1.IsCodirectionalTo(vec2))
                                    {
                                        faceVertices.RemoveAt(v2);
                                        continueCollinearCheck = true;
                                        break;
                                    }
                                }
                            } while (continueCollinearCheck);

                            if (faceVertices.Count == 3)
                            {
                                Point3d p1 = vertices[faceVertices[0]];
                                Point3d p2 = vertices[faceVertices[1]];
                                Point3d p3 = vertices[faceVertices[2]];

                                if (!threeVertices.Contains(p1))
                                {
                                    threeVertices.Add(p1);
                                }
                                threeFaceInfo.Add(threeVertices.IndexOf(p1));

                                if (!threeVertices.Contains(p2))
                                {
                                    threeVertices.Add(p2);
                                }
                                threeFaceInfo.Add(threeVertices.IndexOf(p2));

                                if (!threeVertices.Contains(p3))
                                {
                                    threeVertices.Add(p3);
                                }
                                threeFaceInfo.Add(threeVertices.IndexOf(p3));
                            }
                            else if (faceVertices.Count == 4)
                            { // A face with 4 vertices, lets split it to
                                // make it easier later to create a THREE.Face3
                                Point3d p1 = vertices[faceVertices[0]];
                                Point3d p2 = vertices[faceVertices[1]];
                                Point3d p3 = vertices[faceVertices[2]];

                                if (!threeVertices.Contains(p1))
                                {
                                    threeVertices.Add(p1);
                                }
                                threeFaceInfo.Add(threeVertices.IndexOf(p1));

                                if (!threeVertices.Contains(p2))
                                {
                                    threeVertices.Add(p2);
                                }
                                threeFaceInfo.Add(threeVertices.IndexOf(p2));

                                if (!threeVertices.Contains(p3))
                                {
                                    threeVertices.Add(p3);
                                }
                                threeFaceInfo.Add(threeVertices.IndexOf(p3));

                                p1 = vertices[faceVertices[2]];
                                p2 = vertices[faceVertices[3]];
                                p3 = vertices[faceVertices[0]];

                                if (!threeVertices.Contains(p1))
                                {
                                    threeVertices.Add(p1);
                                }
                                threeFaceInfo.Add(threeVertices.IndexOf(p1));

                                if (!threeVertices.Contains(p2))
                                {
                                    threeVertices.Add(p2);
                                }
                                threeFaceInfo.Add(threeVertices.IndexOf(p2));

                                if (!threeVertices.Contains(p3))
                                {
                                    threeVertices.Add(p3);
                                }
                                threeFaceInfo.Add(threeVertices.IndexOf(p3));
                            }
                            else
                            {
                                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Face with more than 4 vertices will need triangulation to import in Three.js ");
                            }
                        }

                        sols.Add(new MeshData(dist, hand, ext, threeVertices, threeFaceInfo, entColor));
                    }
                    else if (id.ObjectClass.Name.Equals("AcDb3dSolid"))
                    {
                        // Mesh the solid to export to Three.js
                        Autodesk.AutoCAD.DatabaseServices.Solid3d sld = tr.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Solid3d;

                        MeshFaceterData mfd = new MeshFaceterData();
                        // Only triangles
                        mfd.FaceterMeshType = 2;

                        // May need change based on how granular we want the mesh to be.
                        mfd.FaceterMaxEdgeLength = dir.Length * 0.025;

                        MeshDataCollection md = SubDMesh.GetObjectMesh(sld, mfd);

                        Point3dCollection threeVertices = new Point3dCollection();
                        Autodesk.AutoCAD.Geometry.Int32Collection threeFaceInfo = new Autodesk.AutoCAD.Geometry.Int32Collection();

                        Point3dCollection vertices = md.VertexArray;

                        int[] faceArr = md.FaceArray.ToArray();

                        Autodesk.AutoCAD.Geometry.Int32Collection faceVertices = new Autodesk.AutoCAD.Geometry.Int32Collection();

                        int verticesInFace = 0;
                        int facecnt        = 0;
                        for (int x = 0; x < faceArr.Length; facecnt++, x = x + verticesInFace + 1)
                        {
                            faceVertices.Clear();

                            verticesInFace = faceArr[x];
                            for (int y = x + 1; y <= x + verticesInFace; y++)
                            {
                                faceVertices.Add(faceArr[y]);
                            }

                            if (faceVertices.Count == 3)
                            {
                                Point3d p1 = vertices[faceVertices[0]];
                                Point3d p2 = vertices[faceVertices[1]];
                                Point3d p3 = vertices[faceVertices[2]];

                                if (!threeVertices.Contains(p1))
                                {
                                    threeVertices.Add(p1);
                                }
                                threeFaceInfo.Add(threeVertices.IndexOf(p1));

                                if (!threeVertices.Contains(p2))
                                {
                                    threeVertices.Add(p2);
                                }
                                threeFaceInfo.Add(threeVertices.IndexOf(p2));

                                if (!threeVertices.Contains(p3))
                                {
                                    threeVertices.Add(p3);
                                }
                                threeFaceInfo.Add(threeVertices.IndexOf(p3));
                            }
                        }

                        sols.Add(new MeshData(dist, hand, ext, threeVertices, threeFaceInfo, entColor));

                        tr.Commit();
                    }
                }
            }
            return(sols);
        }
コード例 #46
0
            public override bool shoot(Point3d Start, Vector3d Dir, int Random, out double u, out double v, out int Srf_ID, out List <Point3d> X_PT, out List <double> t, out List <int> Code)
            {
                S_Origin = new Point3d(Start);
                Srf_ID   = 0;

                while (true)
                {
                    Point3d[] P = Rhino.Geometry.Intersect.Intersection.RayShoot(new Ray3d(S_Origin, Dir), BrepList, 1);

                    if (P == null)
                    {
                        X_PT = new List <Point3d> {
                            default(Point3d)
                        }; u = 0; v = 0; t = new List <double> {
                            0
                        }; Code = new List <int> {
                            0
                        }; return(false);
                    }

                    Voxels.PointIsInVoxel(P[0], ref XVoxel, ref YVoxel, ref ZVoxel);
                    try
                    {
                        SurfaceIndex = Voxels.VoxelList(XVoxel, YVoxel, ZVoxel);
                    }
                    catch (Exception)
                    {
                        //Rare floating point error on some computers... abandon the ray and start the next...
                        //Explanation: This would never happen on my IBM T43P laptop, but happened
                        //consistently millions of function calls into the calculation on my
                        //ASUS K8N-DL based desktop computer. I believe it has something to do with some quirk of that system.
                        //This try...catch statement is here in case this ever manifests on any user's computer.
                        //It is rare enough that this should not affect the accuracy of the calculation.
                        t = new List <double> {
                            0.0f
                        };
                        X_PT = new List <Point3d> {
                            default(Point3d)
                        };
                        u    = 0;
                        v    = 0;
                        Code = new List <int> {
                            0
                        };
                        return(false);
                    }

                    Point3d        CP;
                    Vector3d       N;
                    ComponentIndex CI;
                    double         MD = 0.0001;

                    foreach (int index in SurfaceIndex)
                    {
                        if (BrepList[index].ClosestPoint(P[0], out CP, out CI, out u, out v, MD, out N) && (CI.ComponentIndexType == ComponentIndexType.BrepFace))
                        {
                            if ((Math.Abs(P[0].X - CP.X) < 0.0001) && (Math.Abs(P[0].Y - CP.Y) < 0.0001) && (Math.Abs(P[0].Z - CP.Z) < 0.0001))
                            {
                                Srf_ID = index;
                                X_PT   = new List <Point3d> {
                                    P[0]
                                };
                                t = new List <double> {
                                    (double)(S_Origin.DistanceTo(X_PT[0]))
                                };
                                Code = new List <int>()
                                {
                                    0
                                };
                                return(true);
                            }
                        }
                    }
                    S_Origin = new Point3d(P[0]);
                }
            }
コード例 #47
0
ファイル: FrameTools.cs プロジェクト: smor/intralattice
        /// <summary>
        /// Computes the distance of a point to a given geometry. (Brep, Mesh or closed Surface)
        /// </summary>
        public static double DistanceTo(GeometryBase geometry, Point3d testPoint, int spaceType)
        {
            double distanceTo = 0;
            Point3d closestPoint;

            switch (spaceType)
            {
                // Brep design space
                case 1:
                    closestPoint = ((Brep)geometry).ClosestPoint(testPoint);
                    distanceTo = testPoint.DistanceTo(closestPoint);
                    break;
                // Mesh design space
                case 2:
                    closestPoint = ((Mesh)geometry).ClosestPoint(testPoint);
                    distanceTo = testPoint.DistanceTo(closestPoint);
                    break;
                // Solid surface design space (must be converted to brep)
                case 3:
                    closestPoint = ((Surface)geometry).ToBrep().ClosestPoint(testPoint);
                    distanceTo = testPoint.DistanceTo(closestPoint);
                    break;
            }

            return distanceTo;
        }
コード例 #48
0
 private double calculate_field(Point3d test_pt)
 {
     double num2 = 0.0;
     int num5 = this.use_charges.Count - 1;
     for (int i = 0; i <= num5; i++)
     {
         double x = test_pt.DistanceTo(this.use_charges[i]);
         if (x < this.use_radii[i])
         {
             num2 += ((((this.cA * Math.Pow(x, 3.0)) / Math.Pow(this.use_radii[i], 3.0)) + ((this.cB * Math.Pow(x, 2.0)) / Math.Pow(this.use_radii[i], 2.0))) + ((this.cC * x) / this.use_radii[i])) + 1.0;
         }
     }
     if (num2 == 0.0)
     {
         num2 = -1.0;
     }
     return num2;
 }