public override void OnDraw(GeometryBuilder dc)
        {
            dc.Clear();

            // Define the basic points for drawing
            Point3d pnt1 = new Point3d(0, 0, 0);
            Point3d pnt2 = new Point3d(pnt1.X + (984 * _scale), pnt1.Y, 0);
            Point3d pnt3 = new Point3d(pnt2.X + 0, pnt1.Y + (50 * _scale), 0);
            Point3d pnt4 = new Point3d(pnt1.X, pnt3.Y, 0);

            // Set the color to ByObject value
            dc.Color = McDbEntity.ByObject;
            Vector3d hvec = new Vector3d(0, 0, _h * _scale);

            // Draw the upper and lower sides
            dc.DrawPolyline(new Point3d[] { pnt1, pnt2, pnt3, pnt4, pnt1 });
            dc.DrawPolyline(new Point3d[] { pnt1.Add(hvec),
                                            pnt2.Add(hvec), pnt3.Add(hvec), pnt4.Add(hvec), pnt1.Add(hvec) });

            // Draw the edges
            dc.DrawLine(pnt1, pnt1.Add(hvec));
            dc.DrawLine(pnt2, pnt2.Add(hvec));
            dc.DrawLine(pnt3, pnt3.Add(hvec));
            dc.DrawLine(pnt4, pnt4.Add(hvec));

            // Drawing a Door Handle
            dc.DrawLine(pnt2.Add(new Vector3d(-190 * _scale, -0, _h * 0.45 * _scale)),
                        pnt2.Add(new Vector3d(-100 * _scale, 0, _h * 0.45 * _scale)));

            dc.DrawLine(pnt3.Add(new Vector3d(-190 * _scale, 0, _h * 0.45 * _scale)),
                        pnt3.Add(new Vector3d(-100 * _scale, 0, _h * 0.45 * _scale)));
        }
Ejemplo n.º 2
0
        /**
         * Returns the coordinates for <code>num</code> randomly
         * chosen points which are degenerate which respect
         * to the specified dimensionality.
         *
         * @param num number of points to produce
         * @param dimen dimensionality of degeneracy: 0 = coincident,
         * 1 = colinear, 2 = coplaner.
         * @return array of coordinate values
         */
        private double[] randomDegeneratePoints(int num, int dimen)
        {
            double[] coords = new double[num * 3];
            Point3d  pnt    = new Point3d();

            Point3d _base = new Point3d();

            _base.SetRandom(-1, 1, rand);

            double tol = DOUBLE_PREC;

            if (dimen == 0)
            {
                for (int i = 0; i < num; i++)
                {
                    pnt.Set(_base);
                    randomlyPerturb(pnt, tol);
                    coords[i * 3 + 0] = pnt.x;
                    coords[i * 3 + 1] = pnt.y;
                    coords[i * 3 + 2] = pnt.z;
                }
            }
            else if (dimen == 1)
            {
                Vector3d u = new Vector3d();
                u.SetRandom(-1, 1, rand);
                u.Normalize();
                for (int i = 0; i < num; i++)
                {
                    double a = 2 * (rand.NextDouble() - 0.5);
                    pnt.Scale(a, u);
                    pnt.Add(_base);
                    randomlyPerturb(pnt, tol);
                    coords[i * 3 + 0] = pnt.x;
                    coords[i * 3 + 1] = pnt.y;
                    coords[i * 3 + 2] = pnt.z;
                }
            }
            else   // dimen == 2
            {
                Vector3d nrm = new Vector3d();
                nrm.SetRandom(-1, 1, rand);
                nrm.Normalize();
                for (int i = 0; i < num; i++)  // compute a random point and project it to the plane
                {
                    Vector3d perp = new Vector3d();
                    pnt.SetRandom(-1, 1, rand);
                    perp.Scale(pnt.Dot(nrm), nrm);
                    pnt.Sub(perp);
                    pnt.Add(_base);
                    randomlyPerturb(pnt, tol);
                    coords[i * 3 + 0] = pnt.x;
                    coords[i * 3 + 1] = pnt.y;
                    coords[i * 3 + 2] = pnt.z;
                }
            }
            return(coords);
        }
