예제 #1
0
파일: mop.cs 프로젝트: robgrz/matmill
        private List <Polyline> calc_visual_rapids(List <Toolpath> toolpaths)
        {
            List <Polyline> rapids = new List <Polyline>();

            double thres = base.GetDistanceThreshold();

            Point3F lastpt = Point3F.Undefined;

            // rapids are possible only between depth levels of pocket and separate pockets
            foreach (Toolpath path in toolpaths)
            {
                if (!lastpt.IsUndefined)
                {
                    Point3F to;

                    if (path.Leadin != null)
                    {
                        to = path.Leadin.FirstPoint;
                    }
                    else
                    {
                        to = (Point3F)path.Trajectory[0].FirstPoint;
                    }

                    double dist = Point2F.Distance((Point2F)lastpt, (Point2F)to);

                    if (dist > thres + (double)CamBamConfig.Defaults.GeneralTolerance)
                    {
                        // rapid here from last to first point of pocket
                        Polyline p = new Polyline();
                        p.Add(lastpt);
                        p.Add(new Point3F(lastpt.X, lastpt.Y, ClearancePlane.Cached));
                        p.Add(new Point3F(to.X, to.Y, ClearancePlane.Cached));
                        p.Add(new Point3F(to.X, to.Y, path.Bottom + to.Z));
                        rapids.Add(p);
                    }
                }

                lastpt = path.Trajectory[path.Trajectory.Count - 1].LastPoint;
                lastpt = new Point3F(lastpt.X, lastpt.Y, path.Bottom);
            }

            return(rapids);
        }
        void UpdateConstants()
        {
            // exit if size is not initialized yet
            if (_drawInfo == null || _constBuffer.Size.IsEmpty)
            {
                return;
            }

            // pre-calculate some values
            var sz = _constBuffer.Size;
            var sp = new Point2F(_warpStart.X * sz.Width, _warpStart.Y * sz.Height);
            var ep = new Point2F(_warpEnd.X * sz.Width, _warpEnd.Y * sz.Height);

            _constBuffer.StartPos = sp;
            _constBuffer.EndPos   = ep;
            _constBuffer.Distance = sp.Distance(ep) * 1.5f;

            _drawInfo.SetVertexConstantBuffer(ref _constBuffer);
        }
예제 #3
0
파일: slice.cs 프로젝트: robgrz/matmill
        public Slice(Slice parent, Point2F center, double radius, RotationDirection dir, double tool_r, Point2F magnet)
        {
            _parent = parent;
            _ball   = new Circle2F(center, radius);

            double dist       = Point2F.Distance(center, parent.Center);
            double delta_r    = this.Radius - parent.Radius;
            double coarse_ted = dist + delta_r;

            // 1) one ball is inside other, no intersections
            // 2) balls are spaced too far and do not intersect, TED is 0, distance is positive
            // 3) balls are intersect, TED is valid
            if (dist <= Math.Abs(delta_r))
            {
                _placement = Slice_placement.INSIDE_ANOTHER;
                return;
            }

            if (dist >= this.Radius + parent.Radius)
            {
                _placement = Slice_placement.TOO_FAR;
                return;
            }
            // TED can't be more >= tool diameter, this check prevents fails during the calculation of real angle-based TED
            if (coarse_ted > tool_r * 1.999)
            {
                _placement = Slice_placement.TOO_FAR;
                return;
            }

            Line2F insects = _parent.Ball.CircleIntersect(this._ball);

            if (insects.p1.IsUndefined || insects.p2.IsUndefined)
            {
                // try to return meaningful result even if CB routine had failed (unlikely)
                Logger.err("no intersections found there intersections should be (_parent.Ball.CircleIntersect(_ball))");
                _placement = (dist <= this.Radius || dist <= parent.Radius) ? Slice_placement.INSIDE_ANOTHER : Slice_placement.TOO_FAR;
                return;
            }

            _placement = Slice_placement.NORMAL;

            Vector2d          v_move      = new Vector2d(_parent.Center, this.Center);
            Vector2d          v1          = new Vector2d(_parent.Center, insects.p1);
            RotationDirection default_dir = v_move.Det(v1) > 0 ? RotationDirection.CW : RotationDirection.CCW;

            if (dir == RotationDirection.Unknown)
            {
                if (magnet.IsUndefined)
                {
                    dir = RotationDirection.CCW;    // just something
                }
                else
                {
                    if (insects.p1.DistanceTo(magnet) < insects.p2.DistanceTo(magnet))  // match, use existing dir
                    {
                        dir = default_dir;
                    }
                    else
                    {
                        dir = (default_dir == RotationDirection.CCW) ? RotationDirection.CW : RotationDirection.CCW;   // flip
                    }
                }
            }

            Arc2F arc;

            if (default_dir == dir)
            {
                arc = new Arc2F(this.Center, insects.p1, insects.p2, dir);
            }
            else
            {
                arc = new Arc2F(this.Center, insects.p2, insects.p1, dir);
            }

            _segments.Add(arc);

            calc_teds(tool_r);

            if (_mid_ted <= 0)
            {
                Logger.warn("forced to patch mid_ted");
                _mid_ted = coarse_ted;    // shouldn't be, but ok
            }

            _max_ted = Math.Max(_mid_ted, _entry_ted);
        }