Ejemplo n.º 3
0
        public void draw()
        {
            ObjectId  layerId = LayerUtil.CreateLayer("coordinate", 0, false);
            Extents3d bounds  = MyDBUtility.getExtents(mydb.getAllLine());

            double zlen = 0;
            double minz = -10;

            if (mydb.TEDicList.Count > 0)
            {
                TEDictionary ted = mydb.TEDicList[0];
                zlen  = ted.maxMaxZ - ted.minMaxZ;
                zlen += 10;
                minz  = ted.minMaxZ - 5;
            }


            Point3d ori = bounds.MinPoint.Add(new Vector3d(-10, -10, 0));

            ori = ori.Add(new Vector3d(0, 0, (minz - ori.Z)));
            double xlen = bounds.MaxPoint.X - bounds.MinPoint.X + 20;
            double ylen = bounds.MaxPoint.Y - bounds.MinPoint.Y + 20;

            MyDBUtility.line(ori, new Point3d(ori.X + xlen, ori.Y, ori.Z), layerId);
            MyDBUtility.line(ori, new Point3d(ori.X, ori.Y + ylen, ori.Z), layerId);
            Point3d zstart = ori.Add(new Vector3d(0, ylen, 0));
            Point3d zend   = zstart.Add(new Vector3d(0, 0, zlen));

            MyDBUtility.line(zstart, zend, layerId);
            int xcount = (int)xlen / 10;
            int ycount = (int)ylen / 10;
            int zcount = (int)zlen / 5;

            for (int i = 0; i < xcount; i++)
            {
                Point3d s = ori.Add(new Vector3d(i * 10, 0, 0));
                Point3d e = s.Add(new Vector3d(0, -5, 0));
                MyDBUtility.line(s, e, layerId);
                MyDBUtility.text(e, ((int)s.X).ToString(), -Math.PI / 2, layerId);
            }
            for (int i = 0; i < ycount; i++)
            {
                Point3d s = ori.Add(new Vector3d(0, i * 10, 0));
                Point3d e = s.Add(new Vector3d(-5, 0, 0));
                MyDBUtility.line(s, e, layerId);
                MyDBUtility.text(e.Add(new Vector3d(-5, 0, 0)), ((int)s.Y).ToString(), 0, layerId);
            }

            for (int i = 0; i < zcount; i++)
            {
                Point3d s = ori.Add(new Vector3d(0, ylen, i * 5));
                Point3d e = s.Add(new Vector3d(0, 5, 0));
                MyDBUtility.line(s, e, layerId);
                MyDBUtility.text(e.Add(new Vector3d(0, 10, 0)), ((int)s.Z).ToString(), 0, layerId);
            }
        }
Ejemplo n.º 4
0
            private void _createLines()
            {
                _horizontalLine = new Line(_origin, _origin.Add(_blockTransform.CoordinateSystem3d.Xaxis).MultiplyBy(_size));
                _horizontalLine.TransformBy(Matrix3d.Displacement(_blockTransform.CoordinateSystem3d.Xaxis.Negate().MultiplyBy(_size / 2d)));

                _verticalLine = new Line(_origin, _origin.Add(_blockTransform.CoordinateSystem3d.Yaxis).MultiplyBy(_size));
                _verticalLine.TransformBy(Matrix3d.Displacement(_blockTransform.CoordinateSystem3d.Yaxis.Negate().MultiplyBy(_size / 2d)));

                /*_horizontalLine.LineWeight = LineWeight.LineWeight015;
                 * _verticalLine.LineWeight = LineWeight.LineWeight015;*/

                _entities.AddRange(new[] { _horizontalLine, _verticalLine });
            }
Ejemplo n.º 5
0
        public override Vector3d getOrientationFromUv(Point3d pos, Vector3d uv_orit)
        {
            /*double i, j;
             * _srf.ClosestPoint(pos,out i,out j);
             * double i2 = i + uv_orit.X;
             * double j2 = j + uv_orit.Y;
             * Point3d tarPt;
             * Vector3d[] deris;
             * if (!_srf.Evaluate(i2, j2, 1, out tarPt, out deris))
             * {
             *  return Point3d.Subtract(tarPt, pos);
             * }
             * else
             *  return new Vector3d(0, 0, 0);  */
            Point3d _ori    = getIndexByPosition(pos.X, pos.Y, pos.Z);
            Point3d _tarIdx = Point3d.Add(_ori, uv_orit);
            int     _x      = (int)_tarIdx.X < u ? (int)_tarIdx.X : u - 1;
            int     _y      = (int)_tarIdx.Y < v ? (int)_tarIdx.Y : v - 1;

            _x = _x > 0 ? _x : 0;
            _y = _y > 0 ? _y : 0;
            Point3d _tar = getPositionByIndex(_x, _y, 0);

            return(Point3d.Subtract(_tar, pos));
        }
Ejemplo n.º 6
0
        public void DisplayNumericalValues(List <Line> formLines, out List <Plane> locations)
        {
            Point3d      startPoint;
            Plane        centerPlane;
            Vector3d     transformationVector;
            double       angle;
            Functions    functions   = new Functions();
            List <Plane> myLocations = new List <Plane>();
            Vector3d     zPositive   = new Vector3d(0, 0, 1);
            Plane        planeXY     = new Plane(new Point3d(0, 0, 0), zPositive);

            for (int i = 0; i < formLines.Count; i++)
            {
                startPoint           = (1 * formLines[i].From + 1 * formLines[i].To) / 2.0;
                transformationVector = formLines[i].Direction;
                transformationVector.Unitize();
                transformationVector = transformationVector * 0.3;
                transformationVector.Rotate(0.5 * Math.PI, zPositive);
                startPoint  = Point3d.Add(startPoint, transformationVector);
                centerPlane = new Plane(startPoint, new Vector3d(0, 0, 1));

                angle = Vector3d.VectorAngle(new Vector3d(1, 0, 0), formLines[i].Direction, planeXY);
                if (((angle > 0.5 * Math.PI) && (angle <= 1.5 * Math.PI)) || ((angle < -0.5 * Math.PI) && (angle >= -1.5 * Math.PI)))
                {
                    angle += Math.PI;
                }

                centerPlane.Rotate(angle, new Vector3d(0, 0, 1));

                myLocations.Add(centerPlane);
            }

            locations = myLocations;
        }
Ejemplo n.º 7
0
        public List <Plane> CreateTextPlane(Point3d centroid, double refLength, List <string> text)
        {
            List <Plane> planes = new List <Plane>();

            for (int i = 0; i < text.Count; i++)
            {
                double zValue = centroid.Z + refLength * 2.5;

                double z = (double)(zValue - i * refLength / 7);

                if (i == 1)
                {
                    z = (double)(z + refLength / 12);
                }

                Point3d p0 = new Point3d(centroid.X - refLength * 3, centroid.Y, z);
                Point3d p1 = Point3d.Add(p0, new Point3d(1, 0, 0));
                Point3d p2 = Point3d.Add(p0, new Point3d(0, 0, 1));

                Plane p = new Plane(p0, p1, p2);

                planes.Add(p);
            }

            return(planes);
        }
Ejemplo n.º 8
0
        public bool recursiveLine(Curve inputcurve, ref List <Curve> inputObstacle, Random inputRand, int dir, int count)
        {
            if (count < 1)
            {
                return(false);
            }

            Plane perpFrame;
            var   t = inputRand.Next(20, 80) * 0.01;

            //select random point on one edge
            var pt = inputcurve.PointAtNormalizedLength(t);

            inputcurve.PerpendicularFrameAt(t, out perpFrame);
            var pt2 = Point3d.Add(pt, perpFrame.XAxis * dir);

            var ln    = new Line(pt, pt2);
            var lnExt = ln.ToNurbsCurve().ExtendByLine(CurveEnd.End, inputObstacle);

            if (lnExt == null)
            {
                return(false);
            }

            inputObstacle.Add(lnExt);

            //RhinoDoc.ActiveDoc.Objects.AddPoint(pt);
            //RhinoDoc.ActiveDoc.Objects.AddLine(lnExt.PointAtStart, lnExt.PointAtEnd);
            //RhinoDoc.ActiveDoc.Views.Redraw();

            recursiveLine(lnExt, ref inputObstacle, inputRand, 1, count - 1);
            recursiveLine(lnExt, ref inputObstacle, inputRand, -1, count - 1);

            return(true);
        }
Ejemplo n.º 9
0
		public List<Point3d> Points (Point3d start, Point3d dir)
		{
			Vector3d delta = dir.GetAsVector().Subtract(start.GetAsVector());
			delta=delta.DivideBy(delta.Length);
			
			return steps.Select(d=>start.Add(delta*d)).ToList();
		}
Ejemplo n.º 10
0
        public (string, double, Plane, Color) CreateText(double defMax, Node nodeMax, double scale, double refSize, double angle, Point3d center)
        {
            Vector3d def = new Vector3d(nodeMax.GetDeformation()[0], nodeMax.GetDeformation()[1], nodeMax.GetDeformation()[2]);

            Point3d newPoint = nodeMax.GetCoord() + def * scale;

            newPoint = Point3d.Add(newPoint, new Point3d(0, -1.5 * refSize, 0));
            defMax   = Math.Round(defMax, 3);

            string text     = defMax.ToString() + " mm";
            double textSize = refSize;

            Point3d p0 = newPoint;
            Point3d p1 = Point3d.Add(newPoint, new Point3d(-1, 0, 0));
            Point3d p2 = Point3d.Add(newPoint, new Point3d(0, 0, 1));

            Plane textplane = new Plane(p0, p1, p2);

            textplane.Rotate(angle, new Vector3d(0, 0, 1), center);
            textplane.Translate(new Vector3d(0, 0, 2 * refSize));

            Color textColor = Color.Orange;

            return(text, textSize, textplane, textColor);
        }
Ejemplo n.º 11
0
            public void Redirect(Point3d jigPoint)
            {
                if (_jigPoint != jigPoint)
                {
                    _jigPoint = jigPoint;
                }

                double   ang    = Vector3d.YAxis.GetAngle2d(_vector);
                Matrix3d hMat   = Matrix3d.Identity;
                Vector3d vector = jigPoint - _position;

                vector = vector.TransformBy(hMat.PreMultiplyBy(Matrix3d.Rotation(-ang, Vector3d.ZAxis, Point3d.Origin)));

                if (vector.X * (_destPoint - _position).X <= 0 && vector.X != 0d)
                {
                    hMat = hMat.PreMultiplyBy(Matrix3d.Displacement(_position - _pline.EndPoint.Add(_pline.GetFirstDerivative(0).Normalize().MultiplyBy(_spaceLength))));
                }
                else
                {
                    hMat = hMat.PreMultiplyBy(Matrix3d.Displacement(_position.Add(_pline.GetFirstDerivative(0).Normalize().MultiplyBy(_spaceLength)) - _pline.StartPoint));
                }



                _pline.TransformBy(hMat);

                _text.TransformBy(hMat);

                _text.AdjustAlignment(HostApplicationServices.WorkingDatabase);
            }
Ejemplo n.º 12
0
        private void GetCellTriangle(Mesh triangles, byte cubeIndex, double[] vertices, Point3d anchorPoint)
        {
            if (cubeIndex == 0)
            {
                return;
            }

            for (int i = 0; i < 16; i += 3)
            {
                if (triTable[cubeIndex, i] < 0)
                {
                    return;
                }
                else
                {
                    int vertEdge1 = triTable[cubeIndex, i];
                    int vertEdge2 = triTable[cubeIndex, i + 1];
                    int vertEdge3 = triTable[cubeIndex, i + 2];

                    List <Point3d> triVerts = new List <Point3d> {
                        Point3d.Add(anchorPoint, GetEdgePoint(vertEdge1, vertices)),
                        Point3d.Add(anchorPoint, GetEdgePoint(vertEdge2, vertices)),
                        Point3d.Add(anchorPoint, GetEdgePoint(vertEdge3, vertices)),
                        Point3d.Add(anchorPoint, GetEdgePoint(vertEdge1, vertices))
                    };

                    triangles.Append(Mesh.CreateFromClosedPolyline(new Polyline(triVerts)));
                }
            }

            RhinoApp.WriteLine(triangles.ToString());
        }
Ejemplo n.º 13
0
        public List <Brep> CreateDefBreps(List <Element> elements, double scale, double angle, Point3d center)
        {
            List <Brep> breps = new List <Brep>();

            for (int j = 0; j < elements.Count; j++)
            {
                var         mesh     = new Mesh();
                List <Node> vertices = elements[j].GetVertices();

                for (int i = 0; i < vertices.Count; i++)
                {
                    Point3d  p         = vertices[i].GetCoord();
                    Vector3d defVector = new Vector3d(vertices[i].GetDeformation()[0], vertices[i].GetDeformation()[1], vertices[i].GetDeformation()[2]);
                    Point3d  new_p     = Point3d.Add(p, defVector * scale);
                    mesh.Vertices.Add(new_p);
                }
                mesh.Faces.AddFace(0, 1, 5, 4);
                mesh.Faces.AddFace(1, 2, 6, 5);
                mesh.Faces.AddFace(2, 3, 7, 6);
                mesh.Faces.AddFace(0, 3, 7, 4);
                mesh.Faces.AddFace(4, 5, 6, 7);
                mesh.Faces.AddFace(0, 1, 2, 3);

                Brep     new_brep = Brep.CreateFromMesh(mesh, false);
                Vector3d vecAxis  = new Vector3d(0, 0, 1);
                new_brep.Rotate(angle, vecAxis, center);
                breps.Add(new_brep);
            }
            return(breps);
        }
Ejemplo n.º 14
0
        public (List <string>, List <Plane>) CreateTextAndPlane(List <Curve> curves)
        {
            List <string> text   = new List <string>();
            List <Plane>  planes = new List <Plane>();

            //Text that will be added
            string header = "CROSS SECTION";
            string uDir   = "u-direction";
            string vDir   = "v-direction";

            double refLength = curves[0].GetLength();

            Point3d  hp1       = curves[0].PointAtEnd;
            Point3d  hp2       = curves[0].PointAtStart;
            Vector3d headerVec = (hp2 - hp1) / 2;
            Point3d  headPoint = Point3d.Add(hp1, headerVec);

            //Creating plane for header
            Point3d hplane0 = new Point3d(headPoint.X, headPoint.Y, headPoint.Z + refLength / 1.8);
            Point3d hplane1 = Point3d.Add(hplane0, new Point3d(1, 0, 0));
            Point3d hplane2 = Point3d.Add(hplane1, new Point3d(0, 0, 1));

            Plane hplane = new Plane(hplane0, hplane1, hplane2);

            planes.Add(hplane);

            Point3d  up1    = curves[2].PointAtEnd;
            Point3d  up2    = curves[2].PointAtStart;
            Vector3d uVec   = (up2 - up1) / 2;
            Point3d  uPoint = Point3d.Add(up1, uVec);

            //Creating plane for text in u-direction
            Point3d uplane0 = new Point3d(uPoint.X, uPoint.Y, uPoint.Z - refLength / 3 - 10);
            Point3d uplane1 = Point3d.Add(uplane0, new Point3d(1, 0, 0));
            Point3d uplane2 = Point3d.Add(uplane1, new Point3d(0, 0, 1));

            Plane uplane = new Plane(uplane0, uplane1, uplane2);

            planes.Add(uplane);

            //Creating plane for text in u-direction
            Point3d  vp1    = curves[1].PointAtEnd;
            Point3d  vp2    = curves[1].PointAtStart;
            Vector3d vVec   = (vp2 - vp1) / 2;
            Point3d  vPoint = Point3d.Add(vp1, vVec);

            Point3d vplane0 = new Point3d(vPoint.X + 120, vPoint.Y, vPoint.Z);
            Point3d vplane1 = Point3d.Add(vplane0, new Point3d(1, 0, 0));
            Point3d vplane2 = Point3d.Add(vplane1, new Point3d(0, 0, 1));

            Plane vplane = new Plane(vplane0, vplane1, vplane2);

            planes.Add(vplane);

            text.Add(header);
            text.Add(uDir);
            text.Add(vDir);

            return(text, planes);
        }
Ejemplo n.º 15
0
 private ParabolaJig(Entity en, Point3d p0, int segments)
     : base(en)
 {
     mp0       = p0;
     mp2       = p0.Add(Vector3d.XAxis);
     mSegments = segments;
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Create an obstacle object, used for solar calculations.
        /// </summary>
        /// <param name="_mesh">Mesh object. Face normals are important.</param>
        /// <param name="_albedos">8760 albedo values.</param>
        /// <param name="_specCoeff">8760 time series for specular reflection coefficient values. Value between 0 - 1.</param>
        /// <param name="_reflType">Reflection type. 0 = diffuse, 1 = specular (no refraction currently considered), 2 = specular and diffuse (snow), all other numbers = blind (no inter-reflections)</param>
        /// <param name="_tolerance">Tolerance, used to offset point from actual face center point, to avoid self obstruction.</param>
        /// <param name="_name">Name of the obstacle. E.g. use to indicate an analysis surface.</param>
        /// <param name="mt">Multi-threading.</param>
        public CObstacleObject(Mesh _mesh, List <double> _albedos, List <double> _specCoeff, int _reflType, double _tolerance, string _name, bool mt)
        {
            int tasks = 1;

            if (mt)
            {
                tasks = Environment.ProcessorCount;
            }
            ParallelOptions paropts = new ParallelOptions {
                MaxDegreeOfParallelism = tasks
            };

            mesh      = _mesh;
            albedos   = new List <double>(_albedos);
            specCoeff = new List <double>(_specCoeff);
            reflType  = _reflType;
            name      = _name;
            tolerance = _tolerance;

            mesh.FaceNormals.ComputeFaceNormals();

            normals    = new Vector3d[mesh.Faces.Count];
            normalsRev = new Vector3d[mesh.Faces.Count];
            faceCen    = new Point3d[mesh.Faces.Count];

            Parallel.For(0, mesh.Faces.Count, paropts, k =>
            {
                normals[k]    = mesh.FaceNormals[k];
                normalsRev[k] = Vector3d.Negate(normals[k]);
                Point3d cen0  = mesh.Faces.GetFaceCenter(k);
                faceCen[k]    = new Point3d(Point3d.Add(cen0, Vector3d.Multiply(Vector3d.Divide(normals[k], normals[k].Length), tolerance)));
            });
        }
Ejemplo n.º 17
0
        public (List <string>, double, List <Plane>, Color) CreateText(Curve curve, Vector3d load, double refLength)
        {
            List <string> text = new List <string>();

            text.Add("Adjust for load in N/mm^2");
            text.Add("(" + Math.Round((load.X), 3).ToString() + ", " + Math.Round((load.Y), 3).ToString() + ", " + Math.Round((load.Z), 3).ToString() + ")");

            double refSize = (double)(refLength / 7);

            List <Plane> textPlane = new List <Plane>();
            Point3d      start     = curve.PointAtStart;
            Point3d      p0        = Point3d.Add(start, new Point3d(0, 0, 2 * refSize));
            Point3d      p1        = Point3d.Add(start, new Point3d(1, 0, 2 * refSize));
            Point3d      p2        = Point3d.Add(start, new Point3d(0, 0, (1 + 2 * refSize)));

            textPlane.Add(new Plane(p0, p1, p2));

            Point3d end = curve.PointAtEnd;
            Point3d p3  = Point3d.Add(end, new Point3d(0, 0, -2 * refSize));
            Point3d p4  = Point3d.Add(end, new Point3d(1, 0, -2 * refSize));
            Point3d p5  = Point3d.Add(end, new Point3d(0, 0, (1 - 2 * refSize)));

            textPlane.Add(new Plane(p3, p4, p5));

            return(text, refSize, textPlane, Color.White);
        }
Ejemplo n.º 18
0
        public List <Brep> CreateDefBreps(GH_Structure <GH_Point> treePoints, GH_Structure <GH_Integer> treeConnect, Vector3d[] defVectors, double scale, double angle, Point3d center)
        {
            List <Brep> breps = new List <Brep>();

            for (int j = 0; j < treePoints.PathCount; j++)
            {
                List <GH_Point>   vertices = (List <GH_Point>)treePoints.get_Branch(j);
                var               mesh     = new Mesh();
                List <GH_Integer> connect  = (List <GH_Integer>)treeConnect.get_Branch(j);

                for (int i = 0; i < vertices.Count; i++)
                {
                    GH_Point p     = vertices[i];
                    Point3d  new_p = Point3d.Add(p.Value, defVectors[connect[i].Value] * scale);
                    mesh.Vertices.Add(new_p);
                }
                mesh.Faces.AddFace(0, 1, 5, 4);
                mesh.Faces.AddFace(1, 2, 6, 5);
                mesh.Faces.AddFace(2, 3, 7, 6);
                mesh.Faces.AddFace(0, 3, 7, 4);
                mesh.Faces.AddFace(4, 5, 6, 7);
                mesh.Faces.AddFace(0, 1, 2, 3);

                Brep new_brep = Brep.CreateFromMesh(mesh, false);

                Vector3d vecAxis = new Vector3d(0, 0, 1);
                new_brep.Rotate(angle, vecAxis, center);

                breps.Add(new_brep);
            }
            return(breps);
        }
Ejemplo n.º 19
0
 private void GetShapeVertices(PointInt minVert, PointInt maxVert, Curve shapeCurve, Point3d shapeCentre, Vector3d shapeTranslation)
 {
     for (int y = minVert.Y; y < maxVert.Y + 1; y++)
     {
         for (int z = minVert.Z; z < maxVert.Z; z++)
         {
             for (int x = minVert.X; x < maxVert.X; x++)
             {
                 Point3d currentVert = new Point3d(x * marchingArea.CellSize, y * marchingArea.CellSize, z * marchingArea.CellSize);
                 shapeCurve.ClosestPoint(currentVert, out double curveParam);
                 Point3d closestPoint  = shapeCurve.PointAt(curveParam);
                 double  distToCurrent = currentVert.DistanceTo(shapeCentre);
                 double  distToClosest = closestPoint.DistanceTo(shapeCentre);
                 double  dist          = currentVert.DistanceTo(closestPoint);
                 if (distToClosest > distToCurrent)
                 {
                     marchingArea.Vertices[x, y, z] = (marchingArea.Vertices[x, y, z] > 0) ? marchingArea.Vertices[x, y, z] : dist;
                 }
                 else
                 {
                     dist = -dist;
                     marchingArea.Vertices[x, y, z] = (marchingArea.Vertices[x, y, z] > 0) ? marchingArea.Vertices[x, y, z]
                         : (dist > marchingArea.Vertices[x, y, z]) ? dist : marchingArea.Vertices[x, y, z];
                 }
             }
         }
         shapeCurve.Translate(shapeTranslation);
         shapeCentre = Point3d.Add(shapeCentre, shapeTranslation);
     }
 }
Ejemplo n.º 20
0
        void MakeSingle()
        {
            double   Offset4 = 5 / asc.Scale;
            Vector3d vp1_l   = leader_point.GetAsVector().Subtract(p1.GetAsVector());
            Point3d  p3;

            switch (gls)
            {
            case GroupLeaderSide.Right:
            {
                p3 = leader_point.Add(Vector3d.XAxis.MultiplyBy(Offset4));
                break;
            }

            case GroupLeaderSide.Left:
            {
                p3 = leader_point.Add(Vector3d.XAxis.MultiplyBy(Offset4 * -1));
                break;
            }

            case GroupLeaderSide.Inside:
            {
                double dx = p1.X - leader_point.X;
                p3 = leader_point.Add(Vector3d.XAxis.MultiplyBy(Offset4 * Math.Sign(dx)));
                break;
            }

            case GroupLeaderSide.Outside:
            {
                double dx = leader_point.X - p1.X;
                p3 = leader_point.Add(Vector3d.XAxis.MultiplyBy(Offset4 * Math.Sign(dx)));
                break;
            }

            default:
            {
                return;
            }
            }
            mtp    = UT.GetMiddle(p3, leader_point);
            points = new Point3d[3] {
                p1, leader_point, p3
            };

            PrepareMtext(0);
            PreparePolyline();
        }
Ejemplo n.º 21
0
        void PrepareDimline()
        {
            Dim_line = new Line(dim_line_point, dim_line_point.Add(DimDirection.Delta));
            //нашли размерную линию, прибавили вектор направления

            //проекция уже на размерную линию
            pl = new Plane(Dim_line.StartPoint, Dim_line.Delta.GetPerpendicularVector());
        }
Ejemplo n.º 22
0
        public Tuple <List <string>, List <double>, List <Plane>, Color> CreateText(Curve curve, double dir, double refLength)
        {
            List <string> text      = new List <string>();
            string        direction = "";

            if (dir <= 1)
            {
                direction = "S,xx";
            }
            else if (dir <= 2)
            {
                direction = "S,yy";
            }
            else if (dir <= 3)
            {
                direction = "S,zz";
            }
            else if (dir <= 4)
            {
                direction = "S,yz";
            }
            else if (dir <= 5)
            {
                direction = "S,xz";
            }
            else
            {
                direction = "S,xy";
            }
            text.Add("Stress direction: " + direction);
            text.AddRange(new List <string>()
            {
                "S,xx", "S,yy", "S,zz", "S,yz", "S,xz", "S,xy"
            });
            double        refSize = (double)(refLength / 10);
            List <double> size    = new List <double>()
            {
                refSize, (double)(refSize / 2)
            };
            List <Plane> textPlane = new List <Plane>();
            Point3d      start     = curve.PointAtStart;
            Point3d      end       = curve.PointAtEnd;
            Point3d      p0        = Point3d.Add(end, new Point3d(0, 0, 2 * refSize));
            Point3d      p1        = Point3d.Add(end, new Point3d(0, -1, 2 * refSize));
            Point3d      p2        = Point3d.Add(end, new Point3d(0, 0, (1 + 2 * refSize)));

            textPlane.Add(new Plane(p0, p1, p2));
            double range = (double)(refLength / 5);

            for (int i = 0; i < 6; i++)
            {
                Point3d p3 = Point3d.Add(start, new Point3d(0, range * i, -2 * refSize));
                Point3d p4 = Point3d.Add(start, new Point3d(0, -1 + range * i, -2 * refSize));
                Point3d p5 = Point3d.Add(start, new Point3d(0, range * i, (1 - 2 * refSize)));
                textPlane.Add(new Plane(p3, p4, p5));
            }
            return(Tuple.Create(text, size, textPlane, Color.White));
        }
Ejemplo n.º 23
0
        //移动夹点
        public override void MoveGripPointsAt(Entity entity, GripDataCollection grips, Vector3d offset, MoveGripPointsFlags bitFlags)
        {
            var ismove = false;

            foreach (GripData gd in grips)
            {
                if (gd is UserGripData && ismove == false)
                {
                    //UserGripData lagd = (UserGripData)gd;
                    if (entity is BlockReference)
                    {
                        var brf = entity as BlockReference;
                        brf.Position = brf.Position.Add(offset);
                    }
                    else if (entity is DBText)
                    {
                        var txt = entity as DBText;
                        txt.Position       = txt.Position.Add(offset);
                        txt.AlignmentPoint = txt.AlignmentPoint.Add(offset);
                    }
                    else if (entity is MText)
                    {
                        var txt = entity as MText;
                        txt.Location = txt.Location.Add(offset);
                    }
                    ismove = true;
                }
            }
            if (grips.Count > 0)
            {
                if (entity is BlockReference)
                {
                    if (!ismove)
                    {
                        base.MoveGripPointsAt(entity, grips, offset, bitFlags);
                    }
                    mpt1 = pt1.Add(offset);
                    mpt2 = pt2.Add(offset);
                    pt   = GeTools.MidPoint(mpt1, mpt2);
                }
                else if (entity is DBText)
                {
                    if (!ismove)
                    {
                        base.MoveGripPointsAt(entity, grips, offset, bitFlags);
                    }
                    pt = ((DBText)entity).Position;
                }
                else if (entity is MText)
                {
                    if (!ismove)
                    {
                        base.MoveGripPointsAt(entity, grips, offset, bitFlags);
                    }
                    pt = ((MText)entity).Location;
                }
            }
        }
Ejemplo n.º 24
0
        public override void OnDraw(GeometryBuilder dc)
        {
            dc.Clear();

            // Define the basic points for drawing
            Point3d pnt1 = _pnt1;
            Point3d pnt2 = new Point3d(_pnt2.X, pnt1.Y, 0);
            Point3d pnt3 = new Point3d(pnt2.X, pnt1.Y + 150, 0);
            Point3d pnt4 = new Point3d(pnt1.X, pnt3.Y, 0);

            // Set the color to ByObject value
            dc.Color = McDbEntity.ByObject;
            Vector3d hvec = new Vector3d(0, 0, _h);

            // Draw the upper and lower sides
            dc.DrawPolyline(new Point3d[] { pnt1, pnt2, pnt3, pnt4, _pnt1 });
            dc.DrawPolyline(new Point3d[] { _pnt1.Add(hvec),
                                            pnt2.Add(hvec), pnt3.Add(hvec), pnt4.Add(hvec), pnt1.Add(hvec) });

            // Draw the edges
            dc.DrawLine(pnt1, pnt1.Add(hvec));
            dc.DrawLine(pnt2, pnt2.Add(hvec));
            dc.DrawLine(pnt3, pnt3.Add(hvec));
            dc.DrawLine(pnt4, pnt4.Add(hvec));

            // Create contours for the front and rear sides and hatch them
            // In this demo, we hatch only two sides, you can tailor the others yourself
            List <Polyline3d> c1 = new List <Polyline3d>();

            c1.Add(new Polyline3d(
                       new List <Point3d>()
            {
                pnt1, pnt1.Add(hvec), pnt2.Add(hvec), pnt2, pnt1,
            }));
            dc.DrawGeometry(new Hatch(c1, "BRICK", 0, 20, false, HatchStyle.Normal, PatternType.PreDefined, 30), 1);

            List <Polyline3d> c2 = new List <Polyline3d>();

            c2.Add(new Polyline3d(
                       new List <Point3d>()
            {
                pnt4, pnt4.Add(hvec), pnt3.Add(hvec), pnt3, pnt4,
            }));
            dc.DrawGeometry(new Hatch(c2, "BRICK", 0, 20, false, HatchStyle.Normal, PatternType.PreDefined, 30), 1);
        }
Ejemplo n.º 25
0
 private BezierJig(Entity en, Point3d p0, Point3d t0, Point3d p2, int segments)
     : base(en)
 {
     mp0       = p0;
     mt0       = t0;
     mp2       = p2;
     mt2       = mp2.Add(Vector3d.XAxis);
     mSegments = segments;
 }
Ejemplo n.º 26
0
        /***************************************************/

        // Apply infill load to the adjoining elements.
        private void ApplyLoad(InfillLoad load)
        {
            foreach (Element e in this._mesh.Elements)
            {
                // Check if the element is 2D.
                Element2D el = e as Element2D;
                if (el == null)
                {
                    continue;
                }

                Point3d  elC = el.GetCentroid();
                Vector3d elN = el.GetNormal();
                foreach (Infill i in load.Infills)
                {
                    // Check if the element is adjoining to the infill (if all its vertices lie within tolerance).
                    bool broken = false;
                    foreach (Point3d v in el.GetVertices())
                    {
                        if (v.DistanceTo(i.Volume.ClosestPoint(v)) > this._tolerance)
                        {
                            broken = true;
                            break;
                        }
                    }

                    // If the element is adjoining to the infill, apply the load based on location of the element and load function of the infill.
                    if (!broken)
                    {
                        // Flip normal of the element if it points outside the infill.
                        Point3d cpt = Point3d.Add(elC, elN * this._tolerance);
                        if (!i.Volume.IsPointInside(cpt, Rhino.RhinoMath.SqrtEpsilon, true))
                        {
                            el.FlipNormal();
                        }

                        // Check if the element is not surrounded by the infill from both sides - if it is then do nothing (no hydrostatic pressure).
                        else
                        {
                            cpt = Point3d.Add(elC, -elN * this._tolerance);
                            if (i.Volume.IsPointInside(cpt, Rhino.RhinoMath.SqrtEpsilon, true))
                            {
                                continue;
                            }
                        }

                        // Apply the load based on location of the element and load function of the infill.
                        string g = load.InfillDensity.ToString(GuanacoUtil.Invariant);
                        string x = (i.MaxZ - elC.Z).ToString(GuanacoUtil.Invariant);
                        string z = (i.MaxZ - i.MinZ).ToString(GuanacoUtil.Invariant);
                        string f = load.LoadFunction.Replace("g", g).Replace("x", x).Replace("z", z);
                        double p = GuanacoUtil.Evaluate(f);
                        el.AddPressure(-p);
                    }
                }
            }
        }
Ejemplo n.º 27
0
    NurbsSurface Srf3Pt(Point3d A, Point3d B, Point3d C)
    {
        Point3d D = new Point3d(0, 0, 0);

        D = Point3d.Add(D, (B + C - A));
        NurbsSurface srf = NurbsSurface.CreateFromCorners(A, B, D, C);

        return(srf);
    }
Ejemplo n.º 28
0
            public double CalculateEx(Point3d pointLocal)
            {
                Point3d  point2d = new Point3d(pointLocal.X, pointLocal.Y, 0d);
                Vector3d perp    = point2d - point2d.Add(this.AxisVector.GetPerpendicularVector());
                Vector3d project = perp.ProjectTo(this.AxisVector.GetNormal(), this.AxisVector);

                Line3d line3d = new Line3d(point2d, project);
                var    points = line3d.IntersectWith(new Line3d(Point3d.Origin, this.AxisVector), Tolerance.Global);

                if (points != null && points.Length > 0)
                {
                    Line line = new Line(point2d, points[0]);
                    this.LastValue = line.Length * (this.AxisVector.GetPerpendicularVector().IsCodirectionalTo(line.GetFirstDerivative(0d)) ? 1 : -1);
                    if (LastValue < 0d)
                    {
                        this.Mirror();
                    }

                    if (this.IsCodirectional)
                    {
                        if (BaseArrow.IsRedirected && !this.IsRedirected)
                        {
                            this.Redirect();
                        }
                        if (!this.IsSymbolsMirrored && !BaseArrow.IsSymbolsMirrored)
                        {
                            BaseArrow.MirrorSymbols();
                        }
                    }
                    else
                    {
                        if (this.BaseArrow != null)
                        {
                            if (this.BaseArrow.IsRedirected)
                            {
                                this.BaseArrow.Redirect();
                                if (this.BaseArrow.IsSymbolsMirrored)
                                {
                                    this.BaseArrow.MirrorSymbols();
                                }
                            }
                            else
                            {
                                if (this.BaseArrow.IsSymbolsMirrored)
                                {
                                    this.BaseArrow.MirrorSymbols();
                                }
                            }
                        }
                    }

                    return(LastValue.Value);
                }

                return(0d);
            }
Ejemplo n.º 29
0
        public Plane FindSpherePlane(Point3d centroid, double refLength)
        {
            Point3d p0 = new Point3d(centroid.X + refLength * 2, centroid.Y, centroid.Z + refLength * 2);
            Point3d p1 = Point3d.Add(p0, new Point3d(1, 0, 0));
            Point3d p2 = Point3d.Add(p0, new Point3d(0, 0, 1));

            Plane p = new Plane(p0, p1, p2);

            return(p);
        }
Ejemplo n.º 30
0
        public static Rectangle3d CreateRectangle(Point3d leftLowPoint, Point3d rightHighPoint, CoordinateSystem3d cs)
        {
            Vector3d verticalVector   = cs.Yaxis.MultiplyBy((rightHighPoint - leftLowPoint).Y);
            Vector3d horizontalVector = cs.Xaxis.MultiplyBy((rightHighPoint - leftLowPoint).X);

            Point3d lowerLeft  = leftLowPoint;
            Point3d lowerRight = leftLowPoint.Add(horizontalVector);
            Point3d upperLeft  = leftLowPoint.Add(verticalVector);
            Point3d upperRight = lowerRight.Add(verticalVector);

            Rectangle3d rectg = new Rectangle3d(
                lowerLeft: lowerLeft,
                lowerRight: lowerRight,
                upperLeft: upperLeft,
                upperRight: upperRight
                );

            return(rectg);
        